Merge branch 'dev_odex25_takaful' of https://github.com/expsa/odex25-standard-modules into esterdad_bugs

 Conflicts:
	odex25_takaful/odex_takaful/wizards/account_payment_register.py
This commit is contained in:
Ali Ammar 2025-12-14 09:55:23 +03:00
commit dd54c2c859
10 changed files with 185 additions and 160 deletions

View File

@ -7580,3 +7580,37 @@ msgstr "إجمالي مبلغ الدفع"
#: model:ir.model.fields,field_description:odex_takaful.field_donation_extension_wizard__remaining_amount
msgid "Remaining Amount"
msgstr "المبلغ المتبقى"
#. module: odex_takaful
#: model:ir.model.fields,field_description:odex_takaful.field_donations_details_lines__direct_debit_filter
msgid "Payment Type (Filter)"
msgstr "طريقة الدفع"
#. module: odex_takaful
#: model:ir.model.fields.selection,name:odex_takaful.selection__donations_details_lines__direct_debit_filter__other
#: model_terms:ir.ui.view,arch_db:odex_takaful.donations_details_lines_view_search
msgid "Other Payments"
msgstr "طرق اخرى"
#. module: odex_takaful
#: model:ir.model.fields.selection,name:odex_takaful.selection__donations_details_lines__direct_debit_filter__direct
#: model_terms:ir.ui.view,arch_db:odex_takaful.donations_details_lines_view_search
msgid "Direct Debit"
msgstr "إستقطاع"
#. module: odex_takaful
#: model:ir.model.fields,field_description:odex_takaful.field_donations_details_lines__number_of_family_member
#: model:ir.model.fields,field_description:odex_takaful.field_family_member__number_of_family_member
msgid "Number Of Family Member"
msgstr "عدد افراد الاسرة"
#. module: odex_takaful
#: model:ir.model.fields,field_description:odex_takaful.field_donations_details_lines__age
msgid "Age"
msgstr "العمر"
#. module: odex_takaful
#: model:ir.model.fields,field_description:odex_takaful.field_donations_details_lines__diseases_attachment_ids
msgid "Diseases Attachment"
msgstr "الأمراض"

View File

