diff --git a/connector_oxigesti/models/product_template/binding.py b/connector_oxigesti/models/product_template/binding.py index 8be8c4fb2..e576f3227 100644 --- a/connector_oxigesti/models/product_template/binding.py +++ b/connector_oxigesti/models/product_template/binding.py @@ -2,10 +2,24 @@ # Copyright NuoBiT Solutions - Kilian Niubo # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) -from odoo import _, fields, models +from odoo import _, api, fields, models from odoo.exceptions import ValidationError +class ProductProduct(models.Model): + _inherit = "product.product" + + # TODO: Review move the default_code logic (required) in a separate module. + @api.model_create_multi + def create(self, vals_list): + records = super().create(vals_list) + for product_tmpl in records.product_tmpl_id: + if not any(product_tmpl.product_variant_ids.mapped("default_code")): + first_variant = product_tmpl.product_variant_ids.sorted("id")[0] + first_variant.default_code = product_tmpl.default_code + return records + + class ProductTemplate(models.Model): _inherit = "product.template" @@ -20,6 +34,13 @@ def _compute_oxigesti_product_variant_bind_ids(self): active_test=False ).product_variant_ids.oxigesti_bind_ids + # TODO: Review move the default_code logic (required) in a separate module. + @api.model_create_multi + def create(self, vals_list): + records = super().create(vals_list) + records._compute_default_code() + return records + def write(self, vals): if "default_code" in vals: for rec in self: