diff --git a/rma/data/mail_data.xml b/rma/data/mail_data.xml index f1d8afa20..391f75f71 100644 --- a/rma/data/mail_data.xml +++ b/rma/data/mail_data.xml @@ -142,4 +142,38 @@ + + + RMA Product delivery Notification + + {{object.user_id.email_formatted}} + {{object.partner_id.id}} + {{object.company_id.name}} RMA (Ref {{object.name or 'n/a' }}) products delivered + + {{(object.name or '')}} + {{object.partner_id.lang}} + + +
+

+ Dear + + + + +
+
+ We are pleased to inform you that your product + related to RMA has been successfully shipped. +
+

+
+
+
diff --git a/rma/models/res_company.py b/rma/models/res_company.py index 2b55930a3..b45ec3c05 100644 --- a/rma/models/res_company.py +++ b/rma/models/res_company.py @@ -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, @@ -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", @@ -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): diff --git a/rma/models/res_config_settings.py b/rma/models/res_config_settings.py index c06d9e594..07a07ec5b 100644 --- a/rma/models/res_config_settings.py +++ b/rma/models/res_config_settings.py @@ -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, + ) diff --git a/rma/models/rma.py b/rma/models/rma.py index d24f93b5b..ed01ffe34 100644 --- a/rma/models/rma.py +++ b/rma/models/rma.py @@ -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() @@ -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""" @@ -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( diff --git a/rma/tests/test_rma.py b/rma/tests/test_rma.py index 78fe135c6..c89dc8257 100644 --- a/rma/tests/test_rma.py +++ b/rma/tests/test_rma.py @@ -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", + ) diff --git a/rma/views/res_config_settings_views.xml b/rma/views/res_config_settings_views.xml index 7030a71db..aa284547f 100644 --- a/rma/views/res_config_settings_views.xml +++ b/rma/views/res_config_settings_views.xml @@ -162,6 +162,44 @@ +
+
+ +
+
+
+