62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
from odoo import models, fields, api, _
|
|
|
|
|
|
class TakafulNotification(models.Model):
|
|
_inherit = 'takaful.notification'
|
|
|
|
name = fields.Char(string='Notification Name', required=True)
|
|
notification_type = fields.Selection([
|
|
('create_kafala', _('Create Kafala')),
|
|
('before_finish', _('Before Kafala End Date')),
|
|
('after_kafala_end', _('After Kafala End Date')),
|
|
('cancel_kafala', _('Cancel Kafala')),
|
|
('refund_full_kafala', _('Fully Refund Kafala')),
|
|
('refund_partial_kafala', _('Partially refund Kafala')),
|
|
('replace_orphan', _('Replace Orphan / Widow')),
|
|
('full_payment', _('Full Payment')),
|
|
('partial_payment', _('Partial Payment')),
|
|
('before_cancel', _('Before Cancel')),
|
|
],
|
|
string='Notification Type',
|
|
default='create_kafala',
|
|
required=True
|
|
)
|
|
|
|
notification_state_ids = fields.Many2many('sponsorship.states', required=True)
|
|
|
|
message = fields.Html(string="Message")
|
|
|
|
|
|
|
|
@api.onchange('notification_type')
|
|
def _onchange_notification_type(self):
|
|
"""Filter available states based on notification_type."""
|
|
if not self.notification_type:
|
|
return
|
|
|
|
allowed_states = {
|
|
'create_kafala': ['draft'],
|
|
'before_finish': ['confirmed', 'wait_pay'],
|
|
'after_kafala_end': ['paid', 'closed'],
|
|
'cancel_kafala': ['canceled'],
|
|
'refund_full_kafala': ['fully_refund'],
|
|
'refund_partial_kafala': ['partial_refund'],
|
|
'replace_orphan': ['under_replacement', 'replacement_done'],
|
|
'full_payment': ['paid'],
|
|
'partial_payment': ['wait_pay'],
|
|
'before_cancel': ['confirmed'],
|
|
}
|
|
|
|
state_names = allowed_states.get(self.notification_type, [])
|
|
|
|
domain = [('name', 'in', state_names)]
|
|
|
|
if allowed_states:
|
|
self.notification_state_ids = self.env['sponsorship.states'].search(domain)
|
|
|
|
return {
|
|
'domain': {
|
|
'notification_state_ids': domain
|
|
}
|
|
}
|