mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
[IMP] rma: auto send confirmation email
This commit is contained in:
committed by
Nikolaus Weingartmair
parent
aa7ff2ea45
commit
4043b37ee2
@@ -5,6 +5,7 @@ from . import rma
|
||||
from . import rma_operation
|
||||
from . import rma_team
|
||||
from . import res_company
|
||||
from . import res_config_settings
|
||||
from . import res_partner
|
||||
from . import res_users
|
||||
from . import stock_move
|
||||
|
||||
@@ -1,12 +1,31 @@
|
||||
# Copyright 2020 Tecnativa - Ernesto Tejeda
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import _, api, models
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
|
||||
class Company(models.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
def _default_rma_mail_confirmation_template(self):
|
||||
try:
|
||||
return self.env.ref("rma.mail_template_rma_notification").id
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
send_rma_confirmation = fields.Boolean(
|
||||
string="Send RMA Confirmation",
|
||||
help="When the delivery is confirmed, send a confirmation email "
|
||||
"to the customer.",
|
||||
)
|
||||
rma_mail_confirmation_template_id = fields.Many2one(
|
||||
comodel_name="mail.template",
|
||||
string="Email Template confirmation for RMA",
|
||||
domain="[('model', '=', 'rma')]",
|
||||
default=_default_rma_mail_confirmation_template,
|
||||
help="Email sent to the customer once the RMA is confirmed.",
|
||||
)
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
company = super(Company, self).create(vals)
|
||||
|
||||
14
rma/models/res_config_settings.py
Normal file
14
rma/models/res_config_settings.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Copyright 2021 Tecnativa - David Vidal
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = "res.config.settings"
|
||||
|
||||
send_rma_confirmation = fields.Boolean(
|
||||
related="company_id.send_rma_confirmation", readonly=False,
|
||||
)
|
||||
rma_mail_confirmation_template_id = fields.Many2one(
|
||||
related="company_id.rma_mail_confirmation_template_id", readonly=False,
|
||||
)
|
||||
@@ -498,10 +498,19 @@ class Rma(models.Model):
|
||||
)
|
||||
return super().unlink()
|
||||
|
||||
def _send_confirmation_email(self):
|
||||
"""Auto send notifications"""
|
||||
for rma in self.filtered(lambda p: p.company_id.send_rma_confirmation):
|
||||
rma_template_id = rma.company_id.rma_mail_confirmation_template_id.id
|
||||
rma.with_context(
|
||||
force_send=True, mark_rma_as_sent=True
|
||||
).message_post_with_template(rma_template_id)
|
||||
|
||||
# Action methods
|
||||
def action_rma_send(self):
|
||||
self.ensure_one()
|
||||
template = self.env.ref("rma.mail_template_rma_notification", False)
|
||||
template = self.company_id.rma_mail_confirmation_template_id or template
|
||||
form = self.env.ref("mail.email_compose_message_wizard_form", False)
|
||||
ctx = {
|
||||
"default_model": "rma",
|
||||
@@ -536,6 +545,7 @@ class Rma(models.Model):
|
||||
self.write({"reception_move_id": reception_move.id, "state": "confirmed"})
|
||||
if self.partner_id not in self.message_partner_ids:
|
||||
self.message_subscribe([self.partner_id.id])
|
||||
self._send_confirmation_email()
|
||||
|
||||
def action_refund(self):
|
||||
"""Invoked when 'Refund' button in rma form view is clicked
|
||||
|
||||
Reference in New Issue
Block a user