mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
[IMP] rma: automatic notification subtypes
TT28344
This commit is contained in:
@@ -7,6 +7,12 @@
|
|||||||
<field name="default" eval="False" />
|
<field name="default" eval="False" />
|
||||||
<field name="description">RMA in draft state</field>
|
<field name="description">RMA in draft state</field>
|
||||||
</record>
|
</record>
|
||||||
|
<record id="mt_rma_notification" model="mail.message.subtype">
|
||||||
|
<field name="name">RMA Notificatoin</field>
|
||||||
|
<field name="res_model">rma</field>
|
||||||
|
<field name="default" eval="False" />
|
||||||
|
<field name="description">RMA automatic customer notifications</field>
|
||||||
|
</record>
|
||||||
<!-- rma_team-related subtypes for messaging / Chatter -->
|
<!-- rma_team-related subtypes for messaging / Chatter -->
|
||||||
<record id="mt_rma_team_rma_draft" model="mail.message.subtype">
|
<record id="mt_rma_team_rma_draft" model="mail.message.subtype">
|
||||||
<field name="name">Draft RMA</field>
|
<field name="name">Draft RMA</field>
|
||||||
@@ -16,6 +22,14 @@
|
|||||||
<field name="parent_id" eval="ref('rma.mt_rma_draft')" />
|
<field name="parent_id" eval="ref('rma.mt_rma_draft')" />
|
||||||
<field name="relation_field">team_id</field>
|
<field name="relation_field">team_id</field>
|
||||||
</record>
|
</record>
|
||||||
|
<record id="mt_rma_team_rma_notification" model="mail.message.subtype">
|
||||||
|
<field name="name">RMA Notification</field>
|
||||||
|
<field name="sequence">20</field>
|
||||||
|
<field name="res_model">rma.team</field>
|
||||||
|
<field name="default" eval="True" />
|
||||||
|
<field name="parent_id" eval="ref('rma.mt_rma_notification')" />
|
||||||
|
<field name="relation_field">team_id</field>
|
||||||
|
</record>
|
||||||
<!--RMA email template -->
|
<!--RMA email template -->
|
||||||
<record id="mail_template_rma_notification" model="mail.template">
|
<record id="mail_template_rma_notification" model="mail.template">
|
||||||
<field name="name">RMA Notification</field>
|
<field name="name">RMA Notification</field>
|
||||||
|
|||||||
@@ -503,7 +503,9 @@ class Rma(models.Model):
|
|||||||
for rma in self.filtered(lambda p: p.company_id.send_rma_confirmation):
|
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_template_id = rma.company_id.rma_mail_confirmation_template_id.id
|
||||||
rma.with_context(
|
rma.with_context(
|
||||||
force_send=True, mark_rma_as_sent=True
|
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)
|
).message_post_with_template(rma_template_id)
|
||||||
|
|
||||||
# Action methods
|
# Action methods
|
||||||
@@ -514,6 +516,7 @@ class Rma(models.Model):
|
|||||||
form = self.env.ref("mail.email_compose_message_wizard_form", False)
|
form = self.env.ref("mail.email_compose_message_wizard_form", False)
|
||||||
ctx = {
|
ctx = {
|
||||||
"default_model": "rma",
|
"default_model": "rma",
|
||||||
|
"default_subtype_id": self.env.ref("rma.mt_rma_notification").id,
|
||||||
"default_res_id": self.ids[0],
|
"default_res_id": self.ids[0],
|
||||||
"default_use_template": bool(template),
|
"default_use_template": bool(template),
|
||||||
"default_template_id": template and template.id or False,
|
"default_template_id": template and template.id or False,
|
||||||
@@ -1110,11 +1113,20 @@ class Rma(models.Model):
|
|||||||
|
|
||||||
# Mail business methods
|
# Mail business methods
|
||||||
def _creation_subtype(self):
|
def _creation_subtype(self):
|
||||||
if self.state in ("draft", "confirmed"):
|
if self.state in ("draft"):
|
||||||
return self.env.ref("rma.mt_rma_draft")
|
return self.env.ref("rma.mt_rma_draft")
|
||||||
else:
|
else:
|
||||||
return super()._creation_subtype()
|
return super()._creation_subtype()
|
||||||
|
|
||||||
|
def _track_subtype(self, init_values):
|
||||||
|
self.ensure_one()
|
||||||
|
if "state" in init_values:
|
||||||
|
if self.state == "draft":
|
||||||
|
return self.env.ref("rma.mt_rma_draft")
|
||||||
|
elif self.state == "confirmed":
|
||||||
|
return self.env.ref("rma.mt_rma_notification")
|
||||||
|
return super()._track_subtype(init_values)
|
||||||
|
|
||||||
def message_new(self, msg_dict, custom_values=None):
|
def message_new(self, msg_dict, custom_values=None):
|
||||||
"""Extract the needed values from an incoming rma emails data-set
|
"""Extract the needed values from an incoming rma emails data-set
|
||||||
to be used to create an RMA.
|
to be used to create an RMA.
|
||||||
|
|||||||
@@ -673,3 +673,4 @@ class TestRma(SavepointCase):
|
|||||||
)
|
)
|
||||||
self.assertTrue(rma.name in mail.subject)
|
self.assertTrue(rma.name in mail.subject)
|
||||||
self.assertTrue(rma.name in mail.body)
|
self.assertTrue(rma.name in mail.body)
|
||||||
|
self.assertEqual(self.env.ref("rma.mt_rma_notification"), mail.subtype_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user