diff --git a/intrastat_product_type/models/product.py b/intrastat_product_type/models/product.py index 5f1cd1f..9bd920a 100644 --- a/intrastat_product_type/models/product.py +++ b/intrastat_product_type/models/product.py @@ -39,3 +39,23 @@ class ProductTemplate(models.Model): "On product '%s' which is not a consumable, " "Intrastat Type must have the same value as Type.") % pt.display_name) + + # inherit method from intrastat_base + @api.constrains("intrastat_type", "is_accessory_cost") + def _check_accessory_cost(self): + for this in self: + if this.is_accessory_cost and this.intrastat_type != "service": + raise ValidationError( + _( + "The option 'Is accessory cost?' should only be " + "activated on 'Service' products. You have activated " + "this option for the product '%(product_name)s' which is " + "configured with type '%(product_type)s'." + ) + % { + "product_name": this.display_name, + "product_type": this._fields["type"].convert_to_export( + this.type, this + ), + } + ) diff --git a/intrastat_product_type/views/product.xml b/intrastat_product_type/views/product.xml index fe5ff7c..4099fa4 100644 --- a/intrastat_product_type/views/product.xml +++ b/intrastat_product_type/views/product.xml @@ -11,11 +11,15 @@ intrastat_product_type.product.template.form product.template - + + 150 + + {'invisible': [('intrastat_type', '!=', 'service')]} +