[CLN] global : full pre-commit & ruff lint

This commit is contained in:
jscampucci
2025-09-15 12:58:03 +02:00
parent b63c4b5335
commit 174aabfbbb
71 changed files with 673 additions and 429 deletions

View File

@@ -1 +1 @@
from . import models
from . import models

View File

@@ -5,18 +5,15 @@
"version": "16.0.0.0.0",
"license": "AGPL-3",
"author": "Elabore",
"website": "https://www.elabore.coop",
'summary': 'Add manual send in event communication',
'description': """
"website": "https://github.com/elabore-coop/event-tools",
"summary": "Add manual send in event communication",
"description": """
Add manual send in event communication
----------------------------------------------------
""",
"category": "",
"depends": ["event"],
"data": [
'views/event_event_views.xml'
],
"data": ["views/event_event_views.xml"],
"installable": True,
}

View File

@@ -1 +1 @@
from . import event_mail
from . import event_mail

View File

@@ -1,54 +1,66 @@
from odoo import _, api, Command, fields, models
from lxml import etree, html
import logging
from odoo.exceptions import MissingError, ValidationError
from odoo import api, fields, models
from odoo.exceptions import MissingError
_logger = logging.getLogger(__name__)
class EventMail(models.Model):
_inherit = "event.mail"
notification_type = fields.Selection(selection_add=[('mail_manual', 'Mail (manual)')], ondelete={'mail_manual': 'set default'})
notification_type = fields.Selection(
selection_add=[("mail_manual", "Mail (manual)")],
ondelete={"mail_manual": "set default"},
)
def _selection_template_model_get_mapping(self):
return {**super(EventMail, self)._selection_template_model_get_mapping(), 'mail_manual': 'mail.template'}
return {
**super()._selection_template_model_get_mapping(),
"mail_manual": "mail.template",
}
@api.depends('event_id.date_begin', 'event_id.date_end', 'interval_type', 'interval_unit', 'interval_nbr','notification_type')
@api.depends(
"event_id.date_begin",
"event_id.date_end",
"interval_type",
"interval_unit",
"interval_nbr",
"notification_type",
)
def _compute_scheduled_date(self):
res = super(EventMail, self)._compute_scheduled_date()
res = super()._compute_scheduled_date()
for scheduler in self:
if scheduler.notification_type == 'mail_manual':
scheduler.scheduled_date = '2148-12-31'
scheduler.interval_type = 'after_sub'
if scheduler.notification_type == "mail_manual":
scheduler.scheduled_date = "2148-12-31"
scheduler.interval_type = "after_sub"
return res
def send(self):
def send(self):
self.execute()
return
class EventMailRegistration(models.Model):
_inherit = 'event.mail.registration'
_inherit = "event.mail.registration"
def execute(self):
"""Inherit execute to send mail from schedulers "mail_manual"
"""
res = super(EventMailRegistration, self).execute()
todo_manual = self.filtered(lambda reg_mail:
not reg_mail.mail_sent and
reg_mail.registration_id.state in ['open', 'done'] and
reg_mail.scheduler_id.notification_type == 'mail_manual'
Inherit execute to send mail from schedulers "mail_manual".
"""
res = super().execute()
todo_manual = self.filtered(
lambda reg_mail: not reg_mail.mail_sent
and reg_mail.registration_id.state in ["open", "done"]
and reg_mail.scheduler_id.notification_type == "mail_manual"
)
done = self.browse()
for reg_mail in todo_manual:
organizer = reg_mail.scheduler_id.event_id.organizer_id
company = self.env.company
author = self.env.ref('base.user_root').partner_id
author = self.env.ref("base.user_root").partner_id
if organizer.email:
author = organizer
elif company.email:
@@ -57,7 +69,7 @@ class EventMailRegistration(models.Model):
author = self.env.user.partner_id
email_values = {
'author_id': author.id,
"author_id": author.id,
}
template = None
try:
@@ -66,15 +78,17 @@ class EventMailRegistration(models.Model):
pass
if not template:
_logger.warning("Cannot process ticket %s, because Mail Scheduler %s has reference to non-existent template", reg_mail.registration_id, reg_mail.scheduler_id)
_logger.warning(
"Cannot process ticket %s, because Mail Scheduler %s has reference to non-existent template",
reg_mail.registration_id,
reg_mail.scheduler_id,
)
continue
if not template.email_from:
email_values['email_from'] = author.email_formatted
email_values["email_from"] = author.email_formatted
template.send_mail(reg_mail.registration_id.id, email_values=email_values)
done |= reg_mail
done.write({'mail_sent': True})
done.write({"mail_sent": True})
return res

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data>
<record model="ir.ui.view" id="view_event_form_event_mail_manual">
@@ -6,22 +6,41 @@
<field name="inherit_id" ref="event.view_event_form" />
<field name="model">event.event</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='event_mail_ids']/tree/field[@name='mail_state']" position="after">
<button
name="send"
type="object"
icon="fa-bullhorn"
attrs="{'invisible':[('notification_type','!=','mail_manual')]}"
confirm="Send mail to all attendees ?" />
<xpath
expr="//field[@name='event_mail_ids']/tree/field[@name='mail_state']"
position="after"
>
<button
name="send"
type="object"
icon="fa-bullhorn"
attrs="{'invisible':[('notification_type','!=','mail_manual')]}"
confirm="Send mail to all attendees ?"
/>
</xpath>
<xpath expr="//field[@name='event_mail_ids']/tree/field[@name='interval_nbr']" position="attributes">
<attribute name="attrs">{'readonly':['|',('interval_unit','=','now'),('notification_type','=','mail_manual')]}</attribute>
<xpath
expr="//field[@name='event_mail_ids']/tree/field[@name='interval_nbr']"
position="attributes"
>
<attribute
name="attrs"
>{'readonly':['|',('interval_unit','=','now'),('notification_type','=','mail_manual')]}</attribute>
</xpath>
<xpath expr="//field[@name='event_mail_ids']/tree/field[@name='interval_unit']" position="attributes">
<attribute name="attrs">{'readonly':[('notification_type','=','mail_manual')]}</attribute>
<xpath
expr="//field[@name='event_mail_ids']/tree/field[@name='interval_unit']"
position="attributes"
>
<attribute
name="attrs"
>{'readonly':[('notification_type','=','mail_manual')]}</attribute>
</xpath>
<xpath expr="//field[@name='event_mail_ids']/tree/field[@name='interval_type']" position="attributes">
<attribute name="attrs">{'readonly':[('notification_type','=','mail_manual')]}</attribute>
<xpath
expr="//field[@name='event_mail_ids']/tree/field[@name='interval_type']"
position="attributes"
>
<attribute
name="attrs"
>{'readonly':[('notification_type','=','mail_manual')]}</attribute>
</xpath>
</field>
</record>