@ -49,7 +49,7 @@ class DonationsDetailsLines(models.Model):
education_status = fields.Selection(string='Education Status',
selection=[('educated', 'educated'), ('illiterate', 'illiterate'),
('under_study_age', 'Under Study Age')])
education_level = fields.Many2one("education.level", string='Education Levels')
education_level = fields.Many2one(related='benefit_id.education_levels', string='Education Levels', store=True)
members_domain_ids = fields.Many2many('family.member', compute='_compute_members_domain_ids')
family_domain_ids = fields.Many2many('grant.benefit', compute='_compute_family_domain_ids')
@ -98,7 +98,10 @@ class DonationsDetailsLines(models.Model):
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)
benefit_status = fields.Selection(related='benefit_id.member_status')
diseases_attachment_ids = fields.Many2many('ir.attachment', compute='_compute_get_diseases')
ages = fields.Integer(compute='_compute_get_age_range' , store=True)
age = fields.Integer(related='benefit_id.age')
number_of_family_member = fields.Integer(related='benefit_id.number_of_family_member')
waiting_date = fields.Date(
string="تاريخ الانتظار",
)
@ -113,6 +116,30 @@ class DonationsDetailsLines(models.Model):
('all', 'جميع الأعمار'),
], string="الفئة العمرية", compute="_compute_age_category")
direct_debit_filter = fields.Selection(
[
('direct', 'Direct Debit'),
('other', 'Other Payments'),
],
string="Payment Type (Filter)",
compute="_compute_direct_debit_filter", store=True,
)
@api.depends('benefit_id.diseases_attachment_ids')
def _compute_get_diseases(self):
for rec in self:
rec.diseases_attachment_ids = rec.benefit_id.diseases_attachment_ids.ids
@api.depends('direct_debit')
def _compute_direct_debit_filter(self):
for rec in self:
if rec.direct_debit:
rec.direct_debit_filter = 'direct'
else:
rec.direct_debit_filter = 'other'
can_edit_benefit = fields.Boolean(
string="Can Edit Benefit",

View File

@ -9,6 +9,9 @@ class GrantBenefit(models.Model):
def action_second_accepted(self):
super(GrantBenefit, self).action_second_accepted()
for member in self.member_ids:
if not member.is_new and member.member_status == 'benefit':
member.is_restricted = True
member.is_new = True
sponsorships_main = self.env['donations.details.lines'].search([
('benefit_id', '=', member.id,),('state', '=', 'active')
])
@ -35,10 +38,34 @@ class FamilyMember(models.Model):
sponsorship_id = fields.Many2one('takaful.sponsorship', string='Sponsorship')
sponsorship_end_date = fields.Date(string='Sponsorship End Date')
is_restricted = fields.Boolean(string="Is Restricted ?", default=False, readonly=True)
is_new = fields.Boolean(string="Is new ?", default=False, readonly=True)
general_restriction = fields.Boolean(string="General Restriction", default=False, readonly=True)
kafala_status = fields.Selection(
[('have_kafala', 'Have Kafala'), ('have_not_kafala', 'Have not Kafala')],
string='Kafala Status', compute='_compute_kafala_status', store=True, readonly=True)
education_levels = fields.Many2one("education.level", string='Education Levels', compute='_compute_education_levels', store=True)
number_of_family_member = fields.Integer(compute='_compute_number_of_family_member' , store=True, string='Number Of Family Member')
@api.depends('benefit_id','relationn','member_status')
def _compute_number_of_family_member(self):
for rec in self:
if rec.relationn.relation_type in ('mother', 'replacement_mother'):
family_members = rec.benefit_id.member_ids.filtered(
lambda m: m.relationn.relation_type in ('daughter', 'son') and m.member_status == 'benefit'
)
rec.number_of_family_member = len(family_members)
@api.depends('member_education_status_ids', 'education_status', 'member_education_status_ids.case_study')
def _compute_education_levels(self):
for record in self:
record.education_levels = (
record.member_education_status_ids.search(
[('case_study', '=', 'continuous')],
order='create_date desc',
limit=1
).education_levels if record.education_status == 'educated' else False)
@api.depends('sponsor_related_id')
def _compute_kafala_status(self):
@ -79,30 +106,9 @@ class FamilyMember(models.Model):
today = fields.Date.today()
restriction_period = self.env['ir.config_parameter'].sudo().get_param('odex_takaful.restriction_period')
for benefit in benefit_ids:
create_date = benefit.create_date.date()
create_date = benefit.benefit_id.approve_date
benefit_date = create_date + timedelta(days=int(restriction_period) or 0)
if benefit_date >= today:
benefit_date_to = today - timedelta(days=int(restriction_period) or 0)
if benefit_date >= today or benefit_date <= benefit_date_to:
benefit.is_restricted = False
def create(self, vals):
res = super(FamilyMember, self).create(vals)
self.is_restricted = True
return res
# @api.model
# def write(self, vals):
# res = super(FamilyMember, self).write(vals)
# if 'member_status' in vals:
# for member in self:
# sponsorships_main = self.env['donations.details.lines'].search([
# ('benefit_id', '=', member.id)
# ])
# sponsorships_multi = self.env['donations.details.lines'].search([
# ('benefit_ids', 'in', member.id)
# ])
# sponsorships = sponsorships_main | sponsorships_multi
#
# if sponsorships:
# if member.member_status and member.member_status == 'non_benefit' and sponsorships.sponsorship_id.record_type == 'sponsorship':
# sponsorships.write({'state': 'replace'})
# return res

View File

@ -1445,7 +1445,7 @@ class TakafulSponsorship(models.Model):
'price_unit': line.total_donation_amount,
'quantity': 1,
'name': _("Sponsorship Entitlement Number %s") % line.sequence_no,
'analytic_account_id': line.sponsorship_id.branch_custom_id.branch.analytic_account_id.id,
'analytic_account_id': line.sponsorship_id.branch_custom_id.branch.analytic_account_id.id or line.sponsorship_mechanism_id.branch_custom_id.branch.analytic_account_id.id,
}) for line in all_donation_lines]
current_invoice = self.journal_entry_ids.filtered(lambda r: r.move_type == 'out_invoice' and r.state == 'draft')

View File

