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:
commit
596ffd04f5
|
|
@ -17200,6 +17200,11 @@ msgstr "يرجى اختيار أمر صرف واحد على الأقل."
|
|||
msgid "Selected Payment Orders do not reference any posted moves."
|
||||
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
|
||||
#: model:ir.model.fields,field_description:odex_benefit.field_payment_orders__payment_order_date
|
||||
msgid "Payment Order Date"
|
||||
|
|
|
|||
|
|
@ -1131,37 +1131,49 @@ class FamilyMemberProfile(models.Model):
|
|||
})
|
||||
|
||||
@api.constrains('member_phone')
|
||||
def _onchange_member_phone_validation(self):
|
||||
if self.member_phone:
|
||||
if self.member_phone.startswith('+966'):
|
||||
member_phone = self.member_phone[4:]
|
||||
self.member_phone = member_phone
|
||||
if re.match(SAUDI_MOBILE_PATTERN, self.member_phone) == None:
|
||||
def _check_member_phone_validation(self):
|
||||
"""Validate member phone number format and uniqueness."""
|
||||
for record in self:
|
||||
if not record.member_phone:
|
||||
continue
|
||||
|
||||
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(
|
||||
_('Enter a valid Saudi mobile number'))
|
||||
exist = self.search([('member_phone', '=', self.member_phone)])
|
||||
if exist:
|
||||
raise ValidationError(
|
||||
_('This Phone Already Exist!'))
|
||||
# Check if the father ID and mother ID are the same on the same record
|
||||
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:
|
||||
|
||||
# Check phone against family's main phones
|
||||
if record.benefit_id and phone in [
|
||||
record.benefit_id.phone,
|
||||
record.benefit_id.phone2,
|
||||
record.benefit_id.sms_phone
|
||||
]:
|
||||
raise ValidationError(
|
||||
_("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([
|
||||
('member_phone', '=', self.member_phone)
|
||||
('member_phone', '=', phone),
|
||||
('id', '!=', record.id)
|
||||
], 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([
|
||||
'|', '|',
|
||||
('phone', '=', self.member_phone),
|
||||
('phone2', '=', self.member_phone),
|
||||
('sms_phone', '=', self.member_phone),
|
||||
('phone', '=', phone),
|
||||
('phone2', '=', phone),
|
||||
('sms_phone', '=', phone),
|
||||
], limit=1)
|
||||
if exist or exist_in_family:
|
||||
if exist_in_family:
|
||||
raise ValidationError(
|
||||
_("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)
|
||||
if exist_in_family:
|
||||
raise ValidationError(
|
||||
_("The phone Number already exists in Family with code %s") % exist_in_family.code)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,14 @@ class FamilyBankReportWizard(models.TransientModel):
|
|||
payment_order_ids = fields.Many2many(comodel_name='payment.orders',
|
||||
string="Payment Orders", required=True,
|
||||
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):
|
||||
if not self.payment_order_ids:
|
||||
|
|
|
|||
|
|
@ -15,6 +15,14 @@
|
|||
<field name="end_date"/>
|
||||
</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>
|
||||
<page string="Payment Orders">
|
||||
<field name="payment_order_ids" options="{'no_create': True}"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue