Skip to content

Commit

Permalink
[FIX] send mail template
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Jul 9, 2024
1 parent 7bdeede commit c774ecb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
30 changes: 13 additions & 17 deletions base_substate/models/base_substate_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,6 @@ def check_substate_id_value(self):
}
)

def _track_template(self, changes):
res = super()._track_template(changes)
first_rec = self[0]
if "substate_id" in changes and first_rec.substate_id.mail_template_id:
res["substate_id"] = (
first_rec.substate_id.mail_template_id,
{
"composition_mode": "comment",
"auto_delete_message": True,
"subtype_id": self.env["ir.model.data"]._xmlid_to_res_id(
"mail.mt_note"
),
"email_layout_xmlid": "mail.mail_notification_light",
},
)
return res

def _get_default_substate_id(self, state_val=False):
"""Gives default substate_id"""
search_domain = self._get_default_substate_domain(state_val)
Expand Down Expand Up @@ -116,6 +99,19 @@ def _update_before_write_create(self, values):
if values.get(state_field) and not values.get("substate_id"):
state_val = values.get(state_field)
values["substate_id"] = self._get_default_substate_id(state_val)
# Send mail if substate has mail template
if values.get("substate_id"):
substate = self.env["base.substate"].browse(values["substate_id"])
if (
hasattr(self, "message_post_with_template")
and substate.mail_template_id
):
self.message_post_with_template(
substate.mail_template_id.id,
subtype_id=self.env["ir.model.data"]._xmlid_to_res_id(
"mail.mt_note"
),
)
return values

def write(self, values):
Expand Down
5 changes: 1 addition & 4 deletions base_substate/tests/test_base_substate.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,10 @@ def test_sale_order_substate(self):
)
self.assertTrue(so_test1.state == "draft")
self.assertTrue(so_test1.substate_id == self.substate_under_negotiation)
# Test that validation of sale order change substate_id
# Test that validation of sale order change substate_id and send email
so_test1.button_confirm()
self.assertTrue(so_test1.state == "sale")
self.assertTrue(so_test1.substate_id == self.substate_wait_docs)
# Test track template
res = so_test1._track_template({"substate_id"})
self.assertEqual(res["substate_id"][0], self.mail_template)
# Test that substate_id is set to false if
# there is not substate corresponding to state
so_test1.button_cancel()
Expand Down

0 comments on commit c774ecb

Please sign in to comment.