@ -11,6 +11,7 @@
<field name="benefit_id"/>
<field name="product_template_id"/>
<field name="branch_custom_id"/>
<field name="education_level"/>
<separator/>
<!-- State Filters -->
<filter string="To Pay" name="filter_draft" domain="[('state', '=', 'draft')]"/>
@ -33,6 +34,10 @@
<filter string="With Conditions" name="filter_with_conditions" domain="[('donation_mechanism', '=', 'with_conditions')]"/>
<filter string="Without Conditions" name="filter_without_conditions" domain="[('donation_mechanism', '=', 'without_conditions')]"/>
<separator/>
<!-- Sponsorship payment type Filters -->
<filter string="Direct Debit " name="filter_direct_debit" domain="[('direct_debit', '=', 'True')]"/>
<filter string="Other Payments" name="filter_other_payment" domain="[('direct_debit', '!=', 'True')]"/>
<separator/>
<filter string="Without Beneficiary" name="filter_no_benefit" domain="[('benefit_id', '=', False), ('donation_type', '=', 'sponsorship')]"/>
<filter string="With Beneficiary" name="filter_with_benefit" domain="[('benefit_id', '!=', False), ('donation_type', '=', 'sponsorship')]"/>
@ -54,6 +59,8 @@
<field name="record_type" enable_counters="1"/>
<field name="sponsorship_duration" enable_counters="1"/>
<field name="donation_mechanism" enable_counters="1"/>
<field name="direct_debit_filter" enable_counters="1"/>
</searchpanel>
</search>
</field>
@ -77,6 +84,10 @@
<field name="benefit_status" widget="badge"
decoration-success="benefit_status == 'benefit'"
decoration-danger="benefit_status == 'non_benefit'" optional="hide"/>
<field name="education_level" optional="hide"/>
<field name="age"/>
<field name="number_of_family_member" optional="hide"/>
<field name="diseases_attachment_ids" widget="many2many_tags" optional="hide"/>
<field name="start_date" widget="date" optional="hide"/>
<field name="end_date" widget="date" optional="hide"/>
<field name="donation_amount" widget="monetary" options="{'currency_field': 'currency_id'}"/>
@ -375,6 +386,10 @@
<field name="benefit_status" widget="badge"
decoration-success="benefit_status == 'benefit'"
decoration-danger="benefit_status == 'non_benefit'"/>
<field name="education_level" optional="hide"/>
<field name="age"/>
<field name="number_of_family_member" optional="hide"/>
<field name="diseases_attachment_ids" widget="many2many_tags" optional="hide"/>
<field name="start_date" widget="date" optional="hide"/>
<field name="end_date" widget="date" optional="hide"/>
<field name="donation_amount" widget="monetary" options="{'currency_field': 'currency_id'}"/>
@ -424,6 +439,10 @@
<field name="benefit_status" widget="badge"
decoration-success="benefit_status == 'benefit'"
decoration-danger="benefit_status == 'non_benefit'"/>
<field name="education_level" optional="hide"/>
<field name="age"/>
<field name="number_of_family_member" optional="hide"/>
<field name="diseases_attachment_ids" widget="many2many_tags" optional="hide"/>
<field name="start_date" widget="date"/>
<field name="end_date" widget="date"/>
<field name="donation_amount" widget="monetary" options="{'currency_field': 'currency_id'}"/>

View File

@ -17,6 +17,7 @@
<field name="sponsor_related_id" readonly="1" invisible="1"/>
</xpath>
<xpath expr="//page[4]" position="after">
<page name="kafala_info" string="Kafala Information">
<group>
@ -62,6 +63,7 @@
<field name="inherit_id" ref="odex_benefit.family_member_search"/>
<field name="arch" type="xml">
<field name="benefit_id" position="after">
<field name="education_levels"/>
<separator/>
<filter name="have_kafala" string="Have Kafala"
domain="[('kafala_status','=','have_kafala')]"/>
@ -96,6 +98,11 @@
<filter name="under_study_age_educated_status" string="Under Study Age"
domain="[('education_status', '=', 'under_study_age')]"/>
<separator/>
<group>
<filter string="Education Level"
name="group_education_level"
context="{'group_by': 'education_levels'}"/>
</group>
</field>
</field>
</record>
@ -110,6 +117,9 @@
decoration-success="kafala_status == 'have_kafala'"
decoration-danger="kafala_status == 'have_not_kafala'"/>
<field name="sponsorship_end_date" optional="hide" />
<field name="education_levels" optional="hide" />
<field name="number_of_family_member" optional="hide" />
<field name="diseases_attachment_ids" widget="many2many_tags" optional="hide" />
</xpath>
</field>
</record>

View File

