[IMP] odex_takaful: notes & improvements

This commit is contained in:
Abdurrahman Saber 2025-11-11 14:58:46 +02:00
parent 0ced8d2a5a
commit 19b31f161a
6 changed files with 65 additions and 16 deletions

View File

@ -70,6 +70,7 @@
'views/takaful_payment_method.xml',
'views/product_views.xml',
'data/message_template_data.xml',
'data/server_actions.xml',
'wizards/transfer_deduction_wizard_views.xml',
'reports/transfer_deduction_report.xml',

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data>
<record id="server_action_unlink_sponsor_and_related" model="ir.actions.server">
<!-- <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"/>
@ -9,7 +9,7 @@
<field name="code">
action = records.action_unlink_sponsor_and_related()
</field>
</record>
</record> -->
<record id="action_extend_donation" model="ir.actions.server">
<field name="name">Extend Donation</field>

View File

@ -136,6 +136,7 @@ class SchedulingLine(models.Model):
dont_redirect_to_payments=True,
schedule_line_id=line.id,
is_direct_debit=True,
sponsorship_id=sponsorship.id,
sponsorship_line_ids=line.donation_detail_linked_id.ids,
from_cron=True,
force_sponsorship_line_partner_id=line.donation_detail_linked_id.sponsor_id.id,

View File

@ -701,7 +701,10 @@ class TakafulSponsorship(models.Model):
@api.depends('payment_ids')
def _compute_state(self):
for sponsorship in self:
if sponsorship.payment_ids and sponsorship.amount_paid >= sponsorship.total_sponsorship_amount:
if not sponsorship.payment_ids:
sponsorship.state = sponsorship.state
continue
if sponsorship.amount_paid >= sponsorship.total_sponsorship_amount:
sponsorship.state = 'paid'
vendor_bill_vals = []
@ -741,7 +744,7 @@ class TakafulSponsorship(models.Model):
line.product_uom_id = line._get_computed_uom()
bill_id.action_post()
else:
sponsorship.state = sponsorship.state
sponsorship.state = 'wait_pay'
def copy(self, default=None):
self.ensure_one()

View File

