diff --git a/odex25_takaful/odex_takaful/wizards/account_payment_register.py b/odex25_takaful/odex_takaful/wizards/account_payment_register.py index 9890cbf8d..68debfcd8 100644 --- a/odex25_takaful/odex_takaful/wizards/account_payment_register.py +++ b/odex25_takaful/odex_takaful/wizards/account_payment_register.py @@ -141,6 +141,15 @@ class AccountRegisterPayment(models.TransientModel): sponsorships = self.env['takaful.sponsorship'].browse(self.env.context.get('sponsorship_id')) branch_ids = sponsorships.mapped('branch_custom_id.id') rec.journal_id = rec.takaful_payment_method_id.journal_id.id + + # Set payment_method_line_id based on payment method name + pml = self.env['account.payment.method.line'].search([ + ('journal_id', '=', rec.journal_id.id), + ('name', '=', rec.takaful_payment_method_id.name) + ], limit=1) + if pml: + rec.payment_method_line_id = pml.id + payment_method = rec.takaful_payment_method_id.payment_method j_type = "" if payment_method == "cash": @@ -150,6 +159,18 @@ class AccountRegisterPayment(models.TransientModel): if j_type: return {"domain": {"journal_id": [("type", "=", j_type), ("branch_ids", "in", branch_ids)]}} + @api.onchange("journal_id") + def onchange_journal_id_set_payment_method_line(self): + """Set payment_method_line_id based on takaful_payment_method_id name when journal changes.""" + for rec in self: + if rec.journal_id and rec.takaful_payment_method_id and self.env.context.get('sponsorship_payment'): + pml = self.env['account.payment.method.line'].search([ + ('journal_id', '=', rec.journal_id.id), + ('name', '=', rec.takaful_payment_method_id.name) + ], limit=1) + if pml: + rec.payment_method_line_id = pml.id + @api.depends('source_amount', 'source_amount_currency', 'source_currency_id', 'company_id', 'currency_id', 'payment_date') def _compute_amount(self):