Merge pull request #6109 from expsa/14.0-feat-other-auto-20260111_003353
[IMP] other odex_takaful: improve data models and business logic
This commit is contained in:
commit
1a8f040bac
|
|
@ -2,23 +2,3 @@ from . import models
|
|||
from . import controllers
|
||||
from . import reports
|
||||
from . import wizards
|
||||
|
||||
|
||||
def _update_payment_method_names(cr, registry):
|
||||
"""Update payment method names to Arabic after module installation/upgrade."""
|
||||
from odoo import api, SUPERUSER_ID
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
|
||||
translations = {
|
||||
'cash': 'نقدي',
|
||||
'bank': 'تحويل بنكي',
|
||||
'direct_debit': 'استقطاع',
|
||||
'check': 'شيك',
|
||||
'network': 'شبكة',
|
||||
}
|
||||
|
||||
PaymentMethod = env['takaful.payment.method']
|
||||
for method_key, arabic_name in translations.items():
|
||||
records = PaymentMethod.search([('payment_method', '=', method_key)])
|
||||
if records:
|
||||
records.write({'name': arabic_name})
|
||||
|
|
|
|||
|
|
@ -94,7 +94,6 @@
|
|||
'static/src/xml/takaful_dashboard.xml',
|
||||
],
|
||||
'icon': 'static/description/icon.png',
|
||||
'post_init_hook': '_update_payment_method_names',
|
||||
# 'installable': True,
|
||||
# 'application': True,
|
||||
# 'auto_install': False,
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<data>
|
||||
<!-- <record id="server_action_unlink_sponsor_and_related" model="ir.actions.server">
|
||||
<field name="name">Sponsor Unlink And Its Relations</field>
|
||||
<field name="model_id" ref="odex_takaful.model_takaful_sponsor"/>
|
||||
<field name="binding_model_id" ref="odex_takaful.model_takaful_sponsor"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">
|
||||
action = records.action_unlink_sponsor_and_related()
|
||||
</field>
|
||||
</record> -->
|
||||
|
||||
<record id="action_extend_donation" model="ir.actions.server">
|
||||
<field name="name">Extend Donation</field>
|
||||
<field name="model_id" ref="odex_takaful.model_donations_details_lines"/>
|
||||
<field name="binding_model_id" ref="odex_takaful.model_donations_details_lines"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">action = records.action_extend_sponsorship()</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
|
@ -135,6 +135,12 @@ class DonationsDetailsLines(models.Model):
|
|||
compute='_compute_payment_method_display',
|
||||
store=True
|
||||
)
|
||||
# Stored field to hold the actual payment method selected during payment
|
||||
takaful_payment_method_id = fields.Many2one(
|
||||
'takaful.payment.method',
|
||||
string='Payment Method (Stored)',
|
||||
help='Payment method selected during payment registration',
|
||||
)
|
||||
payment_method_type = fields.Selection(related='payment_method_display.payment_method', string='Payment Method Type', store=True)
|
||||
|
||||
|
||||
|
|
@ -220,22 +226,26 @@ class DonationsDetailsLines(models.Model):
|
|||
period_display = "منتهي"
|
||||
rec.period_display = period_display
|
||||
|
||||
@api.depends('direct_debit', 'sponsorship_id', 'sponsorship_mechanism_id')
|
||||
@api.depends('direct_debit', 'sponsorship_id', 'sponsorship_mechanism_id', 'takaful_payment_method_id')
|
||||
def _compute_payment_method_display(self):
|
||||
for rec in self:
|
||||
method = False
|
||||
# 1. Check Direct Debit first
|
||||
if rec.direct_debit:
|
||||
|
||||
# 1. PRIORITY: Use stored payment method if available (set during payment)
|
||||
if rec.takaful_payment_method_id:
|
||||
method = rec.takaful_payment_method_id.id
|
||||
|
||||
# 2. Check Direct Debit flag
|
||||
if not method and rec.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, check related Payments
|
||||
# 3. FALLBACK: If not stored, check related Payments via journal
|
||||
if not method:
|
||||
sponsorship_id = rec.sponsorship_id.id or rec.sponsorship_mechanism_id.id
|
||||
if sponsorship_id:
|
||||
# Find latest posted payment for this sponsorship
|
||||
# We use the related field 'takaful_sponsorship_id' on account.payment which is computed from the move
|
||||
payment = self.env['account.payment'].search([
|
||||
('takaful_sponsorship_id', '=', sponsorship_id),
|
||||
('state', '=', 'posted')
|
||||
|
|
|
|||
|
|
@ -191,7 +191,11 @@ class AccountRegisterPayment(models.TransientModel):
|
|||
state = 'paid'
|
||||
else:
|
||||
state = 'paid'
|
||||
line.write({'state': state})
|
||||
# Write both state and payment method to the line
|
||||
write_vals = {'state': state}
|
||||
if self.takaful_payment_method_id:
|
||||
write_vals['takaful_payment_method_id'] = self.takaful_payment_method_id.id
|
||||
line.write(write_vals)
|
||||
if self.env.context.get('schedule_line_payment'):
|
||||
schedule_line = self.env['sponsorship.scheduling.line'].browse(self.env.context.get('schedule_line_id'))
|
||||
schedule_line.sudo().write({'status': 'paid'})
|
||||
|
|
|
|||
Loading…
Reference in New Issue