From 240b65c88d9bff0a41e49e7a4d2672634053bbca Mon Sep 17 00:00:00 2001 From: Mohamed Eltayar Date: Wed, 12 Nov 2025 00:46:10 +0300 Subject: [PATCH] fix: correct sponsor/donor fields behavior and logic - Fixed sponsor_donor_type: added default='registered' in Python model - Fixed preferred_communication: removed duplicate field, unified with correct attrs - Fixed sponsor_id: always visible, readonly when new_sponsor selected - Fixed sponsor_phone: readonly for registered/new_sponsor, editable for unknown - Fixed preferred_communication: hidden for unknown, readonly always, not required - Fixed create_new_sponsor button: moved next to sponsor_id field with correct visibility logic - Added required attribute to sponsor_or_donor_type and sponsor_donor_type fields - Enhanced JavaScript: added _update method to reinitialize UI on form re-renders - Enhanced CSS: unified button widths for donation mechanism options All changes are Odoo 14 compatible and tested. Synced with latest dev_odex25_ensan on 20251112 --- .../models/takaful_sponorship_model.py | 2 +- odex25_ensan/odex_takaful/views/assets.xml | 21 ++++++ .../views/takaful_sponorship_view.xml | 67 ++++++++++++------- 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py b/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py index 713f5a920..a73d2a5e2 100644 --- a/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py +++ b/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py @@ -69,7 +69,7 @@ class TakafulSponsorship(models.Model): sponsor_note = fields.Text(string='Sponsor Note') sponsor_or_donor_type = fields.Selection(string='Sponsor / Donor Type',selection=[('registered', 'Registered'), ('new_sponsor', 'New Sponsor'), ('unknown', 'Unknown')], required=True, default='registered') # ('not_registered', 'Not Registered'), - sponsor_donor_type = fields.Selection(string='Sponsor / Donor Type',selection=[('registered', 'Registered'), ('new_sponsor', 'New Sponsor')]) + sponsor_donor_type = fields.Selection(string='Sponsor / Donor Type',selection=[('registered', 'Registered'), ('new_sponsor', 'New Sponsor')], default='registered') sponsor_name = fields.Char(string="Sponsor Name") sponsor_phone = fields.Char(string="Sponsor Phone", compute='_compute_sponsor_phone', store=True, readonly=False) sponsor_title = fields.Many2one('res.partner.title',string='Sponsor Title') diff --git a/odex25_ensan/odex_takaful/views/assets.xml b/odex25_ensan/odex_takaful/views/assets.xml index 26afaa7ae..9937e7660 100644 --- a/odex25_ensan/odex_takaful/views/assets.xml +++ b/odex25_ensan/odex_takaful/views/assets.xml @@ -127,6 +127,12 @@ font-size: 16px; } + .mechanism_option span { + min-width: 90px; + display: inline-block; + text-align: center; + } + .mechanism_option:hover { border-color: #ffc107; background: #fffbf0; @@ -175,9 +181,24 @@ }); }, + _update: function () { + var result = this._super.apply(this, arguments); + if (this.mode === 'edit' && this.modelName === 'takaful.sponsorship') { + var self = this; + setTimeout(function() { + self._setupSimpleUI(); + }, 50); + } + return result; + }, + _setupSimpleUI: function () { var self = this; + // Remove old event handlers to prevent duplicates + this.$('.record_option').off('click'); + this.$('.mechanism_option').off('click'); + // Record Type Options - Odoo 14 Compatible Method this.$('.record_option').on('click', function () { var $option = $(this); diff --git a/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml b/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml index 6177cf884..82a51a2b4 100644 --- a/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml +++ b/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml @@ -148,41 +148,62 @@