Skip to content

Commit

Permalink
[14.0][IMP] product_tier_validation state_to default values
Browse files Browse the repository at this point in the history
  • Loading branch information
Kev-Roche authored and sebastienbeau committed Apr 3, 2023
1 parent f9b90e0 commit d386a14
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions product_tier_validation/models/product_template.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo import _, api, models, tools
from odoo.exceptions import UserError
from odoo.tools import config


class ProductTemplate(models.Model):
_name = "product.template"
_inherit = ["product.template", "tier.validation"]
_tier_validation_manual_config = False

@property
@tools.ormcache()
def _state_to(self):
return (
self.env["product.state"]
.search([("code", "not in", self._state_from + [self._cancel_state])])
.mapped("code")
)

def write(self, vals):
# Tier Validation does not work with Stages, only States :-(
# So, signal state transition by adding it to the vals
Expand All @@ -24,9 +35,10 @@ def write(self, vals):
@api.model_create_multi
def create(self, vals_list):
states = self.env["product.state"].search([("code", "in", self._state_from)])
if not states:
raise UserError("Wrong configuration of '_state_from' in product.state")
for vals in vals_list:
if vals.get("product_state_id") not in states.ids:
vals["product_state_id"] = states[0].id
if not states and not config["test_enable"]:
raise UserError(_("Wrong configuration of '_state_from' in product.state"))
if states:
for vals in vals_list:
if vals.get("product_state_id") not in states.ids:
vals["product_state_id"] = states[0].id
return super().create(vals_list)

0 comments on commit d386a14

Please sign in to comment.