2021-03-23 19:13:18 +00:00
|
|
|
# Copyright 2019 Open Source Integrators
|
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
|
|
|
2021-04-28 15:43:20 +00:00
|
|
|
from flectra import api, fields, models
|
2021-03-23 19:13:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ResPartner(models.Model):
|
|
|
|
_name = "res.partner"
|
2021-04-28 15:43:20 +00:00
|
|
|
_inherit = ["res.partner", "tier.validation"]
|
|
|
|
_tier_validation_manual_config = False
|
2021-03-23 19:13:18 +00:00
|
|
|
|
|
|
|
state = fields.Selection(
|
2021-04-28 15:43:20 +00:00
|
|
|
[("draft", "Draft"), ("confirmed", "Active"), ("cancel", "Archived")],
|
|
|
|
string="Status",
|
|
|
|
default="draft",
|
2021-03-23 19:13:18 +00:00
|
|
|
)
|
2021-04-28 15:43:20 +00:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
def create(self, vals):
|
|
|
|
new = super().create(vals)
|
|
|
|
if new.need_validation and new.state != "confirmed":
|
|
|
|
new.active = False
|
|
|
|
return new
|
|
|
|
|
|
|
|
def write(self, vals):
|
|
|
|
"""
|
|
|
|
Default `active` is False.
|
|
|
|
It is set to True when State changes to confirmed.
|
|
|
|
"""
|
|
|
|
if "state" in vals:
|
|
|
|
vals["active"] = vals["state"] == "confirmed"
|
|
|
|
return super().write(vals)
|