server-ux/base_tier_validation_server_action/models/tier_review.py

31 lines
1.2 KiB
Python
Raw Permalink Normal View History

2021-03-23 19:15:27 +00:00
# Copyright 2020 Ecosoft (http://ecosoft.co.th)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2021-07-25 02:12:32 +00:00
from flectra import models
2021-03-23 19:15:27 +00:00
class TierReview(models.Model):
_inherit = "tier.review"
2021-07-25 02:12:32 +00:00
def write(self, vals):
res = super().write(vals)
if vals.get("status") in ["approved", "rejected"]:
for rec in self:
server_action = False
if rec.status == "approved":
server_action = rec.definition_id.server_action_id
if rec.status == "rejected":
server_action = rec.definition_id.rejected_server_action_id
2022-06-29 18:41:04 +00:00
server_action_tier = self.env.context.get("server_action_tier")
# Don't allow reentrant server action as it will lead to
# recursive behaviour
if server_action and (
not server_action_tier or server_action_tier != server_action.id
):
2021-07-25 02:12:32 +00:00
server_action.with_context(
2022-06-29 18:41:04 +00:00
server_action_tier=server_action.id,
2021-07-25 02:12:32 +00:00
active_model=rec.model,
active_id=rec.res_id,
).sudo().run()
return res