From 527d85249ea92ec65a1d6e12d5c5eaa419007860 Mon Sep 17 00:00:00 2001 From: Samir Ladoui Date: Fri, 19 Sep 2025 12:16:18 +0100 Subject: [PATCH] [UPD] odex_benefit --- odex25_ensan/odex_benefit/i18n/ar_001.po | 21 +++++++++++ odex25_ensan/odex_benefit/models/benefit.py | 11 +++--- .../odex_benefit/models/benefit_config.py | 1 + .../odex_benefit/models/family_members.py | 13 +++++++ .../views/benefit_config_view.xml | 1 + .../odex_benefit/views/benefit_view.xml | 11 +++--- .../wizards/suspend_reason_wizard.py | 35 +++++++++++++++---- 7 files changed, 76 insertions(+), 17 deletions(-) diff --git a/odex25_ensan/odex_benefit/i18n/ar_001.po b/odex25_ensan/odex_benefit/i18n/ar_001.po index 3394a4182..31b2ce6bd 100644 --- a/odex25_ensan/odex_benefit/i18n/ar_001.po +++ b/odex25_ensan/odex_benefit/i18n/ar_001.po @@ -1336,6 +1336,11 @@ msgstr "المناطق والمحافظات" msgid "Age" msgstr "العمر" +#. module: odex_benefit +#: model:ir.model.fields,field_description:odex_benefit.field_relation_settings__age_difference +msgid "Age Difference" +msgstr "فرق العمر" + #. module: odex_benefit #: model:ir.model.fields,field_description:odex_benefit.field_generate_reports__age_from #: model:ir.model.fields,field_description:odex_benefit.field_rooms_categories__age_from @@ -11327,6 +11332,22 @@ msgstr "رقم الجوال {} موجود بالفعل في أسرة بكود {} msgid "The phone {} already exists in family with code {}." msgstr "رقم الجوال {} موجود بالفعل في أسرة بكود {}" +#. module: odex_benefit +#: code:addons/odex_benefit/models/family_members.py:0 +#, python-format +msgid "" +"The son/daughter's age is supposed to be less than the father's age by %s" +msgstr "" +"عمر الابن/الابنة مفترض أن يكون أقل من عمر الأب بـ %s" + +#. module: odex_benefit +#: code:addons/odex_benefit/models/family_members.py:0 +#, python-format +msgid "" +"The son/daughter's age is supposed to be less than the mother's age by %s" +msgstr "" +"عمر الابن/الابنة مفترض أن يكون أقل من عمر الأم بـ %s" + #. module: odex_benefit #: model:ir.model.fields,help:odex_benefit.field_benefits_representative__membership_amount #: model:ir.model.fields,help:odex_benefit.field_external_benefits__membership_amount diff --git a/odex25_ensan/odex_benefit/models/benefit.py b/odex25_ensan/odex_benefit/models/benefit.py index 08610c282..9d10e05ff 100644 --- a/odex25_ensan/odex_benefit/models/benefit.py +++ b/odex25_ensan/odex_benefit/models/benefit.py @@ -427,7 +427,7 @@ class GrantBenefitProfile(models.Model): ) zip = fields.Char('Zip', change_default=True, readonly=False, store=True) # res_city_id = fields.Many2one('res.city', domain="[('country_city_id', '=', city_id)]") - housing_city = fields.Char() + # housing_city = fields.Char() url = fields.Char() url_html = fields.Html( sanitize=False, @@ -2006,15 +2006,16 @@ class GrantBenefitProfile(models.Model): 'target': 'current', } - @api.depends('birth_date') + @api.depends('father_birth_date') def _compute_get_father_age(self): for rec in self: - if rec.birth_date: + if rec.father_birth_date: today = date.today() - day = datetime.strptime(str(rec.birth_date), DEFAULT_SERVER_DATE_FORMAT) + day = datetime.strptime(str(rec.father_birth_date), DEFAULT_SERVER_DATE_FORMAT) age = rd(today, day) rec.father_age = age.years - rec.father_age = 0 + else: + rec.father_age = 0 @api.depends('mother_birth_date') def _compute_get_mother_age(self): diff --git a/odex25_ensan/odex_benefit/models/benefit_config.py b/odex25_ensan/odex_benefit/models/benefit_config.py index a1981f99d..29991d1b5 100644 --- a/odex25_ensan/odex_benefit/models/benefit_config.py +++ b/odex25_ensan/odex_benefit/models/benefit_config.py @@ -734,6 +734,7 @@ class RelationSettings(models.Model): name = fields.Char(string='name') relation_type = fields.Selection( [('son', _('Son')), ('daughter', _('Daughter')),('mother', _('Mother')),('replacement_mother', _('Replacement Mother')),('other relation', _('Other Relation'))]) + age_difference = fields.Integer() class LocationSettings(models.Model): _name = 'location.settings' diff --git a/odex25_ensan/odex_benefit/models/family_members.py b/odex25_ensan/odex_benefit/models/family_members.py index 2033b1907..31e5df17d 100644 --- a/odex25_ensan/odex_benefit/models/family_members.py +++ b/odex25_ensan/odex_benefit/models/family_members.py @@ -262,6 +262,19 @@ class FamilyMemberProfile(models.Model): # _("You should at least insert one current/previous education status!") # ) # return super(FamilyMemberProfile, self).write(vals) + + @api.onchange('age') + def _check_son_daughter_age(self): + for rec in self: + if rec.relationn.relation_type in ['son', 'daughter'] and rec.relationn.age_difference > 0: + if rec.benefit_id.father_age and rec.benefit_id.father_age - rec.age < rec.relationn.age_difference: + raise ValidationError( + _("The son/daughter's age is supposed to be less than the father's age by %s" % rec.relationn.age_difference) + ) + if rec.benefit_id.mother_age and rec.benefit_id.mother_age - rec.age < rec.relationn.age_difference: + raise ValidationError( + _("The son/daughter's age is supposed to be less than the mother's age by %s" % rec.relationn.age_difference) + ) @api.depends('age_status', 'is_dead','benefit_id.member_ids.age_status','benefit_id.member_ids.is_dead') def _compute_minor_siblings(self): diff --git a/odex25_ensan/odex_benefit/views/benefit_config_view.xml b/odex25_ensan/odex_benefit/views/benefit_config_view.xml index 5aec99058..7d2bf26be 100644 --- a/odex25_ensan/odex_benefit/views/benefit_config_view.xml +++ b/odex25_ensan/odex_benefit/views/benefit_config_view.xml @@ -1002,6 +1002,7 @@ + diff --git a/odex25_ensan/odex_benefit/views/benefit_view.xml b/odex25_ensan/odex_benefit/views/benefit_view.xml index c1e814d58..dedc70536 100644 --- a/odex25_ensan/odex_benefit/views/benefit_view.xml +++ b/odex25_ensan/odex_benefit/views/benefit_view.xml @@ -1001,20 +1001,21 @@ widget="many2many_attachment_preview"/> - - --> + - + diff --git a/odex25_ensan/odex_benefit/wizards/suspend_reason_wizard.py b/odex25_ensan/odex_benefit/wizards/suspend_reason_wizard.py index 8b674df6c..4d279abfe 100644 --- a/odex25_ensan/odex_benefit/wizards/suspend_reason_wizard.py +++ b/odex25_ensan/odex_benefit/wizards/suspend_reason_wizard.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- -from odoo import models, fields +from odoo import models, fields, _ +from odoo.exceptions import UserError class SuspendReasonWizard(models.TransientModel): @@ -21,11 +22,31 @@ class SuspendReasonWizard(models.TransientModel): entity_id = fields.Many2one("grant.benefit", string="Entity", default=_default_entity) member_id = fields.Many2one("family.member", string="Member", default=_default_member) - suspend_reason = fields.Many2one('suspend.reason',string='Suspend Reason') - suspend_description = fields.Text(string='Suspend Description') - suspend_attachment = fields.Binary(string='Suspend Attachment',attachment = True) - suspend_type = fields.Selection(selection=[('temporarily_suspend', 'Temporarily Suspended'), ('suspend', 'Suspend')], string="Suspend Type") + suspend_reason = fields.Many2one('suspend.reason',string='Suspend Reason', required=True) + suspend_description = fields.Text(string='Suspend Description', required=True) + suspend_attachment = fields.Binary(string='Suspend Attachment', attachment=True, required=True) + suspend_type = fields.Selection(selection=[('temporarily_suspend', 'Temporarily Suspended'), ('suspend', 'Suspend')], string="Suspend Type", required=True) + + def _create_attachment_record_from_binary(self): + self.ensure_one() + + linked_record = self.entity_id or self.member_id + if not linked_record: + UserError( + _('There is no record to link the binary to it!') + ) + binary_file = self.suspend_attachment + attachment_vals = { + 'name': 'suspend_attachment_%s' % (linked_record.id or 'tmp'), + 'datas': binary_file, + 'res_model': 'grant.benefit', + 'res_id': linked_record.id, + 'type': 'binary', + } + + return self.env['ir.attachment'].create(attachment_vals) + def action_submit(self): for rec in self: rec.entity_id.state = 'waiting_approve' @@ -33,7 +54,7 @@ class SuspendReasonWizard(models.TransientModel): rec.entity_id.suspend_reason = rec.suspend_reason rec.entity_id.suspend_description = rec.suspend_description rec.entity_id.suspend_type = rec.suspend_type - rec.entity_id.suspend_attachment = rec.suspend_attachment + rec.entity_id.suspend_attachment = self._create_attachment_record_from_binary() rec.entity_id.suspend_method = 'manual' def action_member_submit(self): @@ -43,5 +64,5 @@ class SuspendReasonWizard(models.TransientModel): rec.member_id.suspend_reason = rec.suspend_reason rec.member_id.suspend_description = rec.suspend_description rec.member_id.suspend_type = rec.suspend_type - rec.member_id.suspend_attachment = rec.suspend_attachment + rec.member_id.suspend_attachment = self._create_attachment_record_from_binary() rec.member_id.suspend_method = 'manual'