diff --git a/odex25_ensan/odex25_empowermentmanagement/models/empowerment_management.py b/odex25_ensan/odex25_empowermentmanagement/models/empowerment_management.py index de29a6cf3..081b797c1 100644 --- a/odex25_ensan/odex25_empowermentmanagement/models/empowerment_management.py +++ b/odex25_ensan/odex25_empowermentmanagement/models/empowerment_management.py @@ -2,6 +2,8 @@ from odoo import models, fields, api, _ from odoo.exceptions import ValidationError from datetime import datetime +from odoo.exceptions import UserError, ValidationError + class EmpowermentRequest(models.Model): @@ -118,6 +120,12 @@ class EmpowermentRequest(models.Model): string="Qualifications" ) + def unlink(self): + for order in self: + if order.state not in ['draft']: + raise UserError(_('You cannot delete this record State not Draft')) + return super(EmpowermentRequest, self).unlink() + @api.model def create(self, vals): diff --git a/odex25_ensan/odex25_empowermentmanagement/views/service_settings.xml b/odex25_ensan/odex25_empowermentmanagement/views/service_settings.xml index a38d2d6f3..c447a4b44 100644 --- a/odex25_ensan/odex25_empowermentmanagement/views/service_settings.xml +++ b/odex25_ensan/odex25_empowermentmanagement/views/service_settings.xml @@ -201,8 +201,6 @@ - - diff --git a/odex25_ensan/odex25_program_activity/i18n/ar_001.po b/odex25_ensan/odex25_program_activity/i18n/ar_001.po index ec1369183..6646539cc 100644 --- a/odex25_ensan/odex25_program_activity/i18n/ar_001.po +++ b/odex25_ensan/odex25_program_activity/i18n/ar_001.po @@ -530,17 +530,17 @@ msgstr "نوع البرنامج" #. module: odex25_program_activity -#: model:ir.model.fields.selection,name:odex25_program_activity.selection__pa_program_level_type__route +#: model:ir.model.fields.selection,name:odex25_program_activity.selection__pa_program_level__type__route msgid "Tracks" msgstr "مسارات " #. module: odex25_program_activity -#: model:ir.model.fields.selection,name:odex25_program_activity.selection__pa_program_level_type__activity +#: model:ir.model.fields.selection,name:odex25_program_activity.selection__pa_program_level__type__activity msgid "Activities" msgstr "أنشطة" #. module: odex25_program_activity -#: model:ir.model.fields.selection,name:odex25_program_activity.selection__pa_program_level_type__medad +#: model:ir.model.fields.selection,name:odex25_program_activity.selection__pa_program_level__type__medad msgid "Medad" msgstr "مداد" diff --git a/odex25_ensan/odex25_program_activity/models/program.py b/odex25_ensan/odex25_program_activity/models/program.py index 252402bf3..c86b5bc27 100644 --- a/odex25_ensan/odex25_program_activity/models/program.py +++ b/odex25_ensan/odex25_program_activity/models/program.py @@ -1,5 +1,7 @@ from odoo import models, fields, api, _ from odoo.exceptions import ValidationError +from odoo.exceptions import UserError, ValidationError + class PaProgramLevel(models.Model): @@ -409,6 +411,12 @@ class PaProgramActivityRegistration(models.Model): rejection_reason = fields.Text('سبب الارجاع') # To hold the last rejection note + def unlink(self): + for order in self: + if order.state not in ['draft']: + raise UserError(_('You cannot delete this record State not Draft')) + return super(PaProgramActivityRegistration, self).unlink() + @api.onchange('familye_id') def _onchange_familye_id(self): if self.familye_id: diff --git a/odex25_ensan/odex25_program_activity/views/program.xml b/odex25_ensan/odex25_program_activity/views/program.xml index 0af2a54bd..5d74e9452 100644 --- a/odex25_ensan/odex25_program_activity/views/program.xml +++ b/odex25_ensan/odex25_program_activity/views/program.xml @@ -389,7 +389,7 @@ + readonly="1" edit="0" create="0">
@@ -553,7 +553,7 @@ - + diff --git a/odex25_ensan/odex_benefit/i18n/ar_001.po b/odex25_ensan/odex_benefit/i18n/ar_001.po index 0e3a23595..3394a4182 100644 --- a/odex25_ensan/odex_benefit/i18n/ar_001.po +++ b/odex25_ensan/odex_benefit/i18n/ar_001.po @@ -10371,6 +10371,11 @@ msgstr "تم تحديد الموعد" msgid "Schedule a visit" msgstr "جاري الزيارة" +#. module: odex_benefit +#: model:ir.model.fields.selection,name:odex_benefit.selection__visit_location__state__pending +msgid "Pending" +msgstr "معلق" + #. module: odex_benefit #: model:ir.model.fields,field_description:odex_benefit.field_program_plane_line__score msgid "Score" diff --git a/odex25_ensan/odex_benefit/models/benefit.py b/odex25_ensan/odex_benefit/models/benefit.py index b1cad43af..61d2f8404 100644 --- a/odex25_ensan/odex_benefit/models/benefit.py +++ b/odex25_ensan/odex_benefit/models/benefit.py @@ -63,6 +63,8 @@ class GrantBenefitProfile(models.Model): ('benefit', 'Benefit'), ('non_benefit', 'Non Benefit'), ], string='Mother Status', compute="check_mother_status", store=True, default=False) + mother_salary_certificate = fields.Many2many('ir.attachment', 'mother_member_salary_cert_rel', 'mother_grant_benefit_id', 'attachment_id', + string="Salary Certificate") phone2 = fields.Char(string="Phone2") relative_phone = fields.Char(string="Relative Phone") relative_relation = fields.Char(string="Relative Relation") @@ -542,6 +544,9 @@ class GrantBenefitProfile(models.Model): ('benefit', 'Benefit'), ('non_benefit', 'Non Benefit'), ], string='Replacement Mother Status', compute="check_replacement_mother_status", store=True, default=False) + replacement_mother_salary_certificate = fields.Many2many('ir.attachment', 'replacement_mother_member_salary_cert_rel', + 'replacement_mother_grant_benefit_id', 'attachment_id', + string="Salary Certificate") # Education_data for replacement mother replacement_education_status_ids = fields.One2many('education.status', 'replacement_grant_benefit_id') replacement_education_status = fields.Selection( @@ -1038,7 +1043,7 @@ class GrantBenefitProfile(models.Model): # Check for uniqueness against `member_id_number` in child records and across database records for member in self.member_ids: - if member.member_id_number and member.member_id_number in unique_ids: + if member.member_id_number and member.member_id_number in unique_ids and member.id not in [self.mother_family_member_id.id,self.replacement_mother_family_member_id.id]: raise ValidationError(_("The ID number %s in the Family Members list must be unique across the record.")%member.member_id_number) # Check for duplicate IDs across records in the database for id_number in unique_ids: @@ -1064,7 +1069,7 @@ class GrantBenefitProfile(models.Model): if conflict: raise ValidationError(_("The ID number %s already exists in family with code %s.") % (id_number, conflict.code)) - duplicate_record_member = self.env['family.member'].search([('member_id_number', '=', id_number)], limit=1) + duplicate_record_member = self.env['family.member'].search([('member_id_number', '=', id_number),('id', 'not in', [self.mother_family_member_id.id, self.replacement_mother_family_member_id.id])], limit=1) if duplicate_record_member : raise ValidationError(_("The ID number {} already exists in family with code {}. Please enter a unique ID number.").format(id_number, duplicate_record_member.code)) @@ -1127,19 +1132,19 @@ class GrantBenefitProfile(models.Model): rec.mother_status = False if rec.mother_location_conf and rec.mother_marital_conf: if not rec.mother_location_conf.is_benefit or not rec.mother_marital_conf.is_benefit or rec.state == 'suspended_second_approve': - rec.write({'mother_status':'non_benefit'}) + rec.mother_status = 'non_benefit' elif rec.mother_marital_conf.is_benefit : if rec.is_mother_work and rec.mother_country_id.code == 'SA' or ( rec.mother_country_id.code != 'SA' and rec.father_country_id.code == 'SA'): if mini_income_for_mother < rec.mother_income <= max_income_for_mother: - rec.write({'mother_status': 'non_benefit'}) + rec.mother_status = 'non_benefit' elif rec.mother_income <= mini_income_for_mother: - rec.write({'mother_status': 'benefit'}) + rec.mother_status = 'benefit' elif rec.mother_income > max_income_for_mother: - rec.write({'mother_status': 'benefit'}) + rec.mother_status = 'benefit' elif not rec.is_mother_work and rec.mother_country_id.code == 'SA' or ( rec.mother_country_id.code != 'SA' and rec.father_country_id.code == 'SA'): - rec.write({'mother_status': 'benefit'}) + rec.mother_status = 'benefit' @api.depends('replacement_mother_marital_conf', 'replacement_mother_income', 'replacement_mother_location_conf', 'replacement_mother_country_id', 'state') @@ -1148,7 +1153,9 @@ class GrantBenefitProfile(models.Model): mini_income_for_mother = validation_setting.mini_income_for_mother max_income_for_mother = validation_setting.max_income_for_mother for rec in self: - rec.replacement_mother_status = False + rec.replacement_mother_status = 'non_benefit' + if not rec.add_replacement_mother: + continue if not rec.replacement_mother_location_conf.is_benefit or not rec.replacement_mother_marital_conf.is_benefit or rec.state == 'suspended_second_approve': rec.replacement_mother_status = 'non_benefit' elif rec.replacement_mother_marital_conf.is_benefit: @@ -1201,22 +1208,11 @@ class GrantBenefitProfile(models.Model): if 'salary_ids' in fields: res['salary_ids'] = income_attachments_data return res - + def write(self, vals): - # mother_education_status = vals.get("education_status", False) or self.education_status - # if mother_education_status == "educated" and "mother_education_status_ids" not in vals and not len(self.mother_education_status_ids): - # raise ValidationError( - # _("You should at least insert one current/previous mother education status!") - # ) - # replacement_education_status = vals.get("replacement_education_status", False) or self.replacement_education_status - # if replacement_education_status == "educated" and "replacement_education_status_ids" not in vals and not len(self.replacement_education_status_ids): - # raise ValidationError( - # _("You should at least insert one current/previous mother education status!") - # ) res = super(GrantBenefitProfile, self).write(vals) if "name" in vals and self.user_id: self.user_id.sudo().write({"name": vals.get("name")}) - # res = super(GrantBenefitProfile, self).write(vals) if any(field in vals for field in ["name", "first_name", "second_name", "middle_name", "family_name", "father_name", "father_second_name", "father_third_name", "father_family_name"]): @@ -1226,6 +1222,32 @@ class GrantBenefitProfile(models.Model): record.sudo().user_id.write({"name": record.partner_id.name}) if not self.env.context.get('force_website', False) and not self.env.context.get('bypass_attachments_requirement', False): self._validate_required_attachments() + + # Handle mother update/create + mother_fields = [ + 'mother_name', 'mother_second_name', 'mother_third_name', 'mother_family_name', 'mother_id_number', + 'mother_birth_date', 'mother_marital_conf', 'mother_location_conf', 'is_mother_work', + 'mother_income', 'mother_age','education_status','mother_diseases_attachment_ids', + 'mother_education_status_ids','mother_disabilities_attachment_ids' + ] + if any(field in vals for field in mother_fields): + for rec in self: + rec.add_or_replace_mother_as_member() + + # Handle replacement mother update/create + replacement_fields = [ + 'replacement_mother_name', 'replacement_mother_second_name', 'replacement_mother_third_name', + 'replacement_mother_family_name','replacement_mother_id_number', + 'replacement_mother_birth_date', 'replacement_mother_marital_conf', + 'replacement_mother_location_conf','replacement_mother_relation', + 'replacement_is_mother_work', 'replacement_mother_income', 'replacement_education_status', + 'replacement_mother_age','replacement_mother_disabilities_attachment_ids', + 'replacement_education_status_ids', 'replacement_mother_diseases_attachment_ids' + ] + if any(field in vals for field in replacement_fields): + for rec in self: + if rec.add_replacement_mother: + rec.add_or_replace_replacement_mother_as_member() return res @api.model @@ -1243,9 +1265,10 @@ class GrantBenefitProfile(models.Model): res.code = self.env['ir.sequence'].sudo().next_by_code('benefit.sequence') or _('New') # Add mother if res.mother_id_number: - res.add_mother_as_member() + res.add_or_replace_mother_as_member() + # Add replacement mother if res.add_replacement_mother and res.replacement_mother_id_number: - res.add_replacement_mother_as_member() + res.add_or_replace_replacement_mother_as_member() return res def unlink(self): @@ -1310,20 +1333,7 @@ class GrantBenefitProfile(models.Model): # # if rec.member_income == 0.0: # raise ValidationError(_("يرجى اكمال ادخال او الموافقة على القيم المرتبطة ببيانات الدخل والمرتب والالتزامات لتحديد فئة الاسرة بشكل صحيح")) - - rec.validate_attachments() - mother_exist = self.env["family.member"].search([('member_id_number', '=', rec.mother_id_number),('relationn.relation_type','=','mother')], limit=1) - replacement_mother_exist = self.env["family.member"].search([('member_id_number', '=', rec.replacement_mother_id_number),('relationn.relation_type','=','replacement_mother')], limit=1) - if not mother_exist: - rec.add_mother_as_member() - if mother_exist: - rec.replace_mother_as_member(mother_exist.id) - if rec.add_replacement_mother: - if not replacement_mother_exist: - rec.add_replacement_mother_as_member() - if replacement_mother_exist: - rec.replace_replacement_mother_as_member(replacement_mother_exist.id) self.state = 'waiting_approve' def action_first_accepted(self): @@ -1853,111 +1863,11 @@ class GrantBenefitProfile(models.Model): else: name = name return name - def add_mother_as_member(self): - for rec in self: - mother_name = rec.get_mother_name() - val = { - 'name': mother_name, - 'mother_first_name': rec.mother_name, - 'mother_second_name': rec.mother_second_name, - 'mother_third_name': rec.mother_third_name, - 'mother_family_name': rec.mother_family_name, - 'member_id_number': rec.mother_id_number, - 'is_mother':True, - 'birth_date': rec.mother_birth_date, - 'gender': 'female', - 'relationn': self.env['relation.settings'].search([('relation_type','=','mother')]).id, - 'mother_marital_conf': rec.mother_marital_conf.id, - 'mother_location_conf': rec.mother_location_conf.id, - 'age': rec.mother_age, - 'is_work': rec.is_mother_work, - 'member_income': rec.mother_income, - 'education_status': rec.education_status, - 'member_education_status_ids': [(5, 0)] + [(4, mother_education_id.id) for mother_education_id in rec.mother_education_status_ids], - 'case_study': rec.case_study, - 'education_entity': rec.education_entity, - 'last_education_entity': rec.last_education_entity, - 'entities': rec.entities.id, - 'last_entities': rec.last_entities.id, - 'education_levels': rec.education_levels.id, - 'last_education_levels': rec.last_education_levels.id, - 'specialization_ids': rec.specialization_ids.id, - 'last_specialization_ids': rec.last_specialization_ids.id, - 'classroom': rec.classroom.id, - 'last_classroom': rec.last_classroom.id, - 'degree': rec.degree.id, - 'last_degree': rec.last_degree.id, - 'percentage': rec.percentage, - 'last_percentage': rec.last_percentage, - 'weak_study': rec.weak_study.ids, - 'member_status': rec.mother_status, - 'education_start_date':rec.education_start_date, - 'education_end_date':rec.education_end_date, - 'educational_certificate':rec.educational_certificate, - 'last_education_start_date': rec.last_education_start_date, - 'last_education_end_date': rec.last_education_end_date, - 'last_educational_certificate': rec.last_educational_certificate, - 'benefit_id': rec.id, - } - mother_family_member_id = self.env['family.member'].create(val) - rec.write({'mother_family_member_id': mother_family_member_id.id}) - for r in rec.mother_diseases_attachment_ids: - r.write({'member_id': mother_family_member_id.id}) - for r in rec.mother_disabilities_attachment_ids: - r.write({'member_id': mother_family_member_id.id}) - def add_replacement_mother_as_member(self): - for rec in self: - mother_name = rec.get_replacement_mother_name() - val = { - 'name': mother_name, - 'mother_first_name': rec.replacement_mother_name, - 'mother_second_name': rec.replacement_mother_second_name, - 'mother_third_name': rec.replacement_mother_third_name, - 'mother_family_name': rec.replacement_mother_family_name, - 'member_id_number': rec.replacement_mother_id_number, - 'is_mother':True, - 'birth_date': rec.replacement_mother_birth_date, - 'gender': 'female', - 'relationn': rec.replacement_mother_relation.id, - 'mother_marital_conf': rec.replacement_mother_marital_conf.id, - 'mother_location_conf': rec.replacement_mother_location_conf.id, - 'age': rec.replacement_mother_age, - 'is_work': rec.replacement_is_mother_work, - 'member_income': rec.replacement_mother_income, - 'education_status': rec.replacement_education_status, - 'case_study': rec.replacement_case_study, - 'education_entity': rec.replacement_education_entity, - 'member_education_status_ids': [(5, 0)] + [(4, replacement_education_id.id) for replacement_education_id in rec.replacement_education_status_ids], - 'last_education_entity': rec.replacement_last_education_entity, - 'entities': rec.replacement_entities.id, - 'last_entities': rec.replacement_last_entities.id, - 'education_levels': rec.replacement_education_levels.id, - 'last_education_levels': rec.replacement_last_education_levels.id, - 'specialization_ids': rec.replacement_specialization_ids.id, - 'last_specialization_ids': rec.replacement_last_specialization_ids.id, - 'classroom': rec.replacement_classroom.id, - 'last_classroom': rec.replacement_last_classroom.id, - 'degree': rec.replacement_degree.id, - 'last_degree': rec.replacement_last_degree.id, - 'percentage': rec.replacement_percentage, - 'weak_study': rec.replacement_weak_study.ids, - 'member_status': rec.replacement_mother_status, - 'education_start_date': rec.replacement_education_start_date, - 'education_end_date': rec.replacement_education_end_date, - 'educational_certificate': rec.replacement_educational_certificate, - 'last_education_start_date': rec.replacement_last_education_start_date, - 'last_education_end_date': rec.replacement_last_education_end_date, - 'last_educational_certificate': rec.replacement_last_educational_certificate, - } - replacement_mother_family_member_id = self.env['family.member'].create(val) - rec.write({'replacement_mother_family_member_id': replacement_mother_family_member_id.id}) - for r in rec.replacement_mother_diseases_attachment_ids: - r.write({'member_id': replacement_mother_family_member_id.id}) - for r in rec.replacement_mother_disabilities_attachment_ids: - r.write({'member_id': replacement_mother_family_member_id.id}) + def add_or_replace_mother_as_member(self): + FamilyMember = self.env['family.member'] + Relation = self.env['relation.settings'].search([('relation_type', '=', 'mother')], limit=1) - def replace_mother_as_member(self, id): for rec in self: mother_name = rec.get_mother_name() val = { @@ -1970,47 +1880,31 @@ class GrantBenefitProfile(models.Model): 'is_mother': True, 'birth_date': rec.mother_birth_date, 'gender': 'female', - 'relationn': self.env['relation.settings'].search([('relation_type','=','mother')]).id, + 'relationn': Relation.id, 'mother_marital_conf': rec.mother_marital_conf.id, 'mother_location_conf': rec.mother_location_conf.id, 'age': rec.mother_age, 'is_work': rec.is_mother_work, 'member_income': rec.mother_income, 'education_status': rec.education_status, - 'member_education_status_ids': [(5, 0)] + [(4, mother_education_id.id) for mother_education_id in rec.mother_education_status_ids], - 'case_study': rec.case_study, - 'education_entity': rec.education_entity, - 'last_education_entity': rec.last_education_entity, - 'entities': rec.entities.id, - 'last_entities': rec.last_entities.id, - 'education_levels': rec.education_levels.id, - 'last_education_levels': rec.last_education_levels.id, - 'specialization_ids': rec.specialization_ids.id, - 'last_specialization_ids': rec.last_specialization_ids.id, - 'classroom': rec.classroom.id, - 'last_classroom': rec.last_classroom.id, - 'degree': rec.degree.id, - 'last_degree': rec.last_degree.id, - 'percentage': rec.percentage, - 'last_percentage': rec.last_percentage, - 'weak_study': rec.weak_study.ids, - 'member_status': rec.mother_status, - 'education_start_date': rec.education_start_date, - 'education_end_date': rec.education_end_date, - 'educational_certificate': rec.educational_certificate, - 'last_education_start_date': rec.last_education_start_date, - 'last_education_end_date': rec.last_education_end_date, - 'last_educational_certificate': rec.last_educational_certificate, + #'member_status': rec.mother_status, + 'member_education_status_ids': [(5, 0)] + [(4, edu.id) for edu in rec.mother_education_status_ids], + 'salary_certificate': [(6, 0, rec.mother_salary_certificate.ids)], } - mother_family_member_id = rec.mother_family_member_id - if mother_family_member_id: - mother_family_member_id.write(val) - for r in rec.mother_diseases_attachment_ids: - r.write({'member_id': mother_family_member_id.id}) - for r in rec.mother_disabilities_attachment_ids: - r.write({'member_id': mother_family_member_id.id}) - def replace_replacement_mother_as_member(self, id): + mother_family_member = rec.mother_family_member_id + if mother_family_member: + mother_family_member.write(val) + else: + val['benefit_id'] = rec.id + mother_family_member = FamilyMember.create(val) + rec.write({'mother_family_member_id': mother_family_member.id}) + rec.mother_diseases_attachment_ids.write({'member_id': mother_family_member.id}) + rec.mother_disabilities_attachment_ids.write({'member_id': mother_family_member.id}) + + def add_or_replace_replacement_mother_as_member(self): + FamilyMember = self.env['family.member'] + for rec in self: mother_name = rec.get_replacement_mother_name() val = { @@ -2020,7 +1914,7 @@ class GrantBenefitProfile(models.Model): 'mother_third_name': rec.replacement_mother_third_name, 'mother_family_name': rec.replacement_mother_family_name, 'member_id_number': rec.replacement_mother_id_number, - 'is_mother': True, + 'is_mother': False, 'birth_date': rec.replacement_mother_birth_date, 'gender': 'female', 'relationn': rec.replacement_mother_relation.id, @@ -2030,38 +1924,21 @@ class GrantBenefitProfile(models.Model): 'is_work': rec.replacement_is_mother_work, 'member_income': rec.replacement_mother_income, 'education_status': rec.replacement_education_status, - 'member_education_status_ids': [(5, 0)] + [(4, replacement_education_id.id) for replacement_education_id in rec.replacement_education_status_ids], - 'case_study': rec.replacement_case_study, - 'education_entity': rec.replacement_education_entity, - 'last_education_entity': rec.replacement_last_education_entity, - 'entities': rec.replacement_entities.id, - 'last_entities': rec.replacement_last_entities.id, - 'education_levels': rec.replacement_education_levels.id, - 'last_education_levels': rec.replacement_last_education_levels.id, - 'specialization_ids': rec.replacement_specialization_ids.id, - 'last_specialization_ids': rec.replacement_last_specialization_ids.id, - 'classroom': rec.replacement_classroom.id, - 'last_classroom': rec.replacement_last_classroom.id, - 'degree': rec.replacement_degree.id, - 'last_degree': rec.replacement_last_degree.id, - 'percentage': rec.replacement_percentage, - 'last_percentage': rec.replacement_last_percentage, - 'weak_study': rec.replacement_weak_study.ids, - 'member_status': rec.replacement_mother_status, - 'education_start_date': rec.replacement_education_start_date, - 'education_end_date': rec.replacement_education_end_date, - 'educational_certificate': rec.replacement_educational_certificate, - 'last_education_start_date': rec.replacement_last_education_start_date, - 'last_education_end_date': rec.replacement_last_education_end_date, - 'last_educational_certificate': rec.replacement_last_educational_certificate, + #'member_status': rec.replacement_mother_status, + 'member_education_status_ids': [(5, 0)] + [(4, edu.id) for edu in rec.replacement_education_status_ids], + 'salary_certificate': [(6, 0, rec.replacement_mother_salary_certificate.ids)], } - replacement_mother_family_member_id = rec.replacement_mother_family_member_id - if replacement_mother_family_member_id: - replacement_mother_family_member_id.write(val) - for r in rec.replacement_mother_diseases_attachment_ids: - r.write({'member_id': replacement_mother_family_member_id.id}) - for r in rec.replacement_mother_disabilities_attachment_ids: - r.write({'member_id': replacement_mother_family_member_id.id}) + + if rec.replacement_mother_family_member_id: + rec.replacement_mother_family_member_id.write(val) + replacement_member = rec.replacement_mother_family_member_id + else: + val['benefit_id'] = rec.id + replacement_member = FamilyMember.create(val) + rec.write({'replacement_mother_family_member_id': replacement_member.id}) + + rec.replacement_mother_diseases_attachment_ids.write({'member_id': replacement_member.id}) + rec.replacement_mother_disabilities_attachment_ids.write({'member_id': replacement_member.id}) def get_members_count(self): for ben in self: diff --git a/odex25_ensan/odex_benefit/models/benefit_config.py b/odex25_ensan/odex_benefit/models/benefit_config.py index a0b35d37f..a1981f99d 100644 --- a/odex25_ensan/odex_benefit/models/benefit_config.py +++ b/odex25_ensan/odex_benefit/models/benefit_config.py @@ -659,11 +659,12 @@ class ResDistricts(models.Model): class VisitsSettings(models.Model): _name = 'visits.types' - name = fields.Char(string="Name") + name = fields.Char(string="Name",required=True) creation_method = fields.Selection( [('manual', 'Manual'),('automatic', 'Automatic')], string="Creation Method", default='manual', + required=True, help="Whether the visit is entered manually or created automatically" ) recurrence_interval = fields.Integer( diff --git a/odex25_ensan/odex_benefit/models/education_status.py b/odex25_ensan/odex_benefit/models/education_status.py index 75c9a82ee..f9eff22fe 100644 --- a/odex25_ensan/odex_benefit/models/education_status.py +++ b/odex25_ensan/odex_benefit/models/education_status.py @@ -76,7 +76,7 @@ class EducationStatus(models.Model): ) def _compute_education_status(self): for record in self: - record.field = record.mother_grant_benefit_id.education_status or\ + record.education_status = record.mother_grant_benefit_id.education_status or\ record.replacement_grant_benefit_id.replacement_education_status or\ record.family_member_id.education_status diff --git a/odex25_ensan/odex_benefit/models/visit.py b/odex25_ensan/odex_benefit/models/visit.py index ac54b1592..6ac61e3ad 100644 --- a/odex25_ensan/odex_benefit/models/visit.py +++ b/odex25_ensan/odex_benefit/models/visit.py @@ -36,7 +36,10 @@ class Visit(models.Model): ], string='Visit Objective') visit_types = fields.Many2one( 'visits.types', - string='Visits Types') + string='Visits Types', + ondelete="restrict" + + ) evaluation = fields.Selection( [('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6')], string='Evaluation') @@ -44,6 +47,7 @@ class Visit(models.Model): ('draft', 'Draft'), ('contact', 'Contact'), ('schedule_a_visit', 'Schedule a visit'), + ('pending', 'Pending'), ('done', 'Done'), ('close', 'Close'), ('cancel', 'Cancel'), @@ -59,6 +63,43 @@ class Visit(models.Model): response_count = fields.Integer(compute="_compute_response_count", store=True, string="Responses Count", copy=False) survey_url = fields.Char(string="Survey URL") + + + # added by eslam + + # def action_postpone(self): + # """Open wizard to postpone""" + # return { + # 'name': _('Postpone Visit'), + # 'type': 'ir.actions.act_window', + # 'res_model': 'visit.postpone.wizard', + # 'view_mode': 'form', + # 'target': 'new', + # 'context': {'default_visit_id': self.id}, + # } + # + # def action_reschedule(self): + # for rec in self: + # rec.state = "contact" + # + # def action_create_new_visit(self): + # for rec in self: + # new_visit = self.create({ + # 'creation_type': rec.creation_type, + # 'visit_types': rec.visit_types.id, + # 'benefit_id': rec.benefit_id.id, + # 'researcher_ids': [(6, 0, rec.researcher_ids.ids)], + # 'visit_date': fields.Datetime.now(), + # 'state': 'draft', + # }) + # return { + # 'type': 'ir.actions.act_window', + # 'res_model': 'visit.location', + # 'view_mode': 'form', + # 'res_id': new_visit.id, + # } + # added by eslam + @api.depends('response_id') def _compute_response_count(self): for rec in self: @@ -352,3 +393,24 @@ class MemberEducationStatus(models.Model): _name = 'member.education.status' name = fields.Char() + +class VisitPostponeWizard(models.TransientModel): + _name = "visit.postpone.wizard" + _description = "Postpone Visit Wizard" + + visit_id = fields.Many2one("visit.location", string="Visit", required=True, readonly=True) + reason = fields.Text(string="Reason", required=True) + notes = fields.Text(string="Notes") + + def action_confirm_postpone(self): + """Confirm postpone and set state to pending""" + for wizard in self: + if not wizard.reason: + raise ValidationError(_("You must provide a reason to postpone.")) + visit = wizard.visit_id + visit.write({ + "state": "pending", + "reason": wizard.reason, + "message": wizard.notes, + }) + return {"type": "ir.actions.act_window_close"} diff --git a/odex25_ensan/odex_benefit/views/benefit_view.xml b/odex25_ensan/odex_benefit/views/benefit_view.xml index 772c3f0c1..a146de264 100644 --- a/odex25_ensan/odex_benefit/views/benefit_view.xml +++ b/odex25_ensan/odex_benefit/views/benefit_view.xml @@ -428,14 +428,14 @@ @@ -511,11 +511,14 @@ readonly="1"/> + + attrs="{'invisible':[('is_mother_work','=',False)],'required':[('is_mother_work','=',True)],'readonly':[('state','not in',['draft','new','complete_info'])]}"/> @@ -664,10 +667,13 @@ readonly="1"/> + + attrs="{'invisible':[('replacement_is_mother_work','=',False)],'required':[('replacement_is_mother_work','=',True),('add_replacement_mother','=',True)],'readonly':[('state','not in',['draft','new','complete_info'])]}"/> diff --git a/odex25_ensan/odex_benefit/views/visit.xml b/odex25_ensan/odex_benefit/views/visit.xml index a46b98bd2..dabb38094 100644 --- a/odex25_ensan/odex_benefit/views/visit.xml +++ b/odex25_ensan/odex_benefit/views/visit.xml @@ -84,6 +84,22 @@ states="draft"/>