[ADD] Esterdad task and refund logic

This commit is contained in:
Ali Ammar 2025-12-04 14:32:53 +03:00
commit 6287c459f1
12 changed files with 287 additions and 204 deletions

View File

@ -7567,5 +7567,16 @@ msgstr "حساب الجمعية"
#. module: odex_takaful
#: model_terms:ir.ui.view,arch_db:odex_takaful.donation_extension_wizard_form
msgid "Sub Payments"
msgstr "دفع متعدد"
msgid "Extend"
msgstr "تمديد/دفع"
#. module: odex_takaful
#: model:ir.model.fields,field_description:odex_takaful.field_donation_extension_wizard__total_extension_amount
#: model:ir.model.fields,field_description:odex_takaful.field_donation_extension_wizard_line__total_donation_amount
msgid "Total Extension Amount"
msgstr "إجمالي مبلغ الدفع"
#. module: odex_takaful
#: model:ir.model.fields,field_description:odex_takaful.field_donation_extension_wizard__remaining_amount
msgid "Remaining Amount"
msgstr "المبلغ المتبقى"

View File

@ -1152,6 +1152,7 @@ class DonationsDetailsLines(models.Model):
'target': 'new',
'context': {
'donation_detail_ids': self.ids,
'no_quick_close': True
},
}

View File

@ -135,6 +135,26 @@ class ResPartner(models.Model):
if is_family_or_beneficiary and is_donor_vendor_sponsor:
raise ValidationError(_("A contact cannot be both Family/Beneficiary and Donor/Member/Sponsor at the same time!"))
@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
if not self.env.context.get('from_contact_search'):
return super().search(args, offset=offset, limit=limit, order=order, count=count)
if self.env.context.get('mail_read') or self.env.context.get('mail_message_origin'):
return super().search(args, offset=offset, limit=limit, order=order, count=count)
base_results = super().search(args, offset=offset, limit=limit, order=order)
if not base_results:
return base_results
children = super().search([('parent_id', 'in', base_results.ids)])
final_ids = list(set(base_results.ids + children.ids))
return super().search([('id', 'in', final_ids)], offset=0, limit=limit, order=order, count=count)
@api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
if not args:

View File

@ -0,0 +1,47 @@
odoo.define('odex_takaful.hide_close_button', function (require) {
"use strict";
const Dialog = require('web.Dialog');
const ActionManager = require('web.ActionManager');
Dialog.include({
/**
* @override
*/
open: function () {
var self = this;
this.opened(function () {
setTimeout(function () {
var parent = self.getParent();
if (parent instanceof ActionManager) {
var action = parent.getCurrentActionInDialog();
console.log(action);
if (action) {
if (action.context) {
let model = action.res_model;
if (model === 'donation.extension.wizard' || model === 'account.payment.register') {
if (self.$modal) {
self.$modal.find('.modal-header button.close').hide();
self.$modal.find('.modal-header .modal-title').css("width", "100%");
}
if (self.$el) {
self.$el.find('.o_cp_top_left').hide();
self.$el.find('.o_cp_bottom_left').hide();
self.$el.find('.o_cp_top_right').css("width", "100%");
self.$el.find('.o_cp_bottom_right').css("width", "100%");
}
}
}
}
}
}, 0);
});
return this._super.apply(this, arguments);
},
});
});

View File

@ -8,6 +8,7 @@
<script type="text/javascript" src="/odex_takaful/static/src/js/product_product_views.js"/>
<script type="text/javascript" src="/odex_takaful/static/src/js/donation_catalog_button.js"/>
<script type="text/javascript" src="/odex_takaful/static/src/js/donation_catalog_controls.js"/>
<script type="text/javascript" src="/odex_takaful/static/src/js/hide_close_button.js"/>
<!-- <script type="text/javascript" src="/odex_takaful/static/src/js/catalog_kanban_dynamic_button.js"/>-->
</xpath>
</template>

View File

