Skip to content

Commit

Permalink
[FIX] connector_oxigesti: execute default code logic during product c…
Browse files Browse the repository at this point in the history
…reation and set the default code on the first created variant
  • Loading branch information
FrankC013 committed Nov 14, 2024
1 parent d35eaea commit 976614b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion connector_oxigesti/models/product_template/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
# Copyright NuoBiT Solutions - Kilian Niubo <[email protected]>
# 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"

Expand All @@ -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:
Expand Down

0 comments on commit 976614b

Please sign in to comment.