@ -38,19 +38,21 @@ class AccountRegisterPayment(models.TransientModel):
string="Show Cancel Button",
compute="_compute_show_cancel_button"
)
apply_old_payment = fields.Boolean(string="Use Previous Payment")
pay_from_old_payment = fields.Monetary(
string="Pay from Old Payment",
currency_field="currency_id",
default=0.0
)
available_old_payment = fields.Monetary(
string="Available Old Payment",
currency_field="currency_id",
compute="_compute_available_old_payment",
help="Unreconciled posted customer payments that can be used to reduce the current payment."
show_payment_group = fields.Boolean(
string="Show Payment Group",
compute="_compute_show_payment_group"
)
@api.depends('can_group_payments')
def _compute_show_payment_group(self):
active_ids = self.env.context.get('active_ids', [])
invoices = self.env['account.move'].browse(active_ids)
unique_partners = invoices.mapped('partner_id')
for rec in self:
rec.show_payment_group = (len(unique_partners) == 1)
@api.depends_context('wiz_id')
def _compute_show_cancel_button(self):
for rec in self:
@ -76,58 +78,13 @@ class AccountRegisterPayment(models.TransientModel):
if j_type:
return {"domain": {"journal_id": [("type", "=", j_type)]}}
@api.depends('partner_id', 'company_id')
def _compute_available_old_payment(self):
AccountMoveLine = self.env['account.move.line']
for wizard in self:
if not wizard.partner_id:
wizard.available_old_payment = 0.0
continue
lines = AccountMoveLine.search([
('partner_id', '=', wizard.partner_id.id),
('account_internal_type', 'in', ('receivable', 'payable')),
('reconciled', '=', False),
('payment_id', '!=', False),
('company_id', '=', wizard.company_id.id),
('move_id.state', '=', 'posted'),
])
# amount_residual keeps the sign of the line. Use abs so inbound/outbound credits work.
wizard.available_old_payment = sum(abs(line.amount_residual) for line in lines)
@api.onchange('apply_old_payment')
def _onchange_apply_old_payment(self):
for wizard in self:
if wizard.apply_old_payment:
wizard.pay_from_old_payment = wizard.available_old_payment
else:
wizard.pay_from_old_payment = 0.0
@api.onchange('pay_from_old_payment')
def _onchange_pay_from_old_payment(self):
for wizard in self:
if wizard.pay_from_old_payment > wizard.available_old_payment:
wizard.pay_from_old_payment = wizard.available_old_payment
if wizard.pay_from_old_payment < 0:
wizard.pay_from_old_payment = 0.0
@api.depends(
'source_amount', 'source_amount_currency', 'source_currency_id',
'company_id', 'currency_id', 'payment_date',
'apply_old_payment', 'pay_from_old_payment', 'available_old_payment'
)
@api.depends('source_amount', 'source_amount_currency', 'source_currency_id', 'company_id', 'currency_id', 'payment_date')
def _compute_amount(self):
if self.env.context.get('sponsorship_payment_skip_compute_amount'):
self.amount = self.amount
else:
super(AccountRegisterPayment, self)._compute_amount()
for wizard in self:
if wizard.apply_old_payment and wizard.pay_from_old_payment:
applied = min(
wizard.pay_from_old_payment,
wizard.available_old_payment,
wizard.amount
)
wizard.amount = wizard.amount - applied
@api.depends('takaful_payment_method_id')
def _compute_takaful_payment_method(self):

View File

@ -9,6 +9,10 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='amount']" position="after">
<field name="is_refund_sponsorship" invisible="1"/>
<field name="show_payment_group" invisible="1"/>
</xpath>
<xpath expr="//field[@name='group_payment']" position="attributes">
<attribute name="attrs">{'invisible':['|', ('show_payment_group','=',False), ('can_group_payments', '=', False)]}</attribute>
</xpath>
<!-- <xpath expr="//field[@name='amount']" position="attributes">-->
<!-- <attribute name="attrs">{'readonly':[('group_payment','=',True)]}</attribute>-->
@ -62,79 +66,6 @@
<xpath expr="//footer/button[2]" position="attributes">
<attribute name="attrs">{'invisible':[('show_cancel_button','=',False)]}</attribute>
</xpath>
<!--<xpath expr="//group" position="after">-->
<!-- <notebook>-->
<!-- <page string="Sub Payments" attrs="{'invisible': [('group_payment', '=', False)]}">-->
<!-- <field name="account_payment_register_ids" attrs="{'invisible': [('group_payment', '=', False)]}" nolabel="1">-->
<!-- <tree editable="bottom" delete="true" create="true">-->
<!-- <field name="sponsorship_payment" invisible="1"/>-->
<!-- <field name="takaful_payment_method" invisible="1"/>-->
<!-- <field name="available_partner_bank_ids" invisible="1"/>-->
<!-- <field name="company_id" invisible="1"/>-->
<!-- <field name="takaful_payment_method_id" options="{'no_create': True, 'no_create_edit': True}"/>-->
<!-- <field name="journal_id" string="Association Journal"/>-->
<!-- <field name="amount"/>-->
<!-- <field name="check_number"-->
<!-- attrs="{-->
<!-- 'invisible': [-->
<!-- ('takaful_payment_method','!=','check')-->
<!-- ],-->
<!-- 'required': [-->
<!-- ('takaful_payment_method','=','check')-->
<!-- ]-->
<!-- }"-->
<!-- optional="hide"/>-->
<!-- <field name="check_due_date"-->
<!-- attrs="{-->
<!-- 'invisible': [-->
<!-- ('takaful_payment_method','!=','check')-->
<!-- ],-->
<!-- 'required': [-->
<!-- ('takaful_payment_method','=','check')-->
<!-- ]-->
<!-- }"-->
<!-- optional="hide"/>-->
<!-- <field name="partner_bank_id"-->
<!-- context="{-->
<!-- 'form_view_ref': 'odex_takaful.res_partner_bank_view_form_quick_create',-->
<!-- 'default_partner_id': context.get('force_sponsorship_line_partner_id')-->
<!-- }"-->
<!-- attrs="{-->
<!-- 'required': [-->
<!-- ('takaful_payment_method','=','bank')-->
<!-- ],-->
<!-- 'invisible': [-->
<!-- ('takaful_payment_method','!=','bank')-->
<!-- ]-->
<!-- }"-->
<!-- readonly="0"-->
<!-- optional="hide"/>-->
<!-- <field name="transaction_file_attachment"-->
<!-- widget="binary"-->
<!-- filename="transaction_attachment_file_name"-->
<!-- attrs="{-->
<!-- 'invisible': [-->
<!-- ('takaful_payment_method','not in',['bank', 'check'])-->
<!-- ],-->
<!-- 'required': ['|',-->
<!-- ('takaful_payment_method','=','bank'),-->
<!-- ('takaful_payment_method','=','check')-->
<!-- ]-->
<!-- }"-->
<!-- optional="hide"/>-->
<!-- </tree>-->
<!-- </field>-->
<!-- </page>-->
<!-- </notebook>-->
<!-- </xpath>-->
<!-- <xpath expr="//footer/button[@name='action_create_payments']" position="after">-->
<!-- <button name="action_register_all_lines"-->
<!-- type="object"-->
<!-- string="Register All Lines"-->
<!-- class="btn-secondary"-->
<!-- attrs="{'invisible': [('line_ids','=',False)]}"/>-->
<!-- </xpath>-->
</field>
</record>

