fix: sponsor form issues - footer buttons + required name + constraint
**Fixed Issues:** 1. Save & Close Button - Moved to Footer - Removed button from header - Added footer with 'حفظ وإغلاق' button (replaces default Save) - Added 'تجاهل' button (Cancel) - Now matches Odoo wizard standard pattern 2. Required First Name - Made 'first_name' field required (required="1") - Title and suffix remain optional - Ensures sponsor name is always filled 3. New Sponsor Constraint - Added @api.constrains to prevent saving when 'new_sponsor' selected but no sponsor created - Clear Arabic error messages guide user to create sponsor first - Only enforced in draft state - Works for both donation and sponsorship types 4. Form Create Disabled - Added create="false" to form to prevent accidental inline creation - Users must use proper workflow All changes Odoo 14 compatible. Tested validation. Synced with latest dev_odex25_ensan on Wed Nov 12 02:51:27 +03 2025
This commit is contained in:
parent
cd764cec50
commit
c46395e42d
|
|
@ -801,6 +801,22 @@ class TakafulSponsorship(models.Model):
|
|||
rec.sponsor_phone = rec.sponsor_id.mobile
|
||||
rec.preferred_communication = rec.sponsor_id.preferred_communication
|
||||
|
||||
@api.constrains('sponsor_id', 'sponsor_or_donor_type', 'sponsor_donor_type', 'state')
|
||||
def _check_new_sponsor_created(self):
|
||||
"""
|
||||
Constraint: If user selects 'new_sponsor', they must create a sponsor before saving
|
||||
"""
|
||||
for rec in self:
|
||||
if rec.state == 'draft': # Only check in draft state
|
||||
# Check for donation
|
||||
if rec.record_type == 'donation' and rec.sponsor_or_donor_type == 'new_sponsor':
|
||||
if not rec.sponsor_id:
|
||||
raise ValidationError(_('يجب إنشاء مشترك جديد أولاً قبل الحفظ. اضغط على زر "إنشاء مشترك" لإضافة مشترك جديد.'))
|
||||
# Check for sponsorship
|
||||
elif rec.record_type == 'sponsorship' and rec.sponsor_donor_type == 'new_sponsor':
|
||||
if not rec.sponsor_id:
|
||||
raise ValidationError(_('يجب إنشاء كافل جديد أولاً قبل الحفظ. اضغط على زر "إنشاء مشترك" لإضافة كافل جديد.'))
|
||||
|
||||
def _get_default_record_type(self):
|
||||
if self.env.user.has_group("odex_takaful.donation_officer_group"):
|
||||
return "donation"
|
||||
|
|
|
|||
|
|
@ -29,11 +29,8 @@
|
|||
<field name="name">partner.sponsor.form</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="The sponsor">
|
||||
<form string="The sponsor" create="false">
|
||||
<header>
|
||||
<button name="action_save_and_close" string="حفظ وإغلاق" type="object"
|
||||
class="btn-primary" attrs="{'invisible': [('id', '!=', False)]}"
|
||||
context="{'save_and_close': True}"/>
|
||||
<button name="action_unlink_sponsor_and_related" string="Unlink Partners" type="object"
|
||||
groups="base.group_no_one" invisible="1"/>
|
||||
</header>
|
||||
|
|
@ -86,7 +83,7 @@
|
|||
<field placeholder="اللقب" name="title" class="oe_inline" nolabel="1" style="width: 20%;"
|
||||
domain="[('position', 'in', ['prefix','both'])]"
|
||||
options="{'no_create': True, 'no_create_edit':True, 'no_open': True}"/>
|
||||
<field placeholder="الاسم" name="first_name" class="oe_inline" nolabel="1" style="width: 60%;"/>
|
||||
<field placeholder="الاسم" name="first_name" class="oe_inline" nolabel="1" style="width: 60%;" required="1"/>
|
||||
<field placeholder="العبارة الختامية" name="suffix_title_id" class="oe_inline" nolabel="1" style="width: 20%;"
|
||||
domain="[('position', 'in', ['suffix','both'])]"
|
||||
options="{'no_create': True, 'no_create_edit':True, 'no_open': True}"/>
|
||||
|
|
@ -188,6 +185,10 @@
|
|||
|
||||
</notebook>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button name="action_save_and_close" string="حفظ وإغلاق" type="object" class="btn-primary"/>
|
||||
<button string="تجاهل" class="btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
<div class="oe_chatter">
|
||||
<field name="message_follower_ids" widget="mail_followers"/>
|
||||
<field name="message_ids" widget="mail_thread"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue