Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions rma/data/mail_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,38 @@
</div>
</field>
</record>
<!--RMA product delivery email template -->
<record id="mail_template_rma_delivery_notification" model="mail.template">
<field name="name">RMA Product delivery Notification</field>
<field name="model_id" ref="model_rma" />
<field name="email_from">{{object.user_id.email_formatted}}</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 delivered</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
<t t-out="object.partner_id.name" />
<t t-if="object.partner_id.parent_id">
<t t-out="object.partner_id.parent_id.name" />
</t>
<br />
<br />
We are pleased to inform you that your product <t
t-out="object.product_id.name"
/>
related to RMA <t
t-out="object.name"
/> has been successfully shipped.
<br />
</p>
</div>
</field>
</record>
</data>
18 changes: 18 additions & 0 deletions rma/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def _default_rma_mail_draft_template(self):
except ValueError:
return False

def _default_rma_mail_delivery_template(self):
try:
return self.env.ref("rma.mail_template_rma_delivery_notification").id
except ValueError:
return False

rma_return_grouping = fields.Boolean(
string="Group RMA returns by customer address and warehouse",
default=True,
Expand All @@ -44,6 +50,10 @@ def _default_rma_mail_draft_template(self):
string="Send RMA draft Confirmation",
help="When a customer places an RMA, send a notification with it",
)
send_rma_delivery_confirmation = fields.Boolean(
string="Send RMA product delivery Confirmation",
help="When repaired / replacement product is delivered, send a notification with it",
)
rma_mail_confirmation_template_id = fields.Many2one(
comodel_name="mail.template",
string="Email Template confirmation for RMA",
Expand All @@ -65,6 +75,14 @@ def _default_rma_mail_draft_template(self):
default=_default_rma_mail_draft_template,
help="Email sent to the customer when they place " "an RMA from the portal",
)
rma_mail_delivery_confirmation_template_id = fields.Many2one(
comodel_name="mail.template",
string="Email Template product delivery notification for RMA",
domain="[('model', '=', 'rma')]",
default=_default_rma_mail_delivery_template,
help="Email sent to the customer when repaired / replacement product "
"is delivered",
)

@api.model_create_multi
def create(self, vals_list):
Expand Down
8 changes: 8 additions & 0 deletions rma/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ class ResConfigSettings(models.TransientModel):
related="company_id.rma_mail_draft_confirmation_template_id",
readonly=False,
)
send_rma_delivery_confirmation = fields.Boolean(
related="company_id.send_rma_delivery_confirmation",
readonly=False,
)
rma_mail_delivery_confirmation_template_id = fields.Many2one(
related="company_id.rma_mail_delivery_confirmation_template_id",
readonly=False,
)
14 changes: 14 additions & 0 deletions rma/models/rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,18 @@ def _send_receipt_confirmation_email(self):
default_subtype_id=self.env.ref("rma.mt_rma_notification").id,
).message_post_with_template(rma_template_id)

def _send_delivery_confirmation_email(self):
"""Send customer notifications when the products are delivered"""
for rma in self.filtered("company_id.send_rma_delivery_confirmation"):
rma_template_id = (
rma.company_id.rma_mail_delivery_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()
Expand Down Expand Up @@ -1601,6 +1613,7 @@ def update_replaced_state(self):
)
if rma:
rma.write({"state": "replaced"})
rma._send_delivery_confirmation_email()

def update_returned_state(self):
"""Invoked by [stock.move]._action_done"""
Expand All @@ -1609,6 +1622,7 @@ def update_returned_state(self):
)
if rma:
rma.write({"state": "returned"})
rma._send_delivery_confirmation_email()

def _delivery_group_key(self):
warnings.warn(
Expand Down
17 changes: 17 additions & 0 deletions rma/tests/test_rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,3 +985,20 @@ def test_group_reception(self):
self.assertNotEqual(rma1.procurement_group_id, rma3.procurement_group_id)
self.assertEqual(len((rma1 | rma2).reception_move_id.picking_id), 1)
self.assertEqual(len((rma1 | rma2 | rma3).reception_move_id.picking_id), 2)

def test_send_delivery_notification(self):
self.env["stock.quant"]._update_available_quantity(
self.product, self.env.ref("stock.stock_location_stock"), 10
)
self.env.company.send_rma_delivery_confirmation = True
rma = self._receive_and_replace(self.partner, self.product, 1, self.rma_loc)
messages = rma.message_ids
rma.delivery_move_ids.quantity_done = 1
rma.delivery_move_ids.picking_id.button_validate()
self.assertEqual(rma.delivery_move_ids.picking_id.state, "done")
self.assertEqual(rma.state, "replaced")
new_messages = rma.message_ids - messages
self.assertTrue(
new_messages,
"No message was posted on the RMA after delivery validation",
)
38 changes: 38 additions & 0 deletions rma/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,44 @@
</div>
</div>
</div>
<div
class="col-12 col-lg-6 o_setting_box"
title="Send automatic RMA products delivery notification to customer"
>
<div class="o_setting_left_pane">
<field name="send_rma_delivery_confirmation" />
</div>
<div class="o_setting_right_pane">
<label
for="send_rma_delivery_confirmation"
string="RMA delivery 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 RMA repaired product or replaced product is delivered to the customer, send an automatic notification acknowleging it.
</div>
<div
class="row mt16"
attrs="{'invisible': [('send_rma_delivery_confirmation', '=', False)]}"
>
<label
for="rma_mail_delivery_confirmation_template_id"
string="Email Template"
class="col-lg-4 o_light_label"
/>
<field
name="rma_mail_delivery_confirmation_template_id"
class="oe_inline"
attrs="{'required': [('send_rma_delivery_confirmation', '=', True)]}"
context="{'default_model': 'rma'}"
/>
</div>
</div>
</div>
</div>
</div>
</xpath>
Expand Down