Merge pull request #6178 from expsa/14.0-i18n-odex_benefit-auto-20260113_125130

[FIX] odex_benefit: improve data models and business logic
This commit is contained in:
Mohamed Eltayar 2026-01-13 12:52:04 +03:00 committed by GitHub
commit 596ffd04f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 58 additions and 25 deletions

View File

@ -17200,6 +17200,11 @@ msgstr "يرجى اختيار أمر صرف واحد على الأقل."
msgid "Selected Payment Orders do not reference any posted moves." msgid "Selected Payment Orders do not reference any posted moves."
msgstr "أوامر الصرف المحددة لا تشير إلى أي قيود منشورة." msgstr "أوامر الصرف المحددة لا تشير إلى أي قيود منشورة."
#. module: odex_benefit
#: model:ir.model.fields,field_description:odex_benefit.field_family_bank_report_wizard__total_amount
msgid "Total Amount"
msgstr "إجمالي المبلغ"
#. module: odex_benefit #. module: odex_benefit
#: model:ir.model.fields,field_description:odex_benefit.field_payment_orders__payment_order_date #: model:ir.model.fields,field_description:odex_benefit.field_payment_orders__payment_order_date
msgid "Payment Order Date" msgid "Payment Order Date"

View File

@ -1131,37 +1131,49 @@ class FamilyMemberProfile(models.Model):
}) })
@api.constrains('member_phone') @api.constrains('member_phone')
def _onchange_member_phone_validation(self): def _check_member_phone_validation(self):
if self.member_phone: """Validate member phone number format and uniqueness."""
if self.member_phone.startswith('+966'): for record in self:
member_phone = self.member_phone[4:] if not record.member_phone:
self.member_phone = member_phone continue
if re.match(SAUDI_MOBILE_PATTERN, self.member_phone) == None:
phone = record.member_phone
# Remove +966 prefix if present
if phone.startswith('+966'):
phone = phone[4:]
record.member_phone = phone
# Validate Saudi mobile pattern
if re.match(SAUDI_MOBILE_PATTERN, phone) is None:
raise ValidationError( raise ValidationError(
_('Enter a valid Saudi mobile number')) _('Enter a valid Saudi mobile number'))
exist = self.search([('member_phone', '=', self.member_phone)])
if exist: # Check phone against family's main phones
raise ValidationError( if record.benefit_id and phone in [
_('This Phone Already Exist!')) record.benefit_id.phone,
# Check if the father ID and mother ID are the same on the same record record.benefit_id.phone2,
if self.member_phone == self.benefit_id.phone or self.member_phone == self.benefit_id.phone2 or self.member_phone == self.benefit_id.sms_phone: record.benefit_id.sms_phone
]:
raise ValidationError( raise ValidationError(
_("Phone number cannot be the same in The Family")) _("Phone number cannot be the same in The Family"))
# Check if the ID number exists in other records or in family members # Check for duplicate phone in other members (excluding current record)
exist = self.search([ exist = self.search([
('member_phone', '=', self.member_phone) ('member_phone', '=', phone),
('id', '!=', record.id)
], limit=1) ], limit=1)
if exist:
raise ValidationError(
_("The phone Number already exists in Family with code %s") % exist.benefit_id.code)
# Check if phone exists in grant.benefit
exist_in_family = self.env["grant.benefit"].search([ exist_in_family = self.env["grant.benefit"].search([
'|', '|', '|', '|',
('phone', '=', self.member_phone), ('phone', '=', phone),
('phone2', '=', self.member_phone), ('phone2', '=', phone),
('sms_phone', '=', self.member_phone), ('sms_phone', '=', phone),
], limit=1) ], limit=1)
if exist or exist_in_family: if exist_in_family:
if exist_in_family: raise ValidationError(
raise ValidationError( _("The phone Number already exists in Family with code %s") % exist_in_family.code)
_("The phone Number already exists in Family with code %s") % exist_in_family.code)
if exist:
raise ValidationError(
_("The phone Number already exists in Family with code %s") % exist.benefit_id.code)

View File

@ -22,6 +22,14 @@ class FamilyBankReportWizard(models.TransientModel):
payment_order_ids = fields.Many2many(comodel_name='payment.orders', payment_order_ids = fields.Many2many(comodel_name='payment.orders',
string="Payment Orders", required=True, string="Payment Orders", required=True,
domain="[('state', '=', 'waiting_deposit'),('payment_order_date','>=', start_date),('payment_order_date','<=', end_date)]") domain="[('state', '=', 'waiting_deposit'),('payment_order_date','>=', start_date),('payment_order_date','<=', end_date)]")
currency_id = fields.Many2one('res.currency', string='Currency', default=lambda self: self.env.company.currency_id)
total_amount = fields.Monetary(string="Total Amount", compute='_compute_total_amount', store=False, currency_field='currency_id')
@api.depends('payment_order_ids', 'payment_order_ids.total_amount')
def _compute_total_amount(self):
"""Compute total amount from selected payment orders."""
for record in self:
record.total_amount = sum(record.payment_order_ids.mapped('total_amount'))
def action_print_bank_report(self): def action_print_bank_report(self):
if not self.payment_order_ids: if not self.payment_order_ids:

View File

@ -15,6 +15,14 @@
<field name="end_date"/> <field name="end_date"/>
</group> </group>
</group> </group>
<group>
<group>
<field name="currency_id" invisible="1"/>
</group>
<group>
<field name="total_amount" widget="monetary" options="{'currency_field': 'currency_id'}" readonly="1" class="oe_subtotal_footer_separator"/>
</group>
</group>
<notebook> <notebook>
<page string="Payment Orders"> <page string="Payment Orders">
<field name="payment_order_ids" options="{'no_create': True}"/> <field name="payment_order_ids" options="{'no_create': True}"/>