From ed6407c65eb12ca3d5d0198140757de0ad4ab6ca Mon Sep 17 00:00:00 2001 From: Samir Ladoui Date: Sat, 24 Jan 2026 02:17:48 +0100 Subject: [PATCH] [UPD] odex_takaful --- odex25_takaful/odex_takaful/i18n/ar_001.po | 6 + .../odex_takaful/models/account_move.py | 3 + .../models/takaful_sponorship_model.py | 16 +- .../odex_takaful/views/acount_move.xml | 13 +- .../views/takaful_sponorship_view.xml | 15 +- .../odex_takaful/wizards/esterdad.py | 186 ++++++++++-------- .../odex_takaful/wizards/esterdad.xml | 19 +- 7 files changed, 150 insertions(+), 108 deletions(-) diff --git a/odex25_takaful/odex_takaful/i18n/ar_001.po b/odex25_takaful/odex_takaful/i18n/ar_001.po index ac4e4ea17..a6fcb3bdd 100644 --- a/odex25_takaful/odex_takaful/i18n/ar_001.po +++ b/odex25_takaful/odex_takaful/i18n/ar_001.po @@ -2982,6 +2982,7 @@ msgstr "مفوتر" #: model:ir.model.fields,field_description:odex_takaful.field_sponsorship_payment__invoice_ids #: model:ir.model.fields,field_description:odex_takaful.field_takaful_sponsorship__invoice_count #: model_terms:ir.ui.view,arch_db:odex_takaful.takaful_sponsorship_form +#: model_terms:ir.ui.view,arch_db:odex_takaful.view_esterdad_wizard_form #, python-format msgid "Invoices" msgstr "الفواتير" @@ -7581,3 +7582,8 @@ msgstr "التمديد الشامل" #: model:ir.actions.server,name:odex_takaful.server_action_print_mother_and_orphan_reports msgid "Print Mother/Orphan Report" msgstr "طباعة تقرير أم اليتيم/اليتيم" + +#. module: odex_takaful +#: model_terms:ir.ui.view,arch_db:odex_takaful.takaful_account_move_inherit_form +msgid "Previous Payments" +msgstr "المدفوعات السابقة" \ No newline at end of file diff --git a/odex25_takaful/odex_takaful/models/account_move.py b/odex25_takaful/odex_takaful/models/account_move.py index 552181d0d..c1b6af496 100644 --- a/odex25_takaful/odex_takaful/models/account_move.py +++ b/odex25_takaful/odex_takaful/models/account_move.py @@ -15,6 +15,9 @@ class AccountMove(models.Model): payment_id = fields.Many2one('account.payment', string='Payment', copy=False) esterdad_id = fields.Many2one('esterdad.wizard') + previous_payment_ids = fields.Many2many(related='esterdad_id.payment_ids') + sponsorship_cancel_reason = fields.Text(readonly=True) + def action_view_esterdad_id(self): self.ensure_one() diff --git a/odex25_takaful/odex_takaful/models/takaful_sponorship_model.py b/odex25_takaful/odex_takaful/models/takaful_sponorship_model.py index ee46b8110..37fc58c6d 100644 --- a/odex25_takaful/odex_takaful/models/takaful_sponorship_model.py +++ b/odex25_takaful/odex_takaful/models/takaful_sponorship_model.py @@ -330,9 +330,9 @@ class TakafulSponsorship(models.Model): context = dict(self.env.context or {}) context['default_sponsor_id'] = rec.id context['default_pay_date'] = rec.pay_date - context['default_amount'] = rec.total_sponsorship_amount + # context['default_amount'] = rec.total_sponsorship_amount context['default_sponsor_name'] = rec.sponsor_id.first_name - context['default_mobile'] = rec.sponsor_id.mobile + context['default_mobile'] = rec.sponsor_phone context['default_id_num'] = rec.sponsor_id.id_number # context['default_payment_ids'] = rec.payment_ids.ids view = self.env.ref('odex_takaful.view_esterdad_wizard_form') @@ -349,13 +349,11 @@ class TakafulSponsorship(models.Model): else: raise UserError(_("You cannot do this. The refund period has expired.")) - - - @api.depends('sponsor_id','sponsor_id.mobile') + @api.depends('sponsor_id', 'sponsor_id.mobile') def _compute_sponsor_phone(self): - for rec in self: - if rec.sponsor_id.id != rec.env.company.faal_kheer_partner_id.id: - rec.sponsor_phone = rec.sponsor_id.mobile if rec.sponsor_id else False + for rec in self.filtered(lambda r: r.state in ['draft']): + if rec.sponsor_or_donor_type == 'registered': + rec.sponsor_phone = rec.sponsor_id.mobile def compute_days_after_payment(self): """Check if the number of hours passed after payment is within the configured limit""" @@ -1057,7 +1055,7 @@ class TakafulSponsorship(models.Model): rec.sponsor_donor_type = 'registered' # Update related fields from selected sponsor - rec.sponsor_phone = rec.sponsor_id.mobile + # rec.sponsor_phone = rec.sponsor_id.mobile rec.preferred_communication = rec.sponsor_id.preferred_communication @api.model diff --git a/odex25_takaful/odex_takaful/views/acount_move.xml b/odex25_takaful/odex_takaful/views/acount_move.xml index a0d6b6826..f01a0f180 100644 --- a/odex25_takaful/odex_takaful/views/acount_move.xml +++ b/odex25_takaful/odex_takaful/views/acount_move.xml @@ -5,6 +5,13 @@ account.move + + + {'invisible': False} @@ -14,7 +21,11 @@ - + + + + + diff --git a/odex25_takaful/odex_takaful/views/takaful_sponorship_view.xml b/odex25_takaful/odex_takaful/views/takaful_sponorship_view.xml index 27603185a..5fad601e3 100644 --- a/odex25_takaful/odex_takaful/views/takaful_sponorship_view.xml +++ b/odex25_takaful/odex_takaful/views/takaful_sponorship_view.xml @@ -193,7 +193,7 @@ ] }"/>
- - - + 'required': [('sponsor_or_donor_type', '!=', 'unknown')], + 'readonly': [('state', '!=', 'draft')] + }"/> = limit_refund_date_time).ids + + @api.depends('journal_entry_ids') + def _compute_payment_ids(self): + for rec in self: + rec.payment_ids = [(6, 0, rec.journal_entry_ids.payment_id.ids)] + + # @api.onchange('sponsor_id') + # def _onchange_sponsor_id_set_payment_domain(self): + # """Limit available payments to same partner within restriction_period days.""" + # for rec in self: + # domain = [] + # partner = False + # invoice_names = [] - if rec.sponsor_id: - # Assuming sponsor_id.sponsor_id is the related partner on the sponsorship - partner = getattr(rec.sponsor_id, 'sponsor_id', False) or getattr(rec.sponsor_id, 'partner_id', False) + # if rec.sponsor_id: + # # Assuming sponsor_id.sponsor_id is the related partner on the sponsorship + # partner = getattr(rec.sponsor_id, 'sponsor_id', False) or getattr(rec.sponsor_id, 'partner_id', False) - # Get all invoices from journal_entry_ids where move_type is 'out_invoice' - invoices = rec.sponsor_id.journal_entry_ids.filtered(lambda inv: inv.move_type == 'out_invoice') - # Get all invoice names (numbers) in a list - invoice_names = invoices.mapped('name') + # # Get all invoices from journal_entry_ids where move_type is 'out_invoice' + # invoices = rec.sponsor_id.journal_entry_ids.filtered(lambda inv: inv.move_type == 'out_invoice') + # # Get all invoice names (numbers) in a list + # invoice_names = invoices.mapped('name') - if partner: - # Get restriction period (in days) from config parameters - sudo_conf = self.env['ir.config_parameter'].sudo() - restriction_period = sudo_conf.get_param('odex_takaful.restriction_period') + # if partner: + # # Get restriction period (in days) from config parameters + # sudo_conf = self.env['ir.config_parameter'].sudo() + # restriction_period = sudo_conf.get_param('odex_takaful.restriction_period') - try: - restriction_period = int(restriction_period or 0) - except (TypeError, ValueError): - restriction_period = 0 + # try: + # restriction_period = int(restriction_period or 0) + # except (TypeError, ValueError): + # restriction_period = 0 - if restriction_period and restriction_period > 0: - limit_date = date.today() - timedelta(days=restriction_period) - domain = [ - ('partner_id', '=', partner.id), - ('date', '>=', limit_date), - ] - else: - # If no restriction configured, just filter by partner - domain = [('partner_id', '=', partner.id)] + # if restriction_period and restriction_period > 0: + # limit_date = date.today() - timedelta(days=restriction_period) + # domain = [ + # ('partner_id', '=', partner.id), + # ('date', '>=', limit_date), + # ] + # else: + # # If no restriction configured, just filter by partner + # domain = [('partner_id', '=', partner.id)] - # Add filter for ref field to match invoice names if we have any - if invoice_names: - domain.append(('ref', 'in', invoice_names)) + # # Add filter for ref field to match invoice names if we have any + # if invoice_names: + # domain.append(('ref', 'in', invoice_names)) + + # # If we have a domain, fetch the matching payments and store them + # # in the helper field, then use their IDs as the domain. + # if domain: + # payments = self.env['account.payment'].search(domain) + # rec.allowed_payment_ids = payments + # return {'domain': {'payment_ids': [('id', 'in', payments.ids)]}} + # else: + # rec.allowed_payment_ids = False + # return {'domain': {'payment_ids': []}} - # If we have a domain, fetch the matching payments and store them - # in the helper field, then use their IDs as the domain. - if domain: - payments = self.env['account.payment'].search(domain) - rec.allowed_payment_ids = payments - return {'domain': {'payment_ids': [('id', 'in', payments.ids)]}} - else: - rec.allowed_payment_ids = False - return {'domain': {'payment_ids': []}} def action_confirm_refund(self): for rec in self: user = rec.sponsor_id.sponsor_id.kafel_id @@ -102,11 +115,15 @@ class EsterdadWizard(models.Model): context = dict(self.env.context or {}) context['default_user_id'] = user.id context['default_otp'] = user.otp_code - context['default_esterdad_id'] = rec.id + context['default_esterdad_id'] = rec.id + context['default_invoice_ids'] = rec.journal_entry_ids.ids + context['default_cancel_reason'] = rec.cancel_reason.name if not rec.another_reason else rec.reason rec.sponsor_id.write({ 'cancel_record_id': rec.id }) - context['default_payment_ids'] = [(6, 0, rec.payment_ids.ids)] + if rec.sponsor_id.sponsor_or_donor_type == 'unknown' and not rec.sponsor_id.sponsor_phone: + rec.sponsor_id.sponsor_phone = rec.mobile + # context['default_payment_ids'] = [(6, 0, rec.payment_ids.ids)] view = self.env.ref('odex_takaful.view_otp_wizard_form') return { 'name': _('OTP Confirmation'), @@ -121,15 +138,10 @@ class EsterdadWizard(models.Model): else: raise UserError(_("No user assigned to this sponsor")) - @api.depends('sponsor_id.donations_details_lines', 'sponsor_id.donations_details_lines_mechanism_ids') + @api.depends('payment_ids') def _get_total_sponsorship_amount(self): - for rec in self: - if rec.sponsor_id: - rec.amount = ( - sum(line.total_donation_amount for line in rec.sponsor_id.donations_details_lines) + - sum(line.total_donation_amount for line in rec.sponsor_id.donations_details_lines_mechanism_ids) - ) + rec.amount = sum(rec.payment_ids.mapped('amount')) class OTPWizard(models.TransientModel): @@ -139,10 +151,12 @@ class OTPWizard(models.TransientModel): otp_code = fields.Integer() esterdad_id = fields.Many2one('esterdad.wizard') user_id = fields.Many2one('res.users') - payment_ids = fields.Many2many( - 'account.payment', - string="Payments" - ) + invoice_ids = fields.Many2many('account.move') + # payment_ids = fields.Many2many( + # 'account.payment', + # string="Payments" + # ) + cancel_reason = fields.Text() def action_confirm_otp(self): for rec in self: @@ -150,21 +164,21 @@ class OTPWizard(models.TransientModel): sponsor_ship = rec.esterdad_id.sponsor_id rec.esterdad_id.cancel_date = date.today() if sponsor_ship: - # Get ref values from selected payments - payment_refs = rec.payment_ids.mapped('ref') - # Filter out empty/False refs - payment_refs = [ref for ref in payment_refs if ref] + # # Get ref values from selected payments + # payment_refs = rec.payment_ids.mapped('ref') + # # Filter out empty/False refs + # payment_refs = [ref for ref in payment_refs if ref] - if not payment_refs: - raise UserError(_("No references found in selected payments")) + # if not payment_refs: + # raise UserError(_("No references found in selected payments")) - # Search for invoices in account.move matching payment refs - invoices = self.env['account.move'].search([ - ('name', 'in', payment_refs), - ]) - if not invoices: + # # Search for invoices in account.move matching payment refs + # invoices = self.env['account.move'].search([ + # ('name', 'in', payment_refs), + # ]) + if not rec.invoice_ids: raise UserError(_("No invoices matching the specified references")) - for invoice in invoices: + for invoice in rec.invoice_ids: credit = self.env['account.move.reversal'].with_company(self.env.user.company_id.id).create({ 'refund_method': 'refund', 'date': date.today(), @@ -181,7 +195,11 @@ class OTPWizard(models.TransientModel): }) credit_note = self.env['account.move'].search([('id', '=', last_id)]) credit_note.action_post() - credit_note.esterdad_id = rec.esterdad_id + credit_note.write({ + 'esterdad_id': rec.esterdad_id.id, + 'sponsorship_cancel_reason': rec.cancel_reason + }) + rec.esterdad_id.confirmed = True rec.esterdad_id.sponsor_id.is_canceled_refund = True diff --git a/odex25_takaful/odex_takaful/wizards/esterdad.xml b/odex25_takaful/odex_takaful/wizards/esterdad.xml index fb0b97d5f..917749770 100644 --- a/odex25_takaful/odex_takaful/wizards/esterdad.xml +++ b/odex25_takaful/odex_takaful/wizards/esterdad.xml @@ -21,6 +21,17 @@
+ +

Invoices

+ + + + + + + + + @@ -33,7 +44,7 @@ - + @@ -45,7 +56,7 @@ - + @@ -55,13 +66,13 @@ readonly="1"/> - -