Skip to content

Commit

Permalink
[IMP] mail_no_reply: mail compose onchange and view
Browse files Browse the repository at this point in the history
  • Loading branch information
corredato committed Oct 1, 2024
1 parent caa1c3e commit 7868d4e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions mail_no_reply/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
],
"data": [
"views/mail_compose_message.xml",
"views/mail_template.xml",
"views/res_company.xml",
"views/res_config.xml",
],
Expand Down
1 change: 1 addition & 0 deletions mail_no_reply/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import res_company
from . import mail_template
from . import mail_compose_message
from . import res_config_settings
15 changes: 15 additions & 0 deletions mail_no_reply/models/mail_compose_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from odoo import api, fields, models


class MailComposeMessage(models.TransientModel):
_inherit = "mail.compose.message"

active_no_reply = fields.Boolean(string="Use no-reply email")

@api.onchange("active_no_reply")
def _onchange_active_no_reply(self):
template_id = self.env.context.get("default_template_id")
if template_id:
mail_template = self.env["mail.template"].browse(template_id)
if mail_template:
mail_template.active_no_reply = self.active_no_reply
5 changes: 1 addition & 4 deletions mail_no_reply/models/mail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ class MailTemplate(models.Model):

@api.onchange("active_no_reply")
def _onchange_active_no_reply(self):
standard_email_from = (
"{{ (object.company_id.email_formatted or user.email_formatted) }}"
)
if self.active_no_reply and self.env.user.company_id.email_no_reply:
self.email_from = self.env.user.company_id.email_no_reply
self.reply_to = self.env.user.company_id.email_no_reply
if not self.active_no_reply:
self.email_from = standard_email_from
self.email_from = False
self.reply_to = False
8 changes: 4 additions & 4 deletions mail_no_reply/views/mail_compose_message.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<odoo>
<record id="mail_no_reply" model="ir.ui.view">
<record id="mail_no_reply_compose_message" model="ir.ui.view">
<field name="name">mail compose message form mail no reply</field>
<field name="model">mail.template</field>
<field name="inherit_id" ref="mail.email_template_form" />
<field name="model">mail.compose.message</field>
<field name="inherit_id" ref="mail.email_compose_message_wizard_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='email_from']" position="after">
<xpath expr="//field[@name='subject']" position="after">
<field name="active_no_reply" widget="boolean_toggle" />
</xpath>
</field>
Expand Down
12 changes: 12 additions & 0 deletions mail_no_reply/views/mail_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<odoo>
<record id="mail_no_reply" model="ir.ui.view">
<field name="name">mail template form mail no reply</field>
<field name="model">mail.template</field>
<field name="inherit_id" ref="mail.email_template_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='email_from']" position="after">
<field name="active_no_reply" widget="boolean_toggle" />
</xpath>
</field>
</record>
</odoo>

0 comments on commit 7868d4e

Please sign in to comment.