[IMP] rma: notify reception to customer

Now we can configure if an automatic notification should be sent when we
receive the goods from an RMA in our warehouse

If we've got `rma_sale` or `website_rma` we can also configure draft
notifications so when the customer places an RMA from the portal the
receive an acknowledge email.

TT29595
This commit is contained in:
david
2021-05-19 14:49:54 +02:00
committed by Nikolaus Weingartmair
parent 1beb33e6f4
commit 5eb8e8443e
7 changed files with 265 additions and 11 deletions

View File

@@ -13,11 +13,32 @@ class Company(models.Model):
except ValueError:
return False
def _default_rma_mail_receipt_template(self):
try:
return self.env.ref("rma.mail_template_rma_receipt_notification").id
except ValueError:
return False
def _default_rma_mail_draft_template(self):
try:
return self.env.ref("rma.mail_template_rma_draft_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.",
)
send_rma_receipt_confirmation = fields.Boolean(
string="Send RMA Receipt Confirmation",
help="When the RMA receipt is confirmed, send a confirmation email "
"to the customer.",
)
send_rma_draft_confirmation = fields.Boolean(
string="Send RMA draft Confirmation",
help="When a customer places an RMA, send a notification with it",
)
rma_mail_confirmation_template_id = fields.Many2one(
comodel_name="mail.template",
string="Email Template confirmation for RMA",
@@ -25,6 +46,20 @@ class Company(models.Model):
default=_default_rma_mail_confirmation_template,
help="Email sent to the customer once the RMA is confirmed.",
)
rma_mail_receipt_confirmation_template_id = fields.Many2one(
comodel_name="mail.template",
string="Email Template receipt confirmation for RMA",
domain="[('model', '=', 'rma')]",
default=_default_rma_mail_receipt_template,
help="Email sent to the customer once the RMA products are received.",
)
rma_mail_draft_confirmation_template_id = fields.Many2one(
comodel_name="mail.template",
string="Email Template draft notification for RMA",
domain="[('model', '=', 'rma')]",
default=_default_rma_mail_draft_template,
help="Email sent to the customer when they place " "an RMA from the portal",
)
@api.model
def create(self, vals):

View File

@@ -14,3 +14,19 @@ class ResConfigSettings(models.TransientModel):
related="company_id.rma_mail_confirmation_template_id",
readonly=False,
)
send_rma_receipt_confirmation = fields.Boolean(
related="company_id.send_rma_receipt_confirmation",
readonly=False,
)
rma_mail_receipt_confirmation_template_id = fields.Many2one(
related="company_id.rma_mail_receipt_confirmation_template_id",
readonly=False,
)
send_rma_draft_confirmation = fields.Boolean(
related="company_id.send_rma_draft_confirmation",
readonly=False,
)
rma_mail_draft_confirmation_template_id = fields.Many2one(
related="company_id.rma_mail_draft_confirmation_template_id",
readonly=False,
)

View File

@@ -511,7 +511,13 @@ class Rma(models.Model):
# Assign a default team_id which will be the first in the sequence
if "team_id" not in vals:
vals["team_id"] = self.env["rma.team"].search([], limit=1).id
return super().create(vals_list)
rmas = super().create(vals_list)
# Send acknowledge when the RMA is created from the portal and the
# company has the proper setting active. This context is set by the
# `rma_sale` module.
if self.env.context.get("from_portal"):
rmas._send_draft_email()
return rmas
def copy(self, default=None):
team = super().copy(default)
@@ -529,6 +535,16 @@ class Rma(models.Model):
)
return super().unlink()
def _send_draft_email(self):
"""Send customer notifications they place the RMA from the portal"""
for rma in self.filtered("company_id.send_rma_draft_confirmation"):
rma_template_id = rma.company_id.rma_mail_draft_confirmation_template_id.id
rma.with_context(
force_send=True,
mark_rma_as_sent=True,
default_subtype_id=self.env.ref("rma.mt_rma_notification").id,
).message_post_with_template(rma_template_id)
def _send_confirmation_email(self):
"""Auto send notifications"""
for rma in self.filtered(lambda p: p.company_id.send_rma_confirmation):
@@ -539,6 +555,18 @@ class Rma(models.Model):
default_subtype_id=self.env.ref("rma.mt_rma_notification").id,
).message_post_with_template(rma_template_id)
def _send_receipt_confirmation_email(self):
"""Send customer notifications when the products are received"""
for rma in self.filtered("company_id.send_rma_receipt_confirmation"):
rma_template_id = (
rma.company_id.rma_mail_receipt_confirmation_template_id.id
)
rma.with_context(
force_send=True,
mark_rma_as_sent=True,
default_subtype_id=self.env.ref("rma.mt_rma_notification").id,
).message_post_with_template(rma_template_id)
# Action methods
def action_rma_send(self):
self.ensure_one()
@@ -1260,6 +1288,16 @@ class Rma(models.Model):
return "RMA Report - %s" % self.name
# Other business methods
def update_received_state_on_reception(self):
"""Invoked by:
[stock.move]._action_done
Here we can attach methods to trigger when the customer products
are received on the RMA location, such as automatic notifications
"""
self.write({"state": "received"})
self._send_receipt_confirmation_email()
def update_received_state(self):
"""Invoked by:
[stock.move].unlink

View File

@@ -75,7 +75,7 @@ class StockMove(models.Model):
.mapped("rma_receiver_ids")
.filtered(lambda r: r.state == "confirmed")
)
to_be_received.write({"state": "received"})
to_be_received.update_received_state_on_reception()
# Set RMAs as delivered
move_done.mapped("rma_id").update_replaced_state()
move_done.mapped("rma_id").update_returned_state()