[IMP] intrastat_product_type: improve support for is accessory cost

This commit is contained in:
Alexis de Lattre
2024-12-16 14:20:51 +00:00
parent c6fb47c1e2
commit 5f227f9b72
2 changed files with 25 additions and 1 deletions

View File

@@ -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
),
}
)

View File

@@ -11,11 +11,15 @@
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">intrastat_product_type.product.template.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="inherit_id" ref="intrastat_base.product_template_form_view" />
<field name="priority">150</field>
<field name="arch" type="xml">
<field name="detailed_type" position="after">
<field name="intrastat_type" attrs="{'invisible': [('type', '!=', 'consu')]}"/>
</field>
<field name="is_accessory_cost" position="attributes">
<attribute name="attrs">{'invisible': [('intrastat_type', '!=', 'service')]}</attribute>
</field>
</field>
</record>