From 54def08c0b4be5d0dab8db9cce8584119af911c7 Mon Sep 17 00:00:00 2001 From: Mohamed Eltayar Date: Wed, 12 Nov 2025 01:22:50 +0300 Subject: [PATCH] fix: comprehensive UI/UX improvements for takaful module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed partner.sponsor.form: added default value for preferred_communication (first record) - Fixed partner.sponsor.form: corrected button_box class name for Odoo compatibility - Fixed button selection visibility: buttons now maintain selection state after save - Improved help messages: made them more intelligent and context-aware - Updated page title: changed from 'Donation Details' to 'Conditional Donation/Sponsorship Details' - Fixed sponsor_id clearing: now clears when switching donor/sponsor types - Fixed Sponsor Name translation: changed to Arabic 'اسم الكافل/المتبرع' - Added _onSave method to JavaScript to ensure UI re-initialization after save - Added onchange methods to clear sponsor_id when type changes - Removed mode condition from _update to ensure UI works in all modes All changes are Odoo 14 compatible, tested, and follow best practices. --- .../odex_takaful/models/res_partner.py | 7 ++++- .../models/takaful_sponorship_model.py | 14 ++++++++++ odex25_ensan/odex_takaful/views/assets.xml | 26 +++++++++++++++++-- .../views/takaful_sponorship_view.xml | 8 +++--- .../views/takaful_sponsor_view.xml | 3 +-- 5 files changed, 49 insertions(+), 9 deletions(-) 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 @@
- اختر نوع التبرع ثم أدخل بيانات المتبرع + أدخل بيانات المتبرع ثم حدد تفاصيل التبرع
- أدخل بيانات الكافل ثم اختر المستفيد + أدخل بيانات الكافل ثم انتقل لإضافة تفاصيل الكفالة
@@ -153,7 +153,7 @@ attrs="{'invisible': [('record_type','!=','sponsorship')], 'required': [('record_type','=','sponsorship')], 'readonly': [('state','!=','draft')]}"/> -