@ -70,15 +70,15 @@
<field name="sponsor_id" />
<field name="sponsor_phone" widget="phone"/>
<field name="donation_type" optional="show"/>
<field name="donation_type" optional="hide"/>
<field name="sponsorship_duration" optional="hide"/>
<field name="donation_mechanism" optional="hide"/>
<field name="product_template_id" />
<field name="benefit_status" widget="badge"
decoration-success="benefit_status == 'benefit'"
decoration-danger="benefit_status == 'non_benefit'"/>
<field name="start_date" widget="date"/>
<field name="end_date" widget="date"/>
decoration-danger="benefit_status == 'non_benefit'" 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'}"/>
<field name="total_donation_amount" widget="monetary" options="{'currency_field': 'currency_id'}"/>
<field name="currency_id" invisible="1"/>
@ -94,7 +94,7 @@
decoration-success="state in ['active', 'paid','confirmed']"
decoration-danger="state == 'closed'"
decoration-info="state == 'extended'" />
<field name="age_category" widget="state" />
<field name="age_category" widget="state" optional="hide"/>
<button name="action_view_scheduling_lines"
string="View Scheduling Lines"
type="object"
@ -368,15 +368,15 @@
<field name="sequence_no" />
<field name="sponsor_id" />
<field name="sponsor_phone" widget="phone"/>
<field name="donation_type" optional="show"/>
<field name="donation_type" optional="hide"/>
<field name="sponsorship_duration" optional="hide"/>
<field name="donation_mechanism" optional="hide"/>
<field name="product_template_id" />
<field name="benefit_status" widget="badge"
decoration-success="benefit_status == 'benefit'"
decoration-danger="benefit_status == 'non_benefit'"/>
<field name="start_date" widget="date"/>
<field name="end_date" widget="date"/>
<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'}"/>
<field name="total_donation_amount" widget="monetary" options="{'currency_field': 'currency_id'}"/>
<field name="currency_id" invisible="1"/>

View File

@ -13,7 +13,7 @@
<field name="acc_holder_name"/>
</group>
<group>
<field name="bank_id"/>
<field name="bank_id" required="1"/>
<field name="partner_id" readonly="1"/>
</group>
</group>

View File

@ -187,10 +187,10 @@
</notebook>
</sheet>
<footer>
<button name="action_save_and_close" string="حفظ وإغلاق" type="object" class="btn-primary"/>
<button string="تجاهل" class="btn-secondary" special="cancel"/>
</footer>
<!-- <footer>-->
<!-- <button name="action_save_and_close" string="حفظ وإغلاق" type="object" class="btn-primary"/>-->
<!-- <button string="تجاهل" class="btn-secondary" special="cancel"/>-->
<!-- </footer>-->
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
@ -210,7 +210,8 @@
'default_company_type': 'person',
'default_is_sponsor_portal': True,
'default_is_donor': True,
'sponsor_contact': True
'sponsor_contact': True,
'from_contact_search': True
}
</field>
</record>
@ -249,6 +250,20 @@
</field>
</record>
<!-- <record id="res_partner_phone_filter" model="ir.ui.view">-->
<!-- <field name="name">res.partner.phone.filter</field>-->
<!-- <field name="model">res.partner</field>-->
<!-- <field name="inherit_id" ref="base.view_res_partner_filter"/>-->
<!-- <field name="arch" type="xml">-->
<!-- <xpath expr="//search" position="attributes">-->
<!-- <attribute name="context">{'from_contact_search': True}</attribute>-->
<!-- </xpath>-->
<!-- </field>-->
<!-- </record>-->
<!-- Unarchive Sponsor -->
<record id="activate_sponsor_multi" model="ir.actions.server">
<field name="name">Make Active</field>

View File

