diff --git a/odex25_ensan/odex_takaful/models/res_partner.py b/odex25_ensan/odex_takaful/models/res_partner.py index e36ccb8e0..fbb3bbe2e 100644 --- a/odex25_ensan/odex_takaful/models/res_partner.py +++ b/odex25_ensan/odex_takaful/models/res_partner.py @@ -52,7 +52,12 @@ class ResPartner(models.Model): ('verified', 'Verified') ], string='State',default='draft', tracking=True) - preferred_communication = fields.Many2one('preferred.communication', string="Preferred Communication") + def _get_default_preferred_communication(self): + """Get first preferred communication method as default""" + first_comm = self.env['preferred.communication'].search([], limit=1, order='id asc') + return first_comm if first_comm else False + + preferred_communication = fields.Many2one('preferred.communication', string="Preferred Communication", default=_get_default_preferred_communication) serial_code = fields.Char(string="Serial Code", readonly=True, copy=False) responsible_user_ids = fields.Many2many( diff --git a/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py b/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py index db7fef64b..8a931e4a1 100644 --- a/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py +++ b/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py @@ -761,6 +761,20 @@ class TakafulSponsorship(models.Model): rec.sponsor_or_donor_type = 'registered' elif rec.sponsor_donor_type == 'new_sponsor': rec.sponsor_or_donor_type = 'new_sponsor' + # Clear sponsor_id when switching to new_sponsor + if rec.sponsor_id: + rec.sponsor_id = False + else: + # Clear sponsor_id when switching to unknown or other types + if rec.sponsor_id: + rec.sponsor_id = False + + @api.onchange('sponsor_or_donor_type') + def _onchange_sponsor_or_donor_type(self): + for rec in self: + # Clear sponsor_id when not 'registered' + if rec.sponsor_or_donor_type != 'registered' and rec.sponsor_id: + rec.sponsor_id = False def _get_default_record_type(self): diff --git a/odex25_ensan/odex_takaful/views/assets.xml b/odex25_ensan/odex_takaful/views/assets.xml index 9937e7660..fe10dc676 100644 --- a/odex25_ensan/odex_takaful/views/assets.xml +++ b/odex25_ensan/odex_takaful/views/assets.xml @@ -183,7 +183,7 @@ _update: function () { var result = this._super.apply(this, arguments); - if (this.mode === 'edit' && this.modelName === 'takaful.sponsorship') { + if (this.modelName === 'takaful.sponsorship') { var self = this; setTimeout(function() { self._setupSimpleUI(); @@ -192,6 +192,17 @@ return result; }, + _onSave: function () { + var result = this._super.apply(this, arguments); + if (this.modelName === 'takaful.sponsorship') { + var self = this; + setTimeout(function() { + self._setupSimpleUI(); + }, 100); + } + return result; + }, + _setupSimpleUI: function () { var self = this; @@ -203,11 +214,22 @@ this.$('.record_option').on('click', function () { var $option = $(this); var recordType = $option.data('value'); + var currentData = self.model.localData[self.handle].data; + + // Clear sponsor_id when changing type if not registered + var sponsorOrDonorType = currentData.sponsor_or_donor_type; + var sponsorDonorType = currentData.sponsor_donor_type; + var changes = {record_type: recordType}; + + // Clear sponsor_id if switching types and not 'registered' + if (sponsorOrDonorType !== 'registered' && sponsorDonorType !== 'registered') { + changes.sponsor_id = false; + } // Update field value using Odoo 14 method self.trigger_up('field_changed', { dataPointID: self.handle, - changes: {record_type: recordType} + changes: changes }); // Update visual selection diff --git a/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml b/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml index 7dc8526cc..1b0c96ffd 100644 --- a/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml +++ b/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml @@ -130,12 +130,12 @@