View File

@ -153,6 +153,10 @@ class DonationExtensionWizard(models.TransientModel):
"""
Cancel the wizard
"""
for rec in self:
for line in rec.line_ids:
line.cancel_extension()
return {'type': 'ir.actions.act_window_close'}
class ExtensionPaymentWizardLine(models.TransientModel):
@ -273,6 +277,8 @@ class DonationExtensionWizardLine(models.TransientModel):
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)
old_end_date = fields.Date()
old_payment_month_count = fields.Integer()
# related
record_type = fields.Selection(related='donation_line_id.record_type')
@ -321,6 +327,9 @@ class DonationExtensionWizardLine(models.TransientModel):
raise ValidationError(_("No donation detail line selected."))
if not self.extension_invoice_id:
# Update the donation detail line
self.old_end_date = self.current_end_date
self.old_payment_month_count = self.donation_line_id.payment_month_count
new_end_date = self.current_end_date + relativedelta(months=self.months)
old_end_date = self.current_end_date
@ -456,4 +465,36 @@ class DonationExtensionWizardLine(models.TransientModel):
invoice_id.action_post()
return invoice_id
def cancel_extension(self):
self.ensure_one()
if self.extension_invoice_id:
invoice = self.extension_invoice_id
if invoice.state == 'posted':
invoice.button_draft()
invoice.button_cancel()
else:
invoice.button_cancel()
scheduling_lines = self.env['sponsorship.scheduling.line'].search([
('donation_detail_linked_id', '=', self.donation_line_id.id),
('scheduled_date', '>', self.old_end_date)
])
scheduling_lines.sudo().unlink()
self.donation_line_id.write({
'end_date': self.old_end_date,
'payment_month_count': self.old_payment_month_count,
})
history_records = self.env['donation.extension.history'].search([
('donation_detail_id', '=', self.donation_line_id.id),
('invoice_id', '=', self.extension_invoice_id.id if self.extension_invoice_id else False),
('new_end_date', '=', self.new_end_date),
])
history_records.sudo().unlink()
return True

View File

@ -98,7 +98,7 @@
</sheet>
<footer>
<button name="action_extend" type="object" string="Extend" class="oe_highlight"/>
<button name="action_cancel" type="object" string="Cancel" special="cancel" attrs="{'invisible': [('is_different_payment', '=', True)]}"/>
<button name="action_cancel" type="object" string="Cancel" class="btn-secondary" />
</footer>
</form>
</field>