Merge pull request #6117 from expsa/14.0-fix-odex_takaful-auto-20260111_130500
[FIX] odex_takaful: improve data models and business logic
This commit is contained in:
commit
0a83726576
|
|
@ -571,29 +571,31 @@ class TakafulSponsorship(models.Model):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.journal_entry_count_vendor = len(rec.journal_entry_ids.filtered(lambda r: r.move_type == 'in_invoice'))
|
rec.journal_entry_count_vendor = len(rec.journal_entry_ids.filtered(lambda r: r.move_type == 'in_invoice'))
|
||||||
|
|
||||||
@api.depends('donations_details_lines.payment_method_display', 'donations_details_lines.direct_debit')
|
@api.depends(
|
||||||
|
'donations_details_lines.payment_method_display',
|
||||||
|
'donations_details_lines.direct_debit',
|
||||||
|
'donations_details_lines_mechanism_ids.payment_method_display',
|
||||||
|
'donations_details_lines_mechanism_ids.direct_debit'
|
||||||
|
)
|
||||||
def _compute_payment_method_display(self):
|
def _compute_payment_method_display(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
method = False
|
method = False
|
||||||
# 1. Check if ANY donation line is Direct Debit. If so, default to Direct Debit as it's the intended primary method.
|
# Combine both One2many fields
|
||||||
is_direct_debit = any(line.direct_debit for line in rec.donations_details_lines)
|
all_lines = rec.donations_details_lines | rec.donations_details_lines_mechanism_ids
|
||||||
|
|
||||||
|
# 1. Check if ANY donation line is Direct Debit
|
||||||
|
is_direct_debit = any(line.direct_debit for line in all_lines)
|
||||||
if is_direct_debit:
|
if is_direct_debit:
|
||||||
dd_method = self.env['takaful.payment.method'].search([('payment_method', '=', 'direct_debit')], limit=1)
|
dd_method = self.env['takaful.payment.method'].search([('payment_method', '=', 'direct_debit')], limit=1)
|
||||||
if dd_method:
|
if dd_method:
|
||||||
method = dd_method.id
|
method = dd_method.id
|
||||||
|
|
||||||
# 2. If not Direct Debit, find the latest payment for this sponsorship
|
# 2. Get from donation lines directly (THE FIX!)
|
||||||
if not method:
|
if not method:
|
||||||
# Find latest posted payment for this sponsorship
|
for line in all_lines:
|
||||||
payment = self.env['account.payment'].search([
|
if line.payment_method_display:
|
||||||
('takaful_sponsorship_id', '=', rec.id),
|
method = line.payment_method_display.id
|
||||||
('state', '=', 'posted')
|
break
|
||||||
], order='date desc', limit=1)
|
|
||||||
|
|
||||||
if payment and payment.journal_id:
|
|
||||||
payment_method = self.env['takaful.payment.method'].search([('journal_id', '=', payment.journal_id.id)], limit=1)
|
|
||||||
if payment_method:
|
|
||||||
method = payment_method.id
|
|
||||||
|
|
||||||
rec.payment_method_display = method
|
rec.payment_method_display = method
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue