[FIX] odex_takaful: automatic update
Auto-generated commit based on local changes.
This commit is contained in:
parent
c45a55660f
commit
b8f04e62e8
|
|
@ -571,29 +571,31 @@ class TakafulSponsorship(models.Model):
|
|||
for rec in self:
|
||||
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):
|
||||
for rec in self:
|
||||
method = False
|
||||
# 1. Check if ANY donation line is Direct Debit. If so, default to Direct Debit as it's the intended primary method.
|
||||
is_direct_debit = any(line.direct_debit for line in rec.donations_details_lines)
|
||||
# Combine both One2many fields
|
||||
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:
|
||||
dd_method = self.env['takaful.payment.method'].search([('payment_method', '=', 'direct_debit')], limit=1)
|
||||
if dd_method:
|
||||
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:
|
||||
# Find latest posted payment for this sponsorship
|
||||
payment = self.env['account.payment'].search([
|
||||
('takaful_sponsorship_id', '=', rec.id),
|
||||
('state', '=', 'posted')
|
||||
], 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
|
||||
for line in all_lines:
|
||||
if line.payment_method_display:
|
||||
method = line.payment_method_display.id
|
||||
break
|
||||
|
||||
rec.payment_method_display = method
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue