[122][FIX] nfu_product,nfu_product_bnn_attributes: Avoid unvalid companies in packagings

This commit is contained in:
Niels Göttsch 2025-04-28 21:28:45 +02:00 committed by madmooose
parent 142ce7f48a
commit 86becfbd22
12 changed files with 46 additions and 7 deletions

View file

@ -34,6 +34,7 @@ Changelog
- 16.0.1.0.0: Initial module.
- 16.0.1.1.0: Add multi company to product packagings
- 16.0.1.1.1: Avoid unvalid packaging companies
Bug Tracker

View file

@ -4,7 +4,7 @@
"author": "BAKEUP",
"website": "https://www.bakeup.org",
"category": "product",
"version": "16.0.1.1.0",
"version": "16.0.1.1.1",
"depends": ["product_multi_company"],
"data": [
"views/product_packaging_views.xml",

View file

@ -1 +1,2 @@
from . import product_packaging
from . import product_product

View file

@ -7,8 +7,8 @@ class ProductPackaging(models.Model):
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
product = self.env["product.product"].browse(vals.get("product_id"))
vals["company_ids"] = [(6, 0, product.company_ids.ids)]
res = super().create(vals_list)
for packaging in res:
product = packaging.product_id
packaging.company_ids = product.company_ids
return res

View file

@ -0,0 +1,25 @@
from odoo import models
class ProductProduct(models.Model):
_inherit = "product.product"
def write(self, vals):
if "company_ids" in vals:
for product in self:
company_ids = vals.get("company_ids", [])[0][2]
if company_ids:
related_packages = self.env["product.packaging"].search([("product_id", "=", product.id)])
# First, set the company_ids on packages if not set
for package in related_packages:
if not package.company_ids:
package.company_ids = product.company_ids
else:
allowed_company_ids = list(set(package.company_ids.ids) & set(company_ids))
if not allowed_company_ids:
package.company_ids = [(6, 0, company_ids)]
else:
package.company_ids = [(6, 0, allowed_company_ids)]
res = super().write(vals)
return res

View file

@ -1,3 +1,4 @@
- 16.0.1.0.0: Initial module.
- 16.0.1.1.0: Add multi company to product packagings
- 16.0.1.1.1: Avoid unvalid packaging companies

View file

@ -391,6 +391,7 @@ ul.auto-toc {
<ul class="simple">
<li>16.0.1.0.0: Initial module.</li>
<li>16.0.1.1.0: Add multi company to product packagings</li>
<li>16.0.1.1.1: Avoid unvalid packaging companies</li>
</ul>
</div>
<div class="section" id="bug-tracker">

View file

@ -37,6 +37,7 @@ Changelog
- 16.0.1.1.0: Add packaging
- 16.0.1.1.1: inherit package company if from product
- 16.0.1.2.0: Add Multi company to packaging
- 16.0.1.2.1: Always write the company in the product packaging
Bug Tracker
===========

View file

@ -4,7 +4,7 @@
"author": "BAKEUP",
"website": "https://www.bakeup.org",
"category": "Product",
"version": "16.0.1.2.0",
"version": "16.0.1.2.1",
"depends": ["nfu_product"],
"data": ["views/product_bnn_views.xml"],
"assets": {},

View file

@ -25,7 +25,14 @@ class ProductTemplate(models.Model):
[("product_id", "=", product_product.id)], limit=1
)
if packagings:
packagings.write({"name": name, "qty": qty, "sales": True})
packagings.write(
{
"name": name,
"qty": qty,
"sales": True,
"company_ids": product_product.company_ids.ids,
}
)
else:
self.env["product.packaging"].create(
{

View file

@ -3,3 +3,4 @@
- 16.0.1.1.0: Add packaging
- 16.0.1.1.1: inherit package company if from product
- 16.0.1.2.0: Add Multi company to packaging
- 16.0.1.2.1: Always write the company in the product packaging

View file

@ -391,6 +391,7 @@ ul.auto-toc {
<li>16.0.1.1.0: Add packaging</li>
<li>16.0.1.1.1: inherit package company if from product</li>
<li>16.0.1.2.0: Add Multi company to packaging</li>
<li>16.0.1.2.1: Always write the company in the product packaging</li>
</ul>
</div>
<div class="section" id="bug-tracker">