-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] connector_oxigesti: execute default code logic during product c…
…reation and set the default code on the first created variant
- Loading branch information
Showing
1 changed file
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
||
|
@@ -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: | ||
|