From a5228c3ee8d05e25a57ecdc5022c09ed11053241 Mon Sep 17 00:00:00 2001 From: younes Date: Mon, 15 Sep 2025 13:42:43 +0100 Subject: [PATCH] IMP benefit --- .../empowerment.png => description/icon.png} | Bin .../views/service_settings.xml | 2 +- .../icon.png} | Bin .../odex25_program_activity/views/program.xml | 2 +- odex25_ensan/odex_benefit/models/visit.py | 103 +++++++++++------- 5 files changed, 67 insertions(+), 40 deletions(-) rename odex25_ensan/odex25_empowermentmanagement/static/{src/img/empowerment.png => description/icon.png} (100%) rename odex25_ensan/odex25_program_activity/static/{src/img/program_activity.png => description/icon.png} (100%) diff --git a/odex25_ensan/odex25_empowermentmanagement/static/src/img/empowerment.png b/odex25_ensan/odex25_empowermentmanagement/static/description/icon.png similarity index 100% rename from odex25_ensan/odex25_empowermentmanagement/static/src/img/empowerment.png rename to odex25_ensan/odex25_empowermentmanagement/static/description/icon.png diff --git a/odex25_ensan/odex25_empowermentmanagement/views/service_settings.xml b/odex25_ensan/odex25_empowermentmanagement/views/service_settings.xml index b5ad09977..1a55683fa 100644 --- a/odex25_ensan/odex25_empowermentmanagement/views/service_settings.xml +++ b/odex25_ensan/odex25_empowermentmanagement/views/service_settings.xml @@ -194,7 +194,7 @@ - + diff --git a/odex25_ensan/odex25_program_activity/static/src/img/program_activity.png b/odex25_ensan/odex25_program_activity/static/description/icon.png similarity index 100% rename from odex25_ensan/odex25_program_activity/static/src/img/program_activity.png rename to odex25_ensan/odex25_program_activity/static/description/icon.png diff --git a/odex25_ensan/odex25_program_activity/views/program.xml b/odex25_ensan/odex25_program_activity/views/program.xml index dbcef4060..7cfcf52a2 100644 --- a/odex25_ensan/odex25_program_activity/views/program.xml +++ b/odex25_ensan/odex25_program_activity/views/program.xml @@ -648,7 +648,7 @@ - + diff --git a/odex25_ensan/odex_benefit/models/visit.py b/odex25_ensan/odex_benefit/models/visit.py index 488d01621..288e0a0e0 100644 --- a/odex25_ensan/odex_benefit/models/visit.py +++ b/odex25_ensan/odex_benefit/models/visit.py @@ -1,9 +1,10 @@ -from odoo import fields, models,api,_ +from odoo import fields, models, api, _ import math, random from odoo.exceptions import UserError, ValidationError from datetime import timedelta import werkzeug + class Visit(models.Model): _name = 'visit.location' _inherit = ['mail.thread', 'mail.activity.mixin'] @@ -11,7 +12,8 @@ class Visit(models.Model): @api.model def _default_researcher_team(self): - researcher_team = self.env['committees.line'].search([('employee_id','in',[self.env.user.employee_id.id])],limit=1) + researcher_team = self.env['committees.line'].search([('employee_id', 'in', [self.env.user.employee_id.id])], + limit=1) return researcher_team.id benefit_type = fields.Selection([ @@ -19,19 +21,19 @@ class Visit(models.Model): ('family', 'Family'), ], string='Type', default="benefit") benefit_id = fields.Many2one( - 'grant.benefit',string='Family file',domain="[('state', '=', 'second_approve')]") + 'grant.benefit', string='Family file', domain="[('state', '=', 'second_approve')]") benefit_name = fields.Char(related="benefit_id.name") - benefit_code= fields.Char(related="benefit_id.code") - sms_phone = fields.Char(string="Contact Phone",related="benefit_id.sms_phone") - researcher_team = fields.Many2one("committees.line", string="Researcher Team",related="benefit_id.researcher_id") - researcher_ids = fields.Many2many("hr.employee", string="Researcher",compute="get_researcher_ids",readonly=False) + benefit_code = fields.Char(related="benefit_id.code") + sms_phone = fields.Char(string="Contact Phone", related="benefit_id.sms_phone") + researcher_team = fields.Many2one("committees.line", string="Researcher Team", related="benefit_id.researcher_id") + researcher_ids = fields.Many2many("hr.employee", string="Researcher", compute="get_researcher_ids", readonly=False) visit_date = fields.Datetime(string='Visit Date', tracking=True) description = fields.Char(string='Description') message = fields.Text(string='Message') visit_objective = fields.Selection([ ('inform_visit', 'Inform Visit'), ('objective_visit', 'Objective Visit'), - ], string='Visit Objective') + ], string='Visit Objective') visit_types = fields.Many2one( 'visits.types', string='Visits Types') @@ -45,7 +47,7 @@ class Visit(models.Model): ('done', 'Done'), ('close', 'Close'), ('cancel', 'Cancel'), - ], string='State',default="draft", tracking=True, group_expand='_expand_states') + ], string='State', default="draft", tracking=True, group_expand='_expand_states') color = fields.Integer('Color Index', default=0) family_id = fields.Many2one('benefit.family') reason = fields.Text(string='Reason/Justification') @@ -54,7 +56,7 @@ class Visit(models.Model): otp_code = fields.Char(string="OTP Code", readonly=True, copy=False) otp_generated_at = fields.Datetime(string="OTP Generated At", readonly=True, copy=False) response_id = fields.Many2one('survey.user_input', string="Survey Responses", ondelete='restrict', copy=False) - response_count = fields.Integer(compute="_compute_response_count",store=True, string="Responses Count", copy=False) + response_count = fields.Integer(compute="_compute_response_count", store=True, string="Responses Count", copy=False) survey_url = fields.Char(string="Survey URL") @api.depends('response_id') @@ -81,6 +83,7 @@ class Visit(models.Model): if order.state not in ['draft']: raise UserError(_('You cannot delete this record')) return super(Visit, self).unlink() + @api.model def create(self, vals): # If the 'name' field is 'New', generate a new sequence number @@ -104,6 +107,7 @@ class Visit(models.Model): else: email_ids = str(rec.work_email) return email_ids + def action_draft(self): self.state = 'draft' @@ -116,7 +120,7 @@ class Visit(models.Model): template.with_context(lang=self.env.user.lang).send_mail(self.id, force_send=True, raise_exception=False) elif self.benefit_id.contact_type == 'sms': - self.benefit_id.partner_id.send_sms_notification(self.message, self.benefit_id.sms_phone) + self.benefit_id.partner_id.send_sms_notification(self.message, self.benefit_id.sms_phone) def action_schedule_a_visit(self): self.state = 'schedule_a_visit' @@ -136,7 +140,6 @@ class Visit(models.Model): 'context': context, } - def action_done(self): if self.visit_types.otp_verification: otp_validity = self.visit_types.otp_validity_minutes or 5 @@ -152,31 +155,44 @@ class Visit(models.Model): if self.benefit_id.contact_type == 'email': if not self.benefit_id.email: - raise UserError(_("The family profile has no email address. OTP cannot be sent. Please add an email first.")) + raise UserError( + _("The family profile has no email address. OTP cannot be sent. Please add an email first.")) template = self.env.ref('odex_benefit.visit_location_otp_email_template', False) if not template: raise UserError( _("The email template 'Visit Location OTP Email' is missing. Please contact your administrator.")) template.write({'email_to': self.benefit_id.email, - 'email_cc': self.env.user.company_id.hr_email or self.env.user.company_id.email,}) - email_values = {"email_from": self.env.user.company_id.hr_email or self.env.user.company_id.email,'res_id': None} - template.with_context({'lang':self.env.user.lang,'tracking_disable':True,'mail_create_nolog': True,'mail_notrack': True,}).send_mail(self.id, force_send=True, - raise_exception=False,email_values=email_values) + 'email_cc': self.env.user.company_id.hr_email or self.env.user.company_id.email, }) + email_values = {"email_from": self.env.user.company_id.hr_email or self.env.user.company_id.email, + 'res_id': None} + template.with_context({'lang': self.env.user.lang}).send_mail(self.id, force_send=True, + raise_exception=False, email_values=email_values) elif self.benefit_id.contact_type == 'sms': if not self.benefit_id.sms_phone: - raise UserError(_("The family profile has no mobile number. Please add a valid phone number before sending OTP.")) - bot = self.env.ref('base.partner_root').id + raise UserError( + _("The family profile has no mobile number. Please add a valid phone number before sending OTP.")) sms_template_id = self.env.ref('odex_benefit.visit_location_otp_sms_template') if not sms_template_id: - raise UserError(_("The SMS template 'Visit Location OTP' is missing. Please contact your administrator.")) - self.with_context(tracking_disable=True)._message_sms_with_template( - template=sms_template_id, - put_in_queue=False, - partner_ids=self.benefit_id.partner_id.ids, - author_id=bot - ) + raise UserError( + _("The SMS template 'Visit Location OTP' is missing. Please contact your administrator.")) + + sms_body = sms_template_id._render_template(sms_template_id.body,self._name,[self.id],post_process=True)[self.id] + sms_values = { + 'number': self.benefit_id.sms_phone, + 'body': sms_body, + 'partner_id': self.benefit_id.partner_id.id, + 'state': 'outgoing', + } + self.env['sms.sms'].sudo().create(sms_values).send() # don't delete this code + # bot = self.env.ref('base.partner_root').id + # self.with_context(tracking_disable=True)._message_sms_with_template( + # template=sms_template_id, + # put_in_queue=False, + # partner_ids=self.benefit_id.partner_id.ids, + # author_id=bot + # ) # message = _("Your verification code is %s. It is valid for %s minutes.") % ( # self.otp_code, # self.visit_types.otp_validity_minutes or 5 @@ -233,7 +249,6 @@ class Visit(models.Model): else: response = self.response_id - self.survey_url = '%s%s?%s' % ( survey.get_base_url(), survey.get_start_url(), @@ -247,12 +262,11 @@ class Visit(models.Model): template = self.env.ref('odex_benefit.visit_location_survey_email_template', False) if not template: raise UserError(_("The email template 'Visit Location Survey Email' is missing.")) - email_values = {"email_from": self.env.user.company_id.hr_email or self.env.user.company_id.email} + email_values = {"email_from": self.env.user.company_id.hr_email or self.env.user.company_id.email,"res_id": None} template.write({'email_to': self.benefit_id.email, 'email_cc': self.env.user.company_id.hr_email or self.env.user.company_id.email, }) template.with_context( lang=self.env.user.lang, - tracking_disable=True, survey_url=self.survey_url ).send_mail(self.id, force_send=True, raise_exception=False, email_values=email_values) elif self.benefit_id.contact_type == 'sms': @@ -261,12 +275,21 @@ class Visit(models.Model): sms_template = self.env.ref('odex_benefit.visit_location_survey_sms_template', False) if not sms_template: raise UserError(_("The SMS template 'Visit Location Survey' is missing.")) - self.with_context(tracking_disable=True,survey_url=self.survey_url)._message_sms_with_template( - template=sms_template, - put_in_queue=False, - partner_ids=self.benefit_id.partner_id.ids, - author_id=self.env.ref('base.partner_root').id - ) + + sms_body = sms_template._render_template(sms_template.body, self._name, [self.id], post_process=True)[self.id] + sms_values = { + 'number': self.benefit_id.sms_phone, + 'body': sms_body, + 'partner_id': self.benefit_id.partner_id.id, + 'state': 'outgoing', + } + self.env['sms.sms'].sudo().create(sms_values).send() + # self.with_context(tracking_disable=True, survey_url=self.survey_url)._message_sms_with_template( + # template=sms_template, + # put_in_queue=False, + # partner_ids=self.benefit_id.partner_id.ids, + # author_id=self.env.ref('base.partner_root').id + # ) def action_close(self): self.ensure_one() @@ -281,6 +304,7 @@ class Visit(models.Model): def get_researcher_ids(self): for rec in self: rec.researcher_ids = rec.researcher_team.employee_id + def send_visit_date_email(self): template = self.env.ref('odex_benefit.visit_date_email', False) if not template: @@ -302,7 +326,8 @@ class Visit(models.Model): def geo_localize(self): for visit in self: if visit.benefit_id: - url = "http://maps.google.com/maps/search/?api=1&query=%s,%s" % (visit.benefit_id.lat,visit.benefit_id.lon), + url = "http://maps.google.com/maps/search/?api=1&query=%s,%s" % ( + visit.benefit_id.lat, visit.benefit_id.lon), return { 'type': 'ir.actions.act_url', 'target': 'new', @@ -312,10 +337,12 @@ class Visit(models.Model): def get_url_local(self): for visit in self: if visit.benefit_id: - url = "http://maps.google.com/maps/search/?api=1&query=%s,%s" % (visit.benefit_id.lat,visit.benefit_id.lon) + url = "http://maps.google.com/maps/search/?api=1&query=%s,%s" % ( + visit.benefit_id.lat, visit.benefit_id.lon) return url + class MemberEducationStatus(models.Model): _name = 'member.education.status' - name = fields.Char() \ No newline at end of file + name = fields.Char()