[IMP] intrastat_base: add field intrastat_type on product.template

This commit is contained in:
Alexis de Lattre
2025-02-06 12:05:43 +01:00
parent bb918f2234
commit de1d1c147b
2 changed files with 32 additions and 11 deletions

View File

@@ -9,27 +9,45 @@ from odoo.exceptions import ValidationError
class ProductTemplate(models.Model): class ProductTemplate(models.Model):
_inherit = "product.template" _inherit = "product.template"
intrastat_type = fields.Selection(
[
("product", "Product"),
("service", "Service"),
],
compute="_compute_intrastat_type",
store=True,
help="Type of product used for the intrastat declarations.",
)
is_accessory_cost = fields.Boolean( is_accessory_cost = fields.Boolean(
help="Activate this option for shipping costs, packaging " help="Activate this option for shipping costs, packaging "
"costs and all services related to the sale of products. " "costs and all services related to the sale of products. "
"This option is used for Intrastat reports.", "This option is used for Intrastat reports.",
) )
@api.constrains("type", "is_accessory_cost") @api.depends("type", "combo_ids.combo_item_ids.product_id.type")
def _compute_intrastat_type(self):
for this in self:
intrastat_type = "service"
if this.type == "consu":
intrastat_type = "product"
elif this.type == "combo":
for combo in this.combo_ids:
for item in combo.combo_item_ids:
if item.product_id.type == "consu":
intrastat_type = "product"
break
this.intrastat_type = intrastat_type
@api.constrains("intrastat_type", "is_accessory_cost")
def _check_accessory_cost(self): def _check_accessory_cost(self):
for this in self: for this in self:
if this.is_accessory_cost and this.type != "service": if this.is_accessory_cost and this.intrastat_type != "service":
raise ValidationError( raise ValidationError(
_( _(
"The option 'Is accessory cost?' should only be " "The option 'Is accessory cost?' can only be "
"activated on 'Service' products. You have activated " "activated on 'Service' products. You have activated "
"this option for the product '%(product_name)s' which is " "this option for the product '%(product_name)s' which is "
"configured with type '%(product_type)s'." "not a service product.",
product_name=this.display_name,
) )
% {
"product_name": this.display_name,
"product_type": this._fields["type"].convert_to_export(
this.type, this
),
}
) )

View File

@@ -10,10 +10,13 @@
<field name="model">product.template</field> <field name="model">product.template</field>
<field name="inherit_id" ref="account.product_template_form_view" /> <field name="inherit_id" ref="account.product_template_form_view" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<group name="group_general" position="inside">
<field name="intrastat_type" invisible="1" />
</group>
<group name="accounting" position="inside"> <group name="accounting" position="inside">
<group string="Intrastat" name="intrastat"> <group string="Intrastat" name="intrastat">
<!-- If you need this field, inherit this view in a <!-- If you need this field, inherit this view in a
localisation module to set invisible="type != 'service'" --> localisation module to set invisible="intrastat_type != 'service'" -->
<field name="is_accessory_cost" invisible="1" /> <field name="is_accessory_cost" invisible="1" />
</group> </group>
</group> </group>