diff --git a/odex25_ensan/odex_takaful/models/donation_details_lines.py b/odex25_ensan/odex_takaful/models/donation_details_lines.py index 01343c648..ccee360d6 100644 --- a/odex25_ensan/odex_takaful/models/donation_details_lines.py +++ b/odex25_ensan/odex_takaful/models/donation_details_lines.py @@ -55,7 +55,7 @@ class DonationsDetailsLines(models.Model): family_domain_ids = fields.Many2many('grant.benefit', compute='_compute_family_domain_ids') benefit_id = fields.Many2one('family.member', string='Beneficiary Name', ondelete='restrict', domain="[('id', 'in', members_domain_ids)]", tracking=True) family_id = fields.Many2one('grant.benefit', string='Family', ondelete='restrict', domain="[('id', 'in', family_domain_ids)]", tracking=True) - benefit_ids = fields.Many2many('family.member', string='Beneficiaries Names', tracking=True, domain="[('id', 'in', members_domain_ids)]") + benefit_ids = fields.Many2many('family.member', string='Beneficiaries Names', tracking=True, domain="[('id', 'in', members_domain_ids) , ('age' , '<' , ages)]") sponsorship_duration = fields.Selection([('temporary', 'Temporary'), ('permanent', 'Permanent')], string='Sponsorship Type', default="temporary") start_date = fields.Date(string="Sponsorship Start Date", copy=False, default=fields.Date.today()) @@ -98,6 +98,7 @@ class DonationsDetailsLines(models.Model): debit_payment_attachment_file_name = fields.Char('Debit Payment File Name', required=False) journal_id = fields.Many2one('account.journal', string="Journal",domain="[('type','=','bank')]",default=_default_journal_id) benefit_status = fields.Selection(related='benefit_id.member_status') + ages = fields.Integer(compute='_compute_get_age_range' , store=True) # cheque_number = fields.Integer(string="Cheque Number") # cheque_due_date = fields.Date(string="Cheque Due Date") # cheque_file_attachment = fields.Binary(string='Cheque Attachment', attachment=True) @@ -106,6 +107,38 @@ class DonationsDetailsLines(models.Model): # bank_transfer_attachment_file_name = fields.Char('Bank Transfer File Name', required=False) + @api.depends('sponsorship_duration' , 'product_template_id' , 'payment_month_count' , 'direct_debit') + def _compute_get_age_range(self): + for rec in self: + x = [] + records = self.env['donations.details.lines'].search(['|' , ('state', '=', 'replace') , ('state', '=', 'waiting')]) + print('records >>> ' , records) + for i in records: + x.append(self.compute_donation_value(records)) + lowest_value = min(x) if x else None + rec.ages = lowest_value + + def compute_donation_value(self , records): + """ + Loop through donation detail lines and return a number based on conditions: + - If sponsorship_duration == 'permanent' → return 1 + - Else if not permanent and payment_month_count > 6 → return 1 + - Else if not permanent and payment_month_count < 6 and direct_debit == True → return 16 + - Else if not permanent and payment_month_count < 6 → return 18 + - Else → return 1 + """ + for record in records: + if record.sponsorship_duration == 'permanent': + return 1 + elif record.sponsorship_duration != 'permanent' and record.payment_month_count > 6: + return 1 + elif record.sponsorship_duration != 'permanent' and record.payment_month_count < 6 and record.direct_debit: + return 16 + elif record.sponsorship_duration != 'permanent' and record.payment_month_count < 6: + return 18 + else: + return 1 + return 1 @api.depends('extension_history_ids') def _compute_extension_count(self): for rec in self: @@ -1064,4 +1097,4 @@ class DonationsDetailsLines(models.Model): 'context': { 'default_donation_detail_id': self.id, }, - } \ No newline at end of file + } diff --git a/odex25_ensan/odex_takaful/views/donations_details_lines.xml b/odex25_ensan/odex_takaful/views/donations_details_lines.xml index ef0af919a..5582f6347 100644 --- a/odex25_ensan/odex_takaful/views/donations_details_lines.xml +++ b/odex25_ensan/odex_takaful/views/donations_details_lines.xml @@ -178,6 +178,7 @@ + @@ -373,4 +374,4 @@ {'create': False, 'delete': False, 'search_default_filter_replace': 1} - \ No newline at end of file + diff --git a/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml b/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml index e0b38bbd2..847aeb512 100644 --- a/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml +++ b/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml @@ -509,6 +509,7 @@ + - + @@ -818,4 +819,4 @@ - \ No newline at end of file +