FIX Donation Line state
This commit is contained in:
parent
0ced8d2a5a
commit
c765a98666
|
|
@ -61,6 +61,7 @@
|
|||
'wizards/add_details_wizard.xml',
|
||||
'wizards/donation_extension_wizard.xml',
|
||||
'wizards/replace_sponsor_wizard.xml',
|
||||
'wizards/add_benefit_wizard.xml',
|
||||
'views/donations_details_lines.xml',
|
||||
'views/donation_extension_history_views.xml',
|
||||
'views/donation_replacement_log_views.xml',
|
||||
|
|
|
|||
|
|
@ -840,6 +840,7 @@ msgid "Beneficiary Filters"
|
|||
msgstr " حقول التصفية"
|
||||
|
||||
#. module: odex_takaful
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_add_benefit_wizard__benefit_id
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_donations_details_lines__benefit_id
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_takaful_sponsorship__benefit_id
|
||||
msgid "Beneficiary Name"
|
||||
|
|
@ -1105,6 +1106,7 @@ msgstr "هل يمكن جعل الكافل نشطًا مرة أخرى؟"
|
|||
|
||||
#. module: odex_takaful
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__month_payment__state__cancel
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.add_benefit_wizard_form
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.add_details_wizard_form
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.benefit_month_payment_form
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.donation_extension_wizard_form
|
||||
|
|
@ -1296,14 +1298,19 @@ msgid "Close To Cancel Date"
|
|||
msgstr ""
|
||||
|
||||
#. module: odex_takaful
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__donations_details_lines__state__closed
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__sponsorship_states__name__closed
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__takaful_sponsorship__state__closed
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.donations_details_lines_view_search
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.takaful_sponsorship_view_search
|
||||
msgid "Closed"
|
||||
msgstr "مغلق"
|
||||
|
||||
#. module: odex_takaful
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__donations_details_lines__state__closed
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.donations_details_lines_view_search
|
||||
|
||||
msgid "Closed"
|
||||
msgstr "ملغي"
|
||||
|
||||
#. module: odex_takaful
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_month_payment__code
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_month_payment_line__code
|
||||
|
|
@ -1879,6 +1886,7 @@ msgid "Donate For Another Person"
|
|||
msgstr "التبرع لشخص آخر"
|
||||
|
||||
#. module: odex_takaful
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__donation_replacement_log__record_type__donation
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__donations_details_lines__donation_type__donation
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__donations_details_lines__donation_types__donation
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__donations_details_lines__record_type__donation
|
||||
|
|
@ -1921,6 +1929,7 @@ msgid "Donation Date"
|
|||
msgstr "تاريخ التبرع"
|
||||
|
||||
#. module: odex_takaful
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_donation_replacement_log__donation_detail_id
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_donation_extension_history__donation_detail_id
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_donation_extension_wizard__donation_detail_id
|
||||
msgid "Donation Detail"
|
||||
|
|
@ -4835,6 +4844,7 @@ msgstr "استلام الأموال"
|
|||
|
||||
#. module: odex_takaful
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_donations_details_lines__record_type
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_donation_replacement_log__record_type
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_replacement_process__record_type
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_takaful_sponsorship__record_type
|
||||
msgid "Record Type"
|
||||
|
|
@ -5092,6 +5102,7 @@ msgid "Replacement Processes"
|
|||
msgstr "عمليات الإستبدال"
|
||||
|
||||
#. module: odex_takaful
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_donation_replacement_log__replacement_reason_id
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_replacement_process__replacement_reason_id
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_replacement_wiz__replacement_reason_id
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.view_replacement_wiz_form
|
||||
|
|
@ -5630,6 +5641,7 @@ msgstr "سجل الكفلاء"
|
|||
#: model:ir.model.fields,field_description:odex_takaful.field_refund_details_lines__sponsorship_id
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_refund_wiz__sponsorship_id
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_replacement_process__sponsorship_id
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__donation_replacement_log__record_type__sponsorship
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_sponsorship_benefit_arrears__sponsorship_id
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_sponsorship_cancellation__sponsorship_id
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_sponsorship_payment__sponsorship_id
|
||||
|
|
@ -5642,6 +5654,7 @@ msgstr "سجل الكفلاء"
|
|||
#: model:ir.model.fields.selection,name:odex_takaful.selection__replacement_process__record_type__sponsorship
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__takaful_sponsor_operation__operation_type__sponsorship
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__takaful_sponsorship__record_type__sponsorship
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__donation_replacement_log__record_type__sponsorship
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.donations_details_lines_view_search
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.kafalat_cancel_report_pdf
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.kafalat_payment_report_pdf
|
||||
|
|
@ -7134,6 +7147,7 @@ msgid "هدية مالية"
|
|||
msgstr ""
|
||||
|
||||
#. module: odex_takaful
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_donation_replacement_log__sponsor_id
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__replacement_process__registered_type__sponsor
|
||||
#: model:ir.model.fields.selection,name:odex_takaful.selection__takaful_sponsorship__registered_type__sponsor
|
||||
#, python-format
|
||||
|
|
@ -7341,7 +7355,8 @@ msgstr "المستفيد القديم"
|
|||
#: model:ir.model.fields,field_description:odex_takaful.field_replacement_wiz__old_family_id
|
||||
msgid "Old Family"
|
||||
msgstr "المستفيد القديم عائلة"
|
||||
#. module: odex_takaful
|
||||
|
||||
#. module: odex_takaful
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_donation_replacement_log__replacement_ref
|
||||
msgid "replacement Reference"
|
||||
msgstr "المرجع"
|
||||
|
|
@ -7400,10 +7415,34 @@ msgstr "يمكنك الارسال الى مسودة للتبرعات المؤك
|
|||
msgid "Payment registered successfully"
|
||||
msgstr "تمت عملية الدفع بنجاح"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#. module: odex_takaful
|
||||
#: code:addons/odex_takaful/models/donation_details_lines.py:0
|
||||
#: code:addons/odex_takaful/wizards/add_benefit_wizard.py:0
|
||||
#: model:ir.model,name:odex_takaful.model_add_benefit_wizard
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.add_benefit_wizard_form
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.donations_details_lines_view_form
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.takaful_sponsorship_form
|
||||
#, python-format
|
||||
msgid "Add Benefit"
|
||||
msgstr "إضافة مستفيد"
|
||||
|
||||
#. module: odex_takaful
|
||||
#: model_terms:ir.ui.view,arch_db:odex_takaful.add_benefit_wizard_form
|
||||
msgid "Benefit Information"
|
||||
msgstr "تفاصيل إضافة المستفيد"
|
||||
|
||||
#. module: odex_takaful
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_donation_replacement_log__user_id
|
||||
msgid "Replaced By"
|
||||
msgstr "تم الإستبدال بواسطة"
|
||||
|
||||
#. module: odex_takaful
|
||||
#: code:addons/odex_takaful/models/donation_details_lines.py:0
|
||||
#: model:ir.actions.act_window,name:odex_takaful.action__replacement_log_history
|
||||
#: model:ir.model.fields,field_description:odex_takaful.field_donations_details_lines__replacement_log_ids
|
||||
#, python-format
|
||||
msgid "Replacement Log"
|
||||
msgstr "سجل الإستبدال"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class DonationsDetailsLines(models.Model):
|
|||
sponsor_phone = fields.Char(related='sponsor_id.mobile')
|
||||
branch_custom_id = fields.Many2one('branch.settings', compute='_compute_branch_custom_id')
|
||||
record_type = fields.Selection([('sponsorship', 'Sponsorship'),('donation', 'Donation')], compute='_compute_record_type', store=True, readonly=True)
|
||||
state = fields.Selection([('draft', 'To Pay'),('waiting', 'Waiting'), ('active', 'Active'),('closed', 'Closed'),('extended', 'Extended'),('replace', 'To Replace'), ('paid', 'Paid')], string='State', default='draft')
|
||||
state = fields.Selection([('draft', 'Draft'),('confirmed', 'Confirmed'),('waiting', 'Waiting'), ('active', 'Active'),('closed', 'Closed'),('extended', 'Extended'),('replace', 'To Replace'), ('paid', 'Paid')], string='State', default='draft')
|
||||
sponsorship_scheduling_line_ids = fields.One2many('sponsorship.scheduling.line', 'donation_detail_linked_id')
|
||||
extension_history_ids = fields.One2many('donation.extension.history', 'donation_detail_id',
|
||||
string='Extension History')
|
||||
|
|
@ -88,6 +88,7 @@ class DonationsDetailsLines(models.Model):
|
|||
|
||||
show_extend_button = fields.Boolean(string='Show Extend Button', compute='_compute_show_extend_button')
|
||||
show_replaced_button = fields.Boolean(string='Show Replaced Button', compute='_compute_show_replaced_button')
|
||||
show_add_benefit_button = fields.Boolean(string='Show Add Benefit Button', compute='_compute_show_add_benefit_button')
|
||||
is_paid = fields.Boolean(string="Is Paid", default=False)
|
||||
parent_state = fields.Char(compute='_compute_parent_state')
|
||||
hide_beneficiary_group = fields.Boolean(compute='_compute_hide_beneficiary_group')
|
||||
|
|
@ -141,10 +142,21 @@ class DonationsDetailsLines(models.Model):
|
|||
for rec in self:
|
||||
show_replaced_button = (
|
||||
((rec.record_type == 'donation' and rec.donation_mechanism == 'with_conditions') or rec.record_type == 'sponsorship') and
|
||||
rec.state in ('active', 'paid','replace')
|
||||
rec.state in ('active', 'paid','replace') and
|
||||
(rec.benefit_id or rec.benefit_ids or rec.family_id)
|
||||
|
||||
)
|
||||
rec.show_replaced_button = show_replaced_button
|
||||
|
||||
@api.depends('record_type', 'state')
|
||||
def _compute_show_add_benefit_button(self):
|
||||
for rec in self:
|
||||
show_add_benefit_button = (
|
||||
rec.record_type == 'sponsorship' and
|
||||
rec.state == 'waiting'
|
||||
)
|
||||
rec.show_add_benefit_button = show_add_benefit_button
|
||||
|
||||
@api.depends('sponsorship_duration', 'direct_debit', 'record_type', 'start_date')
|
||||
def _compute_hide_beneficiary_group(self):
|
||||
for rec in self:
|
||||
|
|
@ -208,7 +220,7 @@ class DonationsDetailsLines(models.Model):
|
|||
def _onchange_benefit_id(self):
|
||||
for rec in self:
|
||||
if rec.benefit_id:
|
||||
if rec.benefit_status and rec.benefit_status == 'non_benefit':
|
||||
if rec.benefit_status and rec.benefit_status == 'non_benefit' and rec.sponsorship_id.record_type == 'sponsorship':
|
||||
rec.state = 'replace'
|
||||
@api.onchange('product_template_id')
|
||||
def _onchange_product_template_id(self):
|
||||
|
|
@ -801,7 +813,7 @@ class DonationsDetailsLines(models.Model):
|
|||
if 'benefit_id' in vals:
|
||||
new_benefit = rec.benefit_id.name or 'None'
|
||||
sponsorship = self.env['takaful.sponsorship'].browse(
|
||||
self.env.context.get('active_id'))
|
||||
self.env.context.get(rec.sponsorship_id))
|
||||
if sponsorship and len(sponsorship) == 1:
|
||||
message = _("Benefit changed from <b>%s</b> to <b>%s</b> in a donation item.") % (
|
||||
old_benefit or 'None', new_benefit)
|
||||
|
|
@ -825,14 +837,14 @@ class DonationsDetailsLines(models.Model):
|
|||
if changes:
|
||||
# Find sponsorship
|
||||
sponsorship = rec.sponsorship_id or self.env['takaful.sponsorship'].browse(
|
||||
self.env.context.get('active_id'))
|
||||
self.env.context.get(rec.sponsorship_id))
|
||||
|
||||
if sponsorship and len(sponsorship) == 1:
|
||||
message = _("Benefit IDs changed in a donation item:<br/>%s") % "<br/>".join(changes)
|
||||
sponsorship.message_post(body=message)
|
||||
self.onset_benefit_id()
|
||||
if self.benefit_id:
|
||||
if self.benefit_status and self.benefit_status == 'non_benefit':
|
||||
if self.benefit_status and self.benefit_status == 'non_benefit' and self.sponsorship_id.record_type == 'sponsorship':
|
||||
self.state = 'replace'
|
||||
return res
|
||||
|
||||
|
|
@ -1046,4 +1058,18 @@ class DonationsDetailsLines(models.Model):
|
|||
'context': {
|
||||
'default_donation_detail_id': self.id,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def add_benefit_wizard(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Add Benefit'),
|
||||
'res_model': 'add.benefit.wizard',
|
||||
'view_mode': 'form',
|
||||
'target': 'new',
|
||||
'context': {
|
||||
'default_donation_detail_id': self.id,
|
||||
},
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ class DonationReplacementLog(models.Model):
|
|||
|
||||
user_id = fields.Many2one(
|
||||
'res.users',
|
||||
string='Extended By',
|
||||
string='Replaced By',
|
||||
default=lambda self: self.env.user,
|
||||
readonly=True
|
||||
)
|
||||
|
|
|
|||
|
|
@ -83,6 +83,6 @@ class FamilyMember(models.Model):
|
|||
sponsorships = sponsorships_main | sponsorships_multi
|
||||
|
||||
if sponsorships:
|
||||
if member.member_status and member.member_status == 'non_benefit':
|
||||
if member.member_status and member.member_status == 'non_benefit' and sponsorships.sponsorship_id.record_type == 'sponsorship':
|
||||
sponsorships.write({'state': 'replace'})
|
||||
return res
|
||||
|
|
|
|||
|
|
@ -143,6 +143,13 @@ class SchedulingLine(models.Model):
|
|||
|
||||
payment_register.action_create_payments()
|
||||
line.sudo().write({'status': 'paid'})
|
||||
if line.donation_detail_linked_id.state == 'waiting' or (not line.donation_detail_linked_id.benefit_id and line.donation_detail_linked_id.record_type == 'sponsorship'):
|
||||
line.donation_detail_linked_id.sudo().write({'state': 'waiting'})
|
||||
else:
|
||||
line.donation_detail_linked_id.sudo().write({'state': 'active'})
|
||||
line.donation_detail_linked_id.sponsorship_id.sudo().write({'state': 'wait_pay'})
|
||||
|
||||
|
||||
_logger.info(f"Successfully processed scheduled payment for line {line.sequence_no}")
|
||||
else:
|
||||
_logger.warning(f"Scheduling line {line.sequence_no} payment method is not direct debit, skipping auto-payment")
|
||||
|
|
|
|||
|
|
@ -1241,6 +1241,8 @@ class TakafulSponsorship(models.Model):
|
|||
push.sudo().send_sms_notification()
|
||||
|
||||
self.state = "confirmed"
|
||||
for line_state in all_donation_lines:
|
||||
line_state.state = 'confirmed'
|
||||
faal_kheer_partner_id = self.env.company.faal_kheer_partner_id
|
||||
# if self.sponsor_or_donor_type != 'registered':
|
||||
# return
|
||||
|
|
@ -1703,6 +1705,11 @@ class TakafulSponsorship(models.Model):
|
|||
move_ids = rec.journal_entry_ids.filtered(lambda l: l.move_type == 'out_invoice')
|
||||
move_ids.button_draft()
|
||||
self.write({'state': 'draft'})
|
||||
all_donation_lines = (self.donations_details_lines + self.donations_details_lines_mechanism_ids).filtered(
|
||||
lambda r: r.display_type == False)
|
||||
for line in all_donation_lines:
|
||||
line.state = 'draft'
|
||||
|
||||
|
||||
class AnotherSponsors(models.Model):
|
||||
_name = "donate.for.another.person"
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ access_donation_extension_history,donation.extension.history.access,model_donati
|
|||
access_donation_extension_wizard_line,donation.extension.wizard.line.access,model_donation_extension_wizard_line,odex_takaful.group_kufula_user,1,1,1,0
|
||||
access_donation_replacement_log,donation.replacement.log.access,model_donation_replacement_log,odex_takaful.group_kufula_user,1,1,1,0
|
||||
access_replace_sponsor_wizard,replace.sponsor.wizard.access,model_replace_sponsor_wizard,odex_takaful.group_replace_sponsor,1,1,1,1
|
||||
|
||||
access_add_benefit_wizard,add.benefit.wizard.access,model_add_benefit_wizard,odex_takaful.group_kufula_user,1,1,1,1
|
||||
|
||||
access_group_kufula_user_product_template,access_group_kufula_user_product_template,product.model_product_template,odex_takaful.group_kufula_user,1,1,0,0
|
||||
access_group_kufula_user_account_move,access_group_kufula_user_account_move,account.model_account_move,odex_takaful.group_kufula_user,1,1,1,0
|
||||
|
|
|
|||
|
|
|
@ -61,7 +61,7 @@
|
|||
<field name="name">donations.details.lines.view.tree</field>
|
||||
<field name="model">donations.details.lines</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree default_order="create_date asc">
|
||||
<tree default_order="create_date asc" create="0" edit="0">
|
||||
<field name="sponsorship_scheduling_line_ids" invisible="1" />
|
||||
<field name="direct_debit" invisible="1" />
|
||||
<field name="sequence_no" />
|
||||
|
|
@ -86,7 +86,7 @@
|
|||
<field name="state" widget="badge"
|
||||
decoration-muted="state == 'draft'"
|
||||
decoration-warning="state == 'waiting'"
|
||||
decoration-success="state in ['active', 'paid']"
|
||||
decoration-success="state in ['active', 'paid','confirmed']"
|
||||
decoration-danger="state == 'closed'"
|
||||
decoration-info="state == 'extended'" />
|
||||
|
||||
|
|
@ -104,7 +104,7 @@
|
|||
<field name="name">donations.details.lines.view.form</field>
|
||||
<field name="model">donations.details.lines</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Donation Details">
|
||||
<form string="Donation Details" create="0" edit="0" >
|
||||
<header>
|
||||
<!-- <button name="action_register_payment"
|
||||
string="Register Payment"
|
||||
|
|
@ -122,12 +122,15 @@
|
|||
class="btn-primary"
|
||||
icon="fa-plus-circle"
|
||||
attrs="{'invisible': [('show_extend_button', '=', False)]}" />
|
||||
|
||||
<button string="Orphan Replacement"
|
||||
name="action_view_replacement_wizard"
|
||||
type="object"
|
||||
class="btn-primary"
|
||||
icon="fa-exchange"
|
||||
attrs="{'invisible': [('show_replaced_button', '=', False)]}"
|
||||
groups="odex_takaful.group_orphan_replacement" />
|
||||
|
||||
<button string="Replace Sponsor"
|
||||
name="replace_sponsor_wizard"
|
||||
type="object"
|
||||
|
|
@ -135,8 +138,17 @@
|
|||
icon="fa-exchange"
|
||||
attrs="{'invisible': [('sponsor_id', '=', False)]}"
|
||||
groups="odex_takaful.group_replace_sponsor" />
|
||||
|
||||
<button string="Add Benefit"
|
||||
name="add_benefit_wizard"
|
||||
type="object"
|
||||
class="btn-primary"
|
||||
icon="fa-plus-circle"
|
||||
attrs="{'invisible': [('show_add_benefit_button', '=', False)]}"
|
||||
groups="odex_takaful.group_kufula_user" />
|
||||
|
||||
<field name="state" widget="statusbar"
|
||||
statusbar_visible="draft,waiting,active,replace,closed,extended" />
|
||||
statusbar_visible="draft,confirmed,waiting,active,replace,closed" />
|
||||
</header>
|
||||
<sheet>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
|
|
@ -186,6 +198,7 @@
|
|||
<field name="is_paid" invisible="1" />
|
||||
<field name="show_extend_button" invisible="1" />
|
||||
<field name="show_replaced_button" invisible="1" />
|
||||
<field name="show_add_benefit_button" invisible="1" />
|
||||
</group>
|
||||
</group>
|
||||
|
||||
|
|
|
|||
|
|
@ -287,6 +287,7 @@
|
|||
<field name="sponsorship_scheduling_line_ids" invisible="1"/>
|
||||
<field name="show_extend_button" invisible="1"/>
|
||||
<field name="show_replaced_button" invisible="1"/>
|
||||
<field name="show_add_benefit_button" invisible="1"/>
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="display_type" invisible="1"/>
|
||||
<field name="state" invisible="1"/>
|
||||
|
|
@ -365,10 +366,18 @@
|
|||
icon="fa-plus-circle"
|
||||
attrs="{'invisible': [('show_extend_button', '=', False)]}"/>
|
||||
|
||||
<button string="Add Benefit"
|
||||
name="add_benefit_wizard"
|
||||
type="object"
|
||||
class="btn-primary"
|
||||
icon="fa-plus-circle"
|
||||
attrs="{'invisible': [('show_add_benefit_button', '=', False)]}"
|
||||
groups="odex_takaful.group_kufula_user" />
|
||||
<button name="action_view_replacement_wizard"
|
||||
string="Orphan Replacement"
|
||||
type="object"
|
||||
class="btn-primary"
|
||||
icon="fa-exchange"
|
||||
attrs="{'invisible': [('show_replaced_button', '=', False)]}"
|
||||
groups="odex_takaful.group_orphan_replacement"/>
|
||||
|
||||
|
|
@ -381,10 +390,18 @@
|
|||
</tree>
|
||||
<form string="Donation Details">
|
||||
<header>
|
||||
<button string="Add Benefit"
|
||||
name="add_benefit_wizard"
|
||||
type="object"
|
||||
class="btn-primary"
|
||||
icon="fa-plus-circle"
|
||||
attrs="{'invisible': [('show_add_benefit_button', '=', False)]}"
|
||||
groups="odex_takaful.group_kufula_user" />
|
||||
<button name="action_view_replacement_wizard"
|
||||
string="Orphan Replacement"
|
||||
type="object"
|
||||
class="btn-primary"
|
||||
icon="fa-exchange"
|
||||
attrs="{'invisible': [('show_replaced_button', '=', False)]}"
|
||||
groups="odex_takaful.group_orphan_replacement"/>
|
||||
<button name="action_extend_sponsorship"
|
||||
|
|
@ -406,6 +423,7 @@
|
|||
<field name="state" invisible="1"/>
|
||||
<field name="show_extend_button" invisible="1"/>
|
||||
<field name="show_replaced_button" invisible="1"/>
|
||||
<field name="show_add_benefit_button" invisible="1"/>
|
||||
<field name="sequence_no" invisible="1"/>
|
||||
<field name="donation_type" invisible="1"/>
|
||||
<field name="direct_debit" invisible="1"/>
|
||||
|
|
|
|||
|
|
@ -8,4 +8,5 @@ from . import orphan_replacement_wizard
|
|||
from . import transfer_deduction_wizard
|
||||
from . import donation_extension_wizard
|
||||
from . import replace_sponsor_wizard
|
||||
from . import add_benefit_wizard
|
||||
from . import account_payment_register
|
||||
|
|
|
|||
|
|
@ -0,0 +1,88 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class AddBenefitWizard(models.TransientModel):
|
||||
_name = 'add.benefit.wizard'
|
||||
_description = "Add Benefit"
|
||||
|
||||
donation_detail_id = fields.Many2one(
|
||||
'donations.details.lines',
|
||||
string='Donation Detail',
|
||||
readonly=True
|
||||
)
|
||||
members_domain_ids = fields.Many2many('family.member', related='donation_detail_id.members_domain_ids')
|
||||
|
||||
benefit_id = fields.Many2one('family.member', string='Beneficiary Name', ondelete='restrict',
|
||||
domain="[('id', 'in', members_domain_ids)]",required = True, tracking=True)
|
||||
|
||||
def action_add_benefit(self):
|
||||
"""
|
||||
Add Benefit on the donation detail line and post a message to the chatter
|
||||
"""
|
||||
self.ensure_one()
|
||||
|
||||
if not self.donation_detail_id:
|
||||
raise ValidationError(_("No donation detail line found."))
|
||||
|
||||
if not self.benefit_id:
|
||||
raise ValidationError(_("Please select a Benefit."))
|
||||
|
||||
donation_line = self.donation_detail_id
|
||||
new_benefit_name = self.benefit_id.name
|
||||
|
||||
# Get the sponsorship record (could be sponsorship_id or sponsorship_mechanism_id)
|
||||
sponsorship = donation_line.sponsorship_id or donation_line.sponsorship_mechanism_id
|
||||
|
||||
if not sponsorship:
|
||||
raise ValidationError(_("No sponsorship found for this donation detail line."))
|
||||
|
||||
# Update the Benefit on the donation detail line
|
||||
donation_line.write({
|
||||
'benefit_id': self.benefit_id.id,
|
||||
'benefit_ids': [(6, 0, [self.benefit_id.id])],
|
||||
})
|
||||
(donation_line.benefit_id | donation_line.benefit_ids).sudo().write({
|
||||
'sponsor_related_id': donation_line.sponsor_id.id,
|
||||
'kafala_status': 'have_kafala'
|
||||
})
|
||||
|
||||
# Post message to the donation detail line chatter
|
||||
message_body = _(
|
||||
"Add Benefit: %s"
|
||||
) % (new_benefit_name)
|
||||
|
||||
donation_line.message_post(
|
||||
body=message_body,
|
||||
subject=_("Add Benefit"),
|
||||
message_type='notification',
|
||||
)
|
||||
|
||||
_logger.info(
|
||||
"Add Benefit on donation line : %s",
|
||||
new_benefit_name
|
||||
)
|
||||
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'params': {
|
||||
'title': _('Success'),
|
||||
'message': _('Benefit has been successfully %s') % (
|
||||
new_benefit_name
|
||||
),
|
||||
'type': 'success',
|
||||
'sticky': False,
|
||||
'next': {'type': 'ir.actions.act_window_close'}
|
||||
}
|
||||
}
|
||||
|
||||
def action_cancel(self):
|
||||
"""
|
||||
Cancel the wizard
|
||||
"""
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="add_benefit_wizard_form" model="ir.ui.view">
|
||||
<field name="name">add.benefit.wizard.form</field>
|
||||
<field name="model">add.benefit.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<field name="donation_detail_id" invisible="1"/>
|
||||
<field name="members_domain_ids" invisible="1"/>
|
||||
<group>
|
||||
<group string="Benefit Information">
|
||||
<field name="benefit_id"/>
|
||||
</group>
|
||||
</group>
|
||||
|
||||
</sheet>
|
||||
<footer>
|
||||
<button name="action_add_benefit" type="object" string="Add Benefit" class="oe_highlight"/>
|
||||
<button name="action_cancel" type="object" string="Cancel" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
Loading…
Reference in New Issue