@ -34,6 +34,15 @@ class AccountRegisterPayment(models.TransientModel):
check_number = fields.Char(string='Check Number')
check_due_date = fields.Date(string='Check Due Date')
sponsorship_payment = fields.Boolean(string='Sponsorship Payment', default=False)
show_cancel_button = fields.Boolean(
string="Show Cancel Button",
compute="_compute_show_cancel_button"
)
@api.depends_context('wiz_id')
def _compute_show_cancel_button(self):
for rec in self:
rec.show_cancel_button = not bool(self.env.context.get('wiz_id'))
@api.onchange("machine_id")
@ -197,7 +206,23 @@ class AccountRegisterPayment(models.TransientModel):
def action_create_payments(self):
res = super(AccountRegisterPayment, self).action_create_payments()
if self.env.context.get('dont_redirect_to_payments'):
if self.env.context.get('dont_redirect_to_payments') and self.env.context.get('wiz_id'):
if self.amount < self.env.context.get('default_amount'):
wiz = self.env['donation.extension.wizard'].browse(self.env.context.get('wiz_id'))
wiz.paid_amount += self.amount
wiz.is_different_payment = True
return {
'type': 'ir.actions.act_window',
'name': _('Extend Donation'),
'res_model': 'donation.extension.wizard',
'view_mode': 'form',
'target': 'new',
'res_id': self.env.context.get('wiz_id'),
'context': {
'paid_amount': self.amount,
'no_quick_close': True,
},
}
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
@ -211,3 +236,24 @@ class AccountRegisterPayment(models.TransientModel):
}
return res
def action_cancel(self):
wiz_id = self.env.context.get('wiz_id')
if wiz_id:
return {
'type': 'ir.actions.act_window',
'name': _('Extend Donation'),
'res_model': 'donation.extension.wizard',
'view_mode': 'form',
'target': 'new',
'res_id': wiz_id,
'context': {
'paid_amount': self.amount or 0.0,
'no_quick_close': True,
},
}
return {'type': 'ir.actions.act_window_close'}

View File

@ -45,12 +45,24 @@
<field name="payment_method" invisible="1"/>
<field name="check_number" attrs="{'invisible': ['|', ('sponsorship_payment', '=', False), ('takaful_payment_method','!=','check')], 'required': [('sponsorship_payment', '=', True), ('takaful_payment_method','=','check')]}"/>
<field name="check_due_date" attrs="{'invisible': ['|', ('sponsorship_payment', '=', False), ('takaful_payment_method','!=','check')], 'required': [('sponsorship_payment', '=', True), ('takaful_payment_method','=','check')]}"/>
<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': [('sponsorship_payment', '=', True), ('takaful_payment_method','=','bank')], 'invisible': ['|', ('sponsorship_payment', '=', False), ('takaful_payment_method','!=','bank')]}"/>
<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': [('sponsorship_payment', '=', True), ('takaful_payment_method','=','bank')], 'invisible': ['|', ('sponsorship_payment', '=', False), ('takaful_payment_method','!=','bank')]}" create="1" edit="1"/>
<field name="transaction_file_attachment" widget="binary"
filename="transaction_attachment_file_name"
attrs="{'invisible': ['|', ('sponsorship_payment', '=', False), ('takaful_payment_method','not in',['bank', 'check'])], 'required': [('sponsorship_payment', '=', True), ('takaful_payment_method','=','bank')]}"/>
<field name="transaction_attachment_file_name" invisible="1"/>
</xpath>
<xpath expr="//footer/button[2]" position="after">
<field name="show_cancel_button" invisible="1"/>
<button name="action_cancel"
type="object"
string="Cancel"
class="btn-secondary"
attrs="{'invisible': [('show_cancel_button', '=', True)]}"/>
</xpath>
<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)]}">-->

View File

@ -39,7 +39,11 @@ class DonationExtensionWizard(models.TransientModel):
compute='_compute_total_extension_amount',
store=True,
)
paid_amount = fields.Float(string="Paid Amount", readonly=True)
remaining_amount = fields.Float(string="Remaining Amount", compute='_compute_total_remaining_amount',
store=True,)
currency_id = fields.Many2one('res.currency', string='Currency',
default=lambda self: self.env.company.currency_id, readonly=True)
@api.depends('line_ids.total_donation_amount')
@ -47,14 +51,19 @@ class DonationExtensionWizard(models.TransientModel):
for rec in self:
rec.total_extension_amount = sum(line.total_donation_amount for line in rec.line_ids if line.direct_debit == False)
@api.constrains('is_different_payment', 'payment_line_ids')
def _check_payment_sum_when_different(self):
@api.depends('total_extension_amount','paid_amount')
def _compute_total_remaining_amount(self):
for rec in self:
if not rec.is_different_payment:
sum_payments = sum(line.payment_amount for line in rec.payment_line_ids)
if float_compare(sum_payments, rec.total_extension_amount, precision_digits=2) != 0:
raise ValidationError(_("Total payment amounts (%s) must equal total extension amount (%s).") %
(sum_payments, rec.total_extension_amount))
rec.remaining_amount = rec.total_extension_amount - rec.paid_amount
# @api.constrains('is_different_payment', 'payment_line_ids')
# def _check_payment_sum_when_different(self):
# for rec in self:
# if not rec.is_different_payment:
# sum_payments = sum(line.payment_amount for line in rec.payment_line_ids)
# if float_compare(sum_payments, rec.total_extension_amount, precision_digits=2) != 0:
# raise ValidationError(_("Total payment amounts (%s) must equal total extension amount (%s).") %
# (sum_payments, rec.total_extension_amount))
def _compute_line_ids(self):
extension_line_ids = [(5,)]
@ -97,76 +106,35 @@ class DonationExtensionWizard(models.TransientModel):
"""
invoice_ids = self.env['account.move']
donation_line_ids = self.env['donations.details.lines']
amount = self.total_extension_amount - self.paid_amount
for line in self.line_ids:
result = line._extend()
if result:
invoice_ids += result[0]
donation_line_ids += result[1]
if invoice_ids and not self.is_different_payment:
invoices = invoice_ids.filtered(
lambda inv: inv.state == 'posted' and inv.move_type in ('out_invoice', 'out_refund'))
if not invoices:
return
residual_map = {inv.id: float(inv.amount_residual) for inv in invoices}
invoices = invoices.sorted(key=lambda r: r.invoice_date or r.date or fields.Date.context_today(self))
for pay_line in self.payment_line_ids:
remaining = float(pay_line.payment_amount or 0.0)
if float_compare(remaining, 0.0, precision_digits=2) <= 0:
continue
candidate_invoices = invoices.filtered(lambda inv: inv.partner_id == pay_line.partner_id)
if not candidate_invoices:
candidate_invoices = invoices
for inv in candidate_invoices:
if float_compare(remaining, 0.0, precision_digits=2) <= 0:
break
inv_res = residual_map.get(inv.id, 0.0)
if float_compare(inv_res, 0.0, precision_digits=2) <= 0:
continue
pay_amount = min(remaining, inv_res)
payment_register_vals = {
'payment_type': 'inbound',
'partner_type': 'customer',
'partner_id': inv.partner_id.id,
'amount': pay_amount,
'journal_id': pay_line.journal_id.id,
# 'payment_method_id': pay_line.payment_method.id,
'communication': _("Extension Payment for %s") % inv.name,
'transaction_file_attachment': pay_line.payment_file_attachment,
}
ctx = {
if invoice_ids:
return {
'name': _('Register Payment'),
'res_model': 'account.payment.register',
'view_mode': 'form',
'context': {
'active_model': 'account.move',
'active_ids': [inv.id],
'active_ids': invoice_ids.ids,
'default_amount': amount,
'sponsorship_payment_skip_compute_amount': True,
'dont_redirect_to_payments': True,
'sponsorship_line_ids': donation_line_ids.ids,
'sponsorship_line_ids': self.line_ids.donation_line_id.ids,
'sponsorship_payment': True,
'default_sponsorship_payment': True,
'wiz_id': self.id
# 'force_sponsorship_line_partner_id': self.donation_detail_id.sponsor_id.id,
},
'target': 'new',
'type': 'ir.actions.act_window',
}
payment_register = self.env['account.payment.register'].sudo().with_context(ctx).new(
payment_register_vals)
payments = payment_register.action_create_payments()
inv_sudo = inv.sudo()
inv_sudo.invalidate_cache(['amount_residual'])
new_residual = float(inv_sudo.amount_residual or 0.0)
residual_map[inv.id] = new_residual
remaining = remaining - pay_amount
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
@ -295,6 +263,12 @@ class DonationExtensionWizardLine(models.TransientModel):
compute='_compute_new_end_date',
readonly=True
)
extension_invoice_id = fields.Many2one(
'account.move',
string="Extension Invoice",
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)
@ -345,7 +319,7 @@ class DonationExtensionWizardLine(models.TransientModel):
if not self.donation_line_id:
raise ValidationError(_("No donation detail line selected."))
if not self.extension_invoice_id:
# Update the donation detail line
new_end_date = self.current_end_date + relativedelta(months=self.months)
old_end_date = self.current_end_date
@ -377,6 +351,7 @@ class DonationExtensionWizardLine(models.TransientModel):
# Create invoice for the extension
invoice_id = self._create_extension_invoice()
self.extension_invoice_id = invoice_id
# Create extension history record
self.env['donation.extension.history'].create({
@ -393,7 +368,7 @@ class DonationExtensionWizardLine(models.TransientModel):
})
if not self.direct_debit:
return invoice_id, self.donation_line_id
return self.extension_invoice_id, self.donation_line_id
return False
@ -455,6 +430,7 @@ class DonationExtensionWizardLine(models.TransientModel):
'journal_id': int(kafala_journal_id),
'date': fields.Date.today(),
'partner_id': sponsorship.sponsor_id.id,
'invoice_origin': sponsorship.code,
'invoice_line_ids': [(0, 0, {
'product_id': donation_line.product_id.id,
'price_unit': self.total_donation_amount,

View File

@ -5,11 +5,14 @@
<field name="name">donation.extension.wizard.form</field>
<field name="model">donation.extension.wizard</field>
<field name="arch" type="xml">
<form>
<form class="o_form_noclose">
<sheet>
<group>
<group string="Extension Details">
<field name="months"/>
<field name="months" attrs="{'readonly': [('is_different_payment', '=', True)]}"/>
<field name="is_different_payment" invisible="1"/>
</group>
</group>
<notebook>
@ -24,7 +27,7 @@
<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="donation_line_id" force_save="1"/>
<field name="donation_line_id" force_save="1" optional="hide"/>
<field name="current_end_date" widget="date" force_save="1"/>
<field name="new_end_date" widget="date" force_save="1"/>
<field name="direct_debit" force_save="1"/>
@ -36,7 +39,7 @@
<field name="total_months_amount" string="Months Amount" widget="monetary"
options="{'currency_field': 'currency_id'}" force_save="1"/>
<field name="total_donation_amount" string="Total Amount" widget="monetary"
options="{'currency_field': 'currency_id'}" force_save="1"/>
options="{'currency_field': 'currency_id'}" force_save="1" sum="Total Amount"/>
</tree>
<form>
<field name="wizard_id" invisible="1" force_save="1"/>
@ -57,7 +60,7 @@
<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)]}"/>
attrs="{'invisible': [('direct_debit', '=', False)], 'required': [('direct_debit', '=', True)]}" create="1" edit="1"/>
<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"
@ -76,75 +79,26 @@
</group>
</form>
</field>
</page>
<page string="Sub Payments" >
<field name="payment_line_ids" nolabel="1">
<tree editable="bottom" delete="true" create="true">
<field name="payment_method" options="{'no_create': True, 'no_create_edit': True}"/>
<group>
<group>
<field name="currency_id" invisible="1"/>
<field name="donation_line_ids" invisible="1"/>
<field name="payment_method_type" invisible="1"/>
<field name="partner_id" invisible="1"/>
<field name="journal_id" string="Association Journal"/>
<field name="payment_amount" widget="monetary"
options="{'currency_field': 'currency_id'}" force_save="1" sum="Total Amount"/>
<field name="check_number"
attrs="{
'invisible': [
('payment_method_type','!=','check')
],
'required': [
('payment_method_type','=','check')
]
}"
optional="hide"/>
<field name="check_due_date"
attrs="{
'invisible': [
('payment_method_type','!=','check')
],
'required': [
('payment_method_type','=','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': [
('payment_method_type','=','bank')
],
'invisible': [
('payment_method_type','!=','bank')
]
}"
readonly="0"
optional="hide"/>
<field name="payment_file_attachment"
widget="binary"
filename="payment_file_attachment_name"
attrs="{
'invisible': [
('payment_method_type','not in',['bank', 'check'])
],
'required': ['|',
('payment_method_type','=','bank'),
('payment_method_type','=','check')
]
}"
optional="hide"/>
</tree>
</field>
<field name="total_extension_amount" widget="monetary"
options="{'currency_field': 'currency_id'}"
class="oe_inline"/>
<field name="remaining_amount" widget="monetary"
options="{'currency_field': 'currency_id'}"
attrs="{'invisible': [('is_different_payment', '=', False)]}"
class="oe_inline"/>
</group>
</group>
</page>
</notebook>
</sheet>
<footer>
<button name="action_extend" type="object" string="Extend" class="oe_highlight"/>
or
<button name="action_cancel" type="object" string="Cancel" special="cancel"/>
<button name="action_cancel" type="object" string="Cancel" special="cancel" attrs="{'invisible': [('is_different_payment', '=', True)]}"/>
</footer>
</form>
</field>