@ -18,8 +18,6 @@ class DonationExtensionWizard(models.TransientModel):
default=lambda self: self._compute_line_ids(),
)
direct_debit = fields.Boolean(string='Direct Debit', required=True)
months = fields.Integer(
string='Extension Months',
required=True,
@ -48,10 +46,6 @@ class DonationExtensionWizard(models.TransientModel):
for rec in self:
if rec.months <= 0:
raise ValidationError(_("Extension months must be greater than 0."))
@api.onchange('direct_debit')
def _onchange_direct_debit(self):
self.line_ids.direct_debit = self.direct_debit
def action_extend(self):
"""
@ -106,6 +100,11 @@ class DonationExtensionWizardLine(models.TransientModel):
_name = 'donation.extension.wizard.line'
_description = "Donation Extension Wizard Line"
@api.model
def _default_journal_id(self):
journal_id = self.env.company.sponsorship_direct_debit_journal_id.id
return journal_id if journal_id else False
wizard_id = fields.Many2one('donation.extension.wizard', string='Wizard', required=True)
donation_line_id = fields.Many2one('donations.details.lines', string='Donation Detail', required=True, readonly=True)
donation_qty = fields.Float(compute='_compute_donation_qty', store=True)
@ -136,6 +135,10 @@ class DonationExtensionWizardLine(models.TransientModel):
compute='_compute_new_end_date',
readonly=True
)
direct_debit_partner_bank_id = fields.Many2one("res.partner.bank", string="Direct Debit Partner Bank", domain="[('partner_id', '=', partner_id)]")
debit_payment_file_attachment = fields.Binary(string='Debit Payment Attachment', attachment=True)
debit_payment_attachment_file_name = fields.Char('Debit Payment File Name', required=False)
journal_id = fields.Many2one('account.journal', string="Journal",domain="[('type','=','bank')]", default=_default_journal_id)
# related
record_type = fields.Selection(related='donation_line_id.record_type')
@ -146,6 +149,7 @@ class DonationExtensionWizardLine(models.TransientModel):
fixed_value = fields.Boolean(related='donation_line_id.fixed_value')
donation_mechanism = fields.Selection(related='donation_line_id.donation_mechanism')
months = fields.Integer(related='wizard_id.months')
partner_id = fields.Many2one(related='donation_line_id.sponsor_id')
@api.depends('benefits_count', 'donation_amount', 'months', 'donation_qty', 'record_type', 'sponsorship_type')
def _compute_total_donation_amount(self):
@ -187,12 +191,20 @@ class DonationExtensionWizardLine(models.TransientModel):
old_end_date = self.current_end_date
# Update end date
self.donation_line_id.write({
donation_line_new_vals = {
'end_date': new_end_date,
'donation_amount': self.total_months_amount,
'payment_month_count': self.donation_line_id.payment_month_count + self.months,
# 'state': 'extended',
})
}
if self.direct_debit:
donation_line_new_vals.update({
'direct_debit': self.direct_debit,
'direct_debit_partner_bank_id': self.direct_debit_partner_bank_id.id,
'journal_id': self.journal_id.id,
'debit_payment_file_attachment': self.debit_payment_file_attachment,
'debit_payment_attachment_file_name': self.debit_payment_attachment_file_name,
})
self.donation_line_id.write(donation_line_new_vals)
benefit_ids = self.donation_line_id.benefit_ids | self.donation_line_id.benefit_id
benefit_ids.write({
@ -218,6 +230,7 @@ class DonationExtensionWizardLine(models.TransientModel):
'invoice_id': invoice_id.id if invoice_id else False,
'old_direct_debit': self.donation_line_id.direct_debit,
'new_direct_debit': self.direct_debit,
})
if not self.direct_debit:

View File

@ -10,14 +10,12 @@
<group>
<group string="Extension Details">
<field name="months"/>
<field name="direct_debit"/>
</group>
</group>
<notebook>
<page string="Lines">
<field name="line_ids" nolabel="1">
<tree create="0" editable="bottom">
<tree create="0">
<field name="wizard_id" invisible="1" force_save="1"/>
<field name="months" invisible="1" force_save="1"/>
<field name="record_type" invisible="1" force_save="1"/>
@ -35,6 +33,39 @@
<field name="total_months_amount" string="Months Amount" force_save="1"/>
<field name="total_donation_amount" string="Total Amount" force_save="1"/>
</tree>
<form>
<field name="wizard_id" invisible="1" force_save="1"/>
<field name="months" invisible="1" force_save="1"/>
<field name="record_type" invisible="1" force_save="1"/>
<field name="sponsorship_type" invisible="1" force_save="1"/>
<field name="benefits_count" invisible="1" force_save="1"/>
<field name="sponsorship_id" invisible="1" force_save="1"/>
<field name="donation_mechanism" invisible="1" force_save="1"/>
<field name="fixed_value" invisible="1" force_save="1"/>
<field name="partner_id" invisible="1" force_save="1"/>
<field name="debit_payment_attachment_file_name" invisible="1"/>
<group>
<group>
<field name="donation_line_id" force_save="1"/>
<field name="current_end_date" force_save="1"/>
<field name="new_end_date" force_save="1"/>
<field name="direct_debit" force_save="1"/>
<field name="direct_debit_partner_bank_id"
context="{'form_view_ref': 'odex_takaful.res_partner_bank_view_form_quick_create', 'default_partner_id': partner_id}"
attrs="{'invisible': [('direct_debit', '=', False)], 'required': [('direct_debit', '=', True)]}"/>
<field name="journal_id" attrs="{'invisible': [('direct_debit', '=', False)], 'required': [('direct_debit', '=', True)]}"/>
<field name="debit_payment_file_attachment" widget="binary"
filename="debit_payment_attachment_file_name"
attrs="{'required': [('direct_debit', '=', True)], 'invisible': [('direct_debit', '=', False)]}"/>
</group>
<group>
<field name="donation_amount" string="Amount" attrs="{'readonly':[('fixed_value','=',True)]}" />
<field name="donation_qty" string="Qty" attrs="{'invisible':[('donation_mechanism','!=','without_conditions')]}"/>
<field name="total_months_amount" string="Months Amount" force_save="1"/>
<field name="total_donation_amount" string="Total Amount" force_save="1"/>
</group>
</group>
</form>
</field>
</page>
</notebook>