Benefit customization
This commit is contained in:
parent
ed96838495
commit
24ff27cc3e
|
|
@ -636,6 +636,14 @@ class GrantBenefitProfile(models.Model):
|
|||
if self.image_url:
|
||||
self.img_attach = '<img id="img" src="%s"/>' % self.url
|
||||
|
||||
def get_researchers_email(self):
|
||||
email_ids = ''
|
||||
for rec in self.researcher_id.employee_id:
|
||||
if email_ids:
|
||||
email_ids = email_ids + ',' + str(rec.work_email)
|
||||
else:
|
||||
email_ids = str(rec.work_email)
|
||||
return email_ids
|
||||
|
||||
@api.depends('room_ids')
|
||||
def get_rooms_total(self):
|
||||
|
|
|
|||
|
|
@ -677,3 +677,4 @@ class MaritalStatus(models.Model):
|
|||
|
||||
name = fields.Char(string="Name")
|
||||
is_benefit = fields.Boolean(string='Is Benefit?')
|
||||
is_dead = fields.Boolean(string='Is Dead?')
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from odoo import fields, models, api, _
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
class ServiceRequest(models.Model):
|
||||
_name = 'service.request'
|
||||
|
|
@ -9,7 +9,6 @@ class ServiceRequest(models.Model):
|
|||
name = fields.Char(string='Name')
|
||||
# family_id = fields.Many2one('grant.benefit',string='Family')
|
||||
# is_main_service = fields.Boolean(string='Is Main Service?')
|
||||
# service_type = fields.Selection([('rent', 'Rent')],string='Service Type')
|
||||
# max_amount_for_student = fields.Float(string='Max Amount for Student')
|
||||
# raise_amount_for_orphan = fields.Float(string='Raise Amount For Orphan')
|
||||
# rent_lines = fields.One2many('rent.lines','services_settings_id')
|
||||
|
|
@ -26,6 +25,16 @@ class ServiceRequest(models.Model):
|
|||
sub_service_category = fields.Many2one('services.settings',domain="[('is_main_service','=',False),('service_type','=',False),('parent_service','=',main_service_category)]",string='Sub Service Category')
|
||||
service_cat = fields.Many2one('services.settings',domain="[('is_main_service','=',False),('service_type','!=',False),('parent_service','=',sub_service_category)]",string='Service Cat.')
|
||||
service_attach = fields.Binary(string="Service Attach")
|
||||
requested_service_amount = fields.Float(string="Requested Service Amount")
|
||||
estimated_rent_amount = fields.Float(string="Estimated Rent Amount",compute="_get_estimated_rent_amount")
|
||||
paid_rent_amount = fields.Float(string="Paid Rent Amount",compute="_get_paid_rent_amount")
|
||||
service_type = fields.Selection([('rent', 'Rent')],string='Service Type',related='service_cat.service_type')
|
||||
rent_contract_number = fields.Char(string="Rent Contract Number",related ="family_id.contract_num")
|
||||
rent_start_date = fields.Date(string='Rent Start Date',related ="family_id.rent_start_date")
|
||||
rent_end_date = fields.Date(string='Rent End Date' ,related ="family_id.rent_end_date")
|
||||
rent_attachment = fields.Many2many('ir.attachment', 'rel_rent_attachment_service_request', 'service_request_id', 'attachment_id',string='Rent Attachment',related ="family_id.rent_attachment")
|
||||
rent_payment_date = fields.Date(string='Rent Payment Date')
|
||||
added_amount_if_mother_dead = fields.Float(string="Added Amount (If mother dead)",compute="_get_added_amount_if_mother_dead")
|
||||
state = fields.Selection([
|
||||
('draft', 'Draft'),
|
||||
('send_request', 'Send Request'),
|
||||
|
|
@ -40,6 +49,38 @@ class ServiceRequest(models.Model):
|
|||
raise UserError(_('You cannot delete this record'))
|
||||
return super(ServiceRequest, self).unlink()
|
||||
|
||||
def _get_estimated_rent_amount(self):
|
||||
for rec in self:
|
||||
rec.estimated_rent_amount = 0.0 # Default value
|
||||
|
||||
if not rec.family_id:
|
||||
continue
|
||||
|
||||
for item in rec.service_cat.rent_lines:
|
||||
# Check if benefit category and member count match
|
||||
if rec.family_id.benefit_category_id != item.benefit_category_id or rec.family_id.benefit_member_count != item.benefit_count:
|
||||
continue
|
||||
|
||||
# Determine rent amount based on branch type and property type
|
||||
branch_type = rec.family_id.branch_custom_id.branch_type
|
||||
is_shared_rent = rec.family_id.property_type == 'rent_shared'
|
||||
|
||||
if branch_type == 'branches':
|
||||
rec.estimated_rent_amount = item.estimated_rent_branches * (
|
||||
item.discount_rate_shared_housing if is_shared_rent else 1)
|
||||
elif branch_type == 'governorates':
|
||||
rec.estimated_rent_amount = item.estimated_rent_governorate * (
|
||||
item.discount_rate_shared_housing if is_shared_rent else 1)
|
||||
|
||||
def _get_paid_rent_amount(self):
|
||||
for rec in self:
|
||||
rec.paid_rent_amount = min(rec.estimated_rent_amount, rec.requested_service_amount)
|
||||
|
||||
def _get_added_amount_if_mother_dead(self):
|
||||
for rec in self:
|
||||
rec.added_amount_if_mother_dead = 0.0
|
||||
if rec.family_id.mother_marital_conf.is_dead:
|
||||
rec.added_amount_if_mother_dead = rec.service_cat.raise_amount_for_orphan
|
||||
def action_send_request(self):
|
||||
for rec in self:
|
||||
rec.state = 'send_request'
|
||||
|
|
@ -53,4 +94,25 @@ class ServiceRequest(models.Model):
|
|||
rec.state = 'second_approve'
|
||||
def action_refuse(self):
|
||||
for rec in self:
|
||||
rec.state = 'refused'
|
||||
rec.state = 'refused'
|
||||
|
||||
@api.onchange('service_cat','family_id')
|
||||
def onchange_service_cat(self):
|
||||
for rec in self:
|
||||
if rec.service_cat.service_type == 'rent' and rec.family_id.property_type == 'ownership' or rec.family_id.property_type == 'ownership_shared':
|
||||
raise UserError(_("You cannot benefit from this service"))
|
||||
|
||||
@api.onchange('rent_payment_date')
|
||||
def onchange_rent_payment_date(self):
|
||||
today_date = fields.Date.today()
|
||||
for rec in self:
|
||||
if rec.rent_payment_date :
|
||||
month_before_rent_payment_date = rec.rent_payment_date - timedelta(days=30)
|
||||
if today_date > month_before_rent_payment_date:
|
||||
raise UserError(_("You Should request At least a month ago rent payment date"))
|
||||
|
||||
def action_set_to_draft(self):
|
||||
for rec in self:
|
||||
rec.state= 'draft'
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1230,6 +1230,7 @@
|
|||
<group>
|
||||
<field name="name"/>
|
||||
<field name="is_benefit"/>
|
||||
<field name="is_dead"/>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
<field name="benefit_member_count" force_save="1"/>
|
||||
<field name="branch_custom_id" force_save="1"/>
|
||||
<field name="member_id" attrs="{'invisible':[('benefit_type','!=','member')],'readonly':[('state','not in',['draft','send_request'])]}"/>
|
||||
<field name="requested_service_amount" attrs="{'readonly':[('state','not in',['draft','send_request'])]}"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="need_status" attrs="{'readonly':[('state','not in',['draft','send_request'])]}"/>
|
||||
|
|
@ -42,8 +43,35 @@
|
|||
<field name="date" attrs="{'readonly':[('state','not in',['draft','send_request'])]}"/>
|
||||
<field name="description" attrs="{'readonly':[('state','not in',['draft','send_request'])]}"/>
|
||||
<field name="service_attach" attrs="{'readonly':[('state','not in',['draft','send_request'])]}"/>
|
||||
<field name="service_type" invisible="1"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Rent Information" attrs="{'invisible':[('service_type', '!=', 'rent')]}">
|
||||
<form>
|
||||
<sheet>
|
||||
<group>
|
||||
<group>
|
||||
<separator string="Rent Contract Information" colspan="2"/>
|
||||
<br/>
|
||||
<field name="rent_contract_number"/>
|
||||
<field name="rent_start_date"/>
|
||||
<field name="rent_end_date"/>
|
||||
<field name="rent_payment_date"/>
|
||||
<field name="rent_attachment" widget="many2many_attachment_preview"/>
|
||||
</group>
|
||||
<group>
|
||||
<separator string="Rent Amounts" colspan="2"/>
|
||||
<br/>
|
||||
<field name="estimated_rent_amount"/>
|
||||
<field name="paid_rent_amount"/>
|
||||
<field name="added_amount_if_mother_dead"/>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</page>
|
||||
</notebook>
|
||||
</sheet>
|
||||
<div class="oe_chatter">
|
||||
<field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue