From 160d6271e0772521261278810900b8fbc6901a36 Mon Sep 17 00:00:00 2001 From: Nossibaelhadi Date: Wed, 7 Jan 2026 13:03:50 +0300 Subject: [PATCH] [FIX] solve bugs from test8 --- .../models/donation_details_lines.py | 20 +++++--- .../odex_takaful/models/family_member.py | 2 + .../wizards/account_payment_register.py | 51 ++++++++++--------- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/odex25_takaful/odex_takaful/models/donation_details_lines.py b/odex25_takaful/odex_takaful/models/donation_details_lines.py index 0a1c49d55..d8392dfaf 100644 --- a/odex25_takaful/odex_takaful/models/donation_details_lines.py +++ b/odex25_takaful/odex_takaful/models/donation_details_lines.py @@ -372,11 +372,11 @@ class DonationsDetailsLines(models.Model): def onset_benefit_id(self): for rec in self: if rec.state == 'waiting' and (rec.benefit_id or rec.benefit_ids): - if rec.sponsorship_duration == 'permanent': - rec.state = 'paid' - else: - rec.state = 'active' - rec.start_date = fields.Date.today() + # if rec.sponsorship_duration == 'permanent': + # rec.state = 'paid' + # else: + rec.state = 'active' + rec.start_date = fields.Date.today() sponsor_id = rec.sponsorship_mechanism_id.sponsor_id.id if rec.sponsorship_mechanism_id else rec.sponsorship_id.sponsor_id.id (rec.benefit_id | rec.benefit_ids).write( @@ -690,11 +690,17 @@ class DonationsDetailsLines(models.Model): else: rec.payment_option = 'once' - @api.depends('start_date', 'payment_month_count') + @api.depends('start_date', 'payment_month_count', 'donation_mechanism', 'sponsorship_duration', 'donation_type', 'direct_debit') def _compute_end_date(self): for record in self: - if record.start_date and record.payment_month_count: + if record.direct_debit and record.start_date and record.payment_month_count: record.end_date = record.start_date + relativedelta(months=record.payment_month_count) + + elif record.donation_type == 'sponsorship' and record.sponsorship_duration == 'temporary' and record.start_date and record.payment_month_count: + record.end_date = record.start_date + relativedelta(months=record.payment_month_count) + + elif not record.direct_debit and record.donation_type == 'donation': + record.end_date = record.start_date else: record.end_date = False diff --git a/odex25_takaful/odex_takaful/models/family_member.py b/odex25_takaful/odex_takaful/models/family_member.py index d9c6994ac..1e68a9141 100644 --- a/odex25_takaful/odex_takaful/models/family_member.py +++ b/odex25_takaful/odex_takaful/models/family_member.py @@ -23,6 +23,8 @@ class GrantBenefit(models.Model): for sponsorship in sponsorships: if member.member_status and member.member_status == 'non_benefit' and sponsorship.record_type == 'sponsorship': sponsorship.sudo().write({'state': 'replace'}) + if member.member_status and member.member_status == 'benefit' and sponsorship.record_type == 'sponsorship' and sponsorship.state == 'replace': + sponsorship.sudo().write({'state': 'active'}) diff --git a/odex25_takaful/odex_takaful/wizards/account_payment_register.py b/odex25_takaful/odex_takaful/wizards/account_payment_register.py index 25fa0b6eb..49a6c68c8 100644 --- a/odex25_takaful/odex_takaful/wizards/account_payment_register.py +++ b/odex25_takaful/odex_takaful/wizards/account_payment_register.py @@ -16,8 +16,8 @@ class AccountRegisterPayment(models.TransientModel): if machine.exists() and machine.journal_id: res['journal_id'] = machine.journal_id.id elif not res.get('machine_id'): - # Fallback if default_get didn't catch the field default (though it usually does for computed defaults) - # Let's explicitly check our custom default logic if not present + # Fallback if default_get didn't catch the field default (though it usually does for computed defaults) + # Let's explicitly check our custom default logic if not present machine_id = self._default_machine_id() if machine_id: res['machine_id'] = machine_id @@ -35,7 +35,8 @@ class AccountRegisterPayment(models.TransientModel): return payment_method.id if payment_method else False takaful_sponsorship_id = fields.Many2one('takaful.sponsorship') - takaful_payment_method_id = fields.Many2one('takaful.payment.method', string="Payment Method", required=True, default=_default_payment_method_id) + takaful_payment_method_id = fields.Many2one('takaful.payment.method', string="Payment Method", required=True, + default=_default_payment_method_id) takaful_payment_method = fields.Selection([ ("cash", "Cash"), ("bank", "Bank Transfer"), @@ -47,7 +48,9 @@ class AccountRegisterPayment(models.TransientModel): is_refund_sponsorship = fields.Boolean(string='Is Refund Sponsorship') transaction_file_attachment = fields.Binary(string='Transaction Attachment', attachment=False) transaction_attachment_file_name = fields.Char('Transaction File Name', required=False) - payment_method = fields.Selection(selection=[("cash", "Cash"), ("bank", "Bank Transfer"), ("check", "Check")], string="Payment Method", required=True, default="cash") + payment_method = fields.Selection(selection=[("cash", "Cash"), ("bank", "Bank Transfer"), ("check", "Check")], + string="Payment Method", required=True, default="cash") + @api.model def _default_machine_id(self): sponsorship_id = self.env.context.get('default_takaful_sponsorship_id') or self.env.context.get('active_id') @@ -96,18 +99,17 @@ class AccountRegisterPayment(models.TransientModel): for rec in self: rec.show_payment_group = (len(unique_partners) == 1) - @api.depends_context('wiz_id') def _compute_show_cancel_button(self): for rec in self: rec.show_cancel_button = not bool(self.env.context.get('wiz_id')) - @api.onchange("machine_id") def onchange_machine_id(self): for rec in self: if rec.machine_id: rec.journal_id = rec.machine_id.journal_id + @api.onchange("takaful_payment_method_id") def onchange_takaful_payment_method_id(self): for rec in self: @@ -119,13 +121,13 @@ class AccountRegisterPayment(models.TransientModel): j_type = "" if payment_method == "cash": j_type = "cash" - elif payment_method in ("bank", "check","network"): + elif payment_method in ("bank", "check", "network"): j_type = "bank" if j_type: return {"domain": {"journal_id": [("type", "=", j_type), ("branch_ids", "in", branch_ids)]}} - - @api.depends('source_amount', 'source_amount_currency', 'source_currency_id', 'company_id', 'currency_id', 'payment_date') + @api.depends('source_amount', 'source_amount_currency', 'source_currency_id', 'company_id', 'currency_id', + 'payment_date') def _compute_amount(self): if self.env.context.get('sponsorship_payment_skip_compute_amount'): self.amount = self.amount @@ -143,23 +145,23 @@ class AccountRegisterPayment(models.TransientModel): else: rec.takaful_payment_method = "cash" - def _create_payments(self): sponsorship_line_ids = self.env.context.get('sponsorship_line_ids') - sponsorship_lines = self.env['donations.details.lines'].browse(sponsorship_line_ids).filtered(lambda r: r.display_type == False) + sponsorship_lines = self.env['donations.details.lines'].browse(sponsorship_line_ids).filtered( + lambda r: r.display_type == False) sponsorship = self.env['takaful.sponsorship'].browse(self.env.context.get('sponsorship_id')) payments = super(AccountRegisterPayment, self)._create_payments() if sponsorship_lines: - + for line in sponsorship_lines: state = '' if line.record_type == 'sponsorship': if not (line.benefit_id | line.benefit_ids): state = 'waiting' - elif line.sponsorship_duration == 'temporary': - state = 'active' + # elif line.sponsorship_duration == 'temporary': + # state = 'active' else: - state = 'paid' + state = 'active' elif line.record_type == 'donation': if line.donation_mechanism == 'with_conditions': state = 'paid' @@ -178,7 +180,7 @@ class AccountRegisterPayment(models.TransientModel): benefit_journal_id = self.env.company.kafala_benefit_journal_id.id donation_line = schedule_line.donation_detail_linked_id family_id = donation_line.family_id - + bill_values = { 'takaful_sponsorship_id': sponsorship.id, 'move_type': 'in_invoice', @@ -190,7 +192,8 @@ class AccountRegisterPayment(models.TransientModel): 'product_id': donation_line.product_id.id, 'price_unit': schedule_line.amount, 'quantity': 1, - 'name': _("Benefit Number %s %s") % (donation_line.sequence_no, f"Cheque Number: {self.check_number} Cheque Due Date: {self.check_due_date}" if self.takaful_payment_method == 'check' else " "), + 'name': _("Benefit Number %s %s") % (donation_line.sequence_no, + f"Cheque Number: {self.check_number} Cheque Due Date: {self.check_due_date}" if self.takaful_payment_method == 'check' else " "), 'analytic_account_id': sponsorship.branch_custom_id.branch.analytic_account_id.id, })] } @@ -237,7 +240,6 @@ class AccountRegisterPayment(models.TransientModel): 'type': 'binary', }) - return payments @api.model @@ -261,15 +263,17 @@ class AccountRegisterPayment(models.TransientModel): @api.model def _get_batch_available_partner_banks(self, batch_result, journal): sponsorship_line_ids = self.env.context.get('sponsorship_line_ids') - sponsorship_lines = self.env['donations.details.lines'].browse(sponsorship_line_ids).filtered(lambda r: r.display_type == False) - + sponsorship_lines = self.env['donations.details.lines'].browse(sponsorship_line_ids).filtered( + lambda r: r.display_type == False) + if sponsorship_lines: - return sponsorship_lines.sponsor_id.bank_ids + return sponsorship_lines.sponsor_id.bank_ids return super(AccountRegisterPayment, self)._get_batch_available_partner_banks(batch_result, journal) def action_create_payments(self): - res = super(AccountRegisterPayment, self.with_context(skip_account_move_synchronization=True)).action_create_payments() - + res = super(AccountRegisterPayment, + self.with_context(skip_account_move_synchronization=True)).action_create_payments() + if self.env.context.get('dont_redirect_to_payments') and self.env.context.get('wiz_id'): if self.amount < self.env.context.get('default_amount'): wiz = self.env['donation.extension.wizard'].browse(self.env.context.get('wiz_id')) @@ -320,4 +324,3 @@ class AccountRegisterPayment(models.TransientModel): } return {'type': 'ir.actions.act_window_close'} -