mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
[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:
committed by
Nikolaus Weingartmair
parent
1beb33e6f4
commit
5eb8e8443e
@@ -8,7 +8,7 @@
|
||||
<field name="description">RMA in draft state</field>
|
||||
</record>
|
||||
<record id="mt_rma_notification" model="mail.message.subtype">
|
||||
<field name="name">RMA Notificatoin</field>
|
||||
<field name="name">RMA Notification</field>
|
||||
<field name="res_model">rma</field>
|
||||
<field name="default" eval="False" />
|
||||
<field name="description">RMA automatic customer notifications</field>
|
||||
@@ -54,6 +54,64 @@
|
||||
Here is the RMA <strong>${object.name}</strong> from ${object.company_id.name}.
|
||||
<br /><br />
|
||||
Do not hesitate to contact us if you have any question.
|
||||
</p>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
<!--RMA receipt confirmation email template -->
|
||||
<record id="mail_template_rma_receipt_notification" model="mail.template">
|
||||
<field name="name">RMA Receipt Notification</field>
|
||||
<field name="model_id" ref="model_rma" />
|
||||
<field name="email_from">${object.user_id.email_formatted |safe}</field>
|
||||
<field name="partner_to">${object.partner_id.id}</field>
|
||||
<field
|
||||
name="subject"
|
||||
>${object.company_id.name} RMA (Ref ${object.name or 'n/a' }) products received</field>
|
||||
<field name="report_template" ref="report_rma_action" />
|
||||
<field name="report_name">${(object.name or '')}</field>
|
||||
<field name="lang">${object.partner_id.lang}</field>
|
||||
<field name="auto_delete" eval="True" />
|
||||
<field name="body_html" type="html">
|
||||
<div style="margin: 0px; padding: 0px;">
|
||||
<p style="margin: 0px; padding: 0px; font-size: 13px;">
|
||||
Dear ${object.partner_id.name}
|
||||
% if object.partner_id.parent_id:
|
||||
(${object.partner_id.parent_id.name})
|
||||
% endif
|
||||
<br /><br />
|
||||
The products for your RMA <strong>${object.name}</strong>
|
||||
from ${object.company_id.name} have been received in our warehouse.
|
||||
<br /><br />
|
||||
Do not hesitate to contact us if you have any question.
|
||||
</p>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
<record id="mail_template_rma_draft_notification" model="mail.template">
|
||||
<field name="name">RMA Draft Notification</field>
|
||||
<field name="model_id" ref="model_rma" />
|
||||
<field name="email_from">${object.user_id.email_formatted |safe}</field>
|
||||
<field name="partner_to">${object.partner_id.id}</field>
|
||||
<field
|
||||
name="subject"
|
||||
>${object.company_id.name} Your RMA has been succesfully created (Ref ${object.name or 'n/a' })</field>
|
||||
<field name="report_template" ref="report_rma_action" />
|
||||
<field name="report_name">${(object.name or '')}</field>
|
||||
<field name="lang">${object.partner_id.lang}</field>
|
||||
<field name="auto_delete" eval="True" />
|
||||
<field name="body_html" type="html">
|
||||
<div style="margin: 0px; padding: 0px;">
|
||||
<p style="margin: 0px; padding: 0px; font-size: 13px;">
|
||||
Dear ${object.partner_id.name}
|
||||
% if object.partner_id.parent_id:
|
||||
(${object.partner_id.parent_id.name})
|
||||
% endif
|
||||
<br /><br />
|
||||
You've succesfully placed your RMA <strong>${object.name}</strong>
|
||||
on ${object.company_id.name}. Our team will check it and will validate
|
||||
it as soon as possible.
|
||||
<br /><br />
|
||||
Do not hesitate to contact us if you have any question.
|
||||
</p>
|
||||
</div>
|
||||
</field>
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -676,19 +676,50 @@ class TestRma(SavepointCase):
|
||||
self.assertEqual(rma.product_id.qty_available, 0)
|
||||
|
||||
def test_autoconfirm_email(self):
|
||||
rma = self._create_rma(self.partner, self.product, 10, self.rma_loc)
|
||||
rma.company_id.send_rma_confirmation = True
|
||||
rma.company_id.rma_mail_confirmation_template_id = self.env.ref(
|
||||
self.company.send_rma_confirmation = True
|
||||
self.company.send_rma_receipt_confirmation = True
|
||||
self.company.send_rma_draft_confirmation = True
|
||||
self.company.rma_mail_confirmation_template_id = self.env.ref(
|
||||
"rma.mail_template_rma_notification"
|
||||
)
|
||||
self.company.rma_mail_receipt_confirmation_template_id = self.env.ref(
|
||||
"rma.mail_template_rma_receipt_notification"
|
||||
)
|
||||
self.company.rma_mail_draft_confirmation_template_id = self.env.ref(
|
||||
"rma.mail_template_rma_draft_notification"
|
||||
)
|
||||
previous_mails = self.env["mail.mail"].search(
|
||||
[("partner_ids", "in", self.partner.ids)]
|
||||
)
|
||||
self.assertFalse(previous_mails)
|
||||
rma.action_confirm()
|
||||
mail = self.env["mail.message"].search(
|
||||
# Force the context to mock an RMA created from the portal, which is
|
||||
# feature that we get on `rma_sale`. We drop it after the RMA creation
|
||||
# to avoid uncontrolled side effects
|
||||
ctx = self.env.context
|
||||
self.env.context = dict(ctx, from_portal=True)
|
||||
rma = self._create_rma(self.partner, self.product, 10, self.rma_loc)
|
||||
self.env.context = ctx
|
||||
mail_draft = self.env["mail.message"].search(
|
||||
[("partner_ids", "in", self.partner.ids)]
|
||||
)
|
||||
self.assertTrue(rma.name in mail.subject)
|
||||
self.assertTrue(rma.name in mail.body)
|
||||
self.assertEqual(self.env.ref("rma.mt_rma_notification"), mail.subtype_id)
|
||||
rma.action_confirm()
|
||||
mail_confirm = (
|
||||
self.env["mail.message"].search([("partner_ids", "in", self.partner.ids)])
|
||||
- mail_draft
|
||||
)
|
||||
self.assertTrue(rma.name in mail_confirm.subject)
|
||||
self.assertTrue(rma.name in mail_confirm.body)
|
||||
self.assertEqual(
|
||||
self.env.ref("rma.mt_rma_notification"), mail_confirm.subtype_id
|
||||
)
|
||||
# Now we'll confirm the incoming goods picking and the automatic
|
||||
# reception notification should be sent
|
||||
rma.reception_move_id.quantity_done = rma.product_uom_qty
|
||||
rma.reception_move_id.picking_id.button_validate()
|
||||
mail_receipt = (
|
||||
self.env["mail.message"].search([("partner_ids", "in", self.partner.ids)])
|
||||
- mail_draft
|
||||
- mail_confirm
|
||||
)
|
||||
self.assertTrue(rma.name in mail_receipt.subject)
|
||||
self.assertTrue("products received" in mail_receipt.subject)
|
||||
|
||||
@@ -46,6 +46,82 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="col-12 col-lg-6 o_setting_box"
|
||||
title="Send automatic RMA products reception notification to customer"
|
||||
>
|
||||
<div class="o_setting_left_pane">
|
||||
<field name="send_rma_receipt_confirmation" />
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<label
|
||||
for="send_rma_receipt_confirmation"
|
||||
string="RMA Receipt Confirmation Email"
|
||||
/>
|
||||
<span
|
||||
class="fa fa-lg fa-building-o"
|
||||
title="Values set here are company-specific."
|
||||
groups="base.group_multi_company"
|
||||
/>
|
||||
<div class="text-muted">
|
||||
When the RMA products are received, send an automatic information email.
|
||||
</div>
|
||||
<div
|
||||
class="row mt16"
|
||||
attrs="{'invisible': [('send_rma_receipt_confirmation', '=', False)]}"
|
||||
>
|
||||
<label
|
||||
for="rma_mail_receipt_confirmation_template_id"
|
||||
string="Email Template"
|
||||
class="col-lg-4 o_light_label"
|
||||
/>
|
||||
<field
|
||||
name="rma_mail_receipt_confirmation_template_id"
|
||||
class="oe_inline"
|
||||
attrs="{'required': [('send_rma_receipt_confirmation', '=', True)]}"
|
||||
context="{'default_model': 'rma'}"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="col-12 col-lg-6 o_setting_box"
|
||||
title="Send automatic notification when the customer places an RMA"
|
||||
>
|
||||
<div class="o_setting_left_pane">
|
||||
<field name="send_rma_draft_confirmation" />
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<label
|
||||
for="send_rma_draft_confirmation"
|
||||
string="RMA draft notification Email"
|
||||
/>
|
||||
<span
|
||||
class="fa fa-lg fa-building-o"
|
||||
title="Values set here are company-specific."
|
||||
groups="base.group_multi_company"
|
||||
/>
|
||||
<div class="text-muted">
|
||||
When customers themselves place an RMA from the portal, send an automatic notification acknowleging it.
|
||||
</div>
|
||||
<div
|
||||
class="row mt16"
|
||||
attrs="{'invisible': [('send_rma_draft_confirmation', '=', False)]}"
|
||||
>
|
||||
<label
|
||||
for="rma_mail_draft_confirmation_template_id"
|
||||
string="Email Template"
|
||||
class="col-lg-4 o_light_label"
|
||||
/>
|
||||
<field
|
||||
name="rma_mail_draft_confirmation_template_id"
|
||||
class="oe_inline"
|
||||
attrs="{'required': [('send_rma_draft_confirmation', '=', True)]}"
|
||||
context="{'default_model': 'rma'}"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user