From 86becfbd22cca7019b651b97f7d82891035d0f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20G=C3=B6ttsch?= Date: Mon, 28 Apr 2025 21:28:45 +0200 Subject: [PATCH] [122][FIX] nfu_product,nfu_product_bnn_attributes: Avoid unvalid companies in packagings --- nfu_product/README.rst | 1 + nfu_product/__manifest__.py | 2 +- nfu_product/models/__init__.py | 1 + nfu_product/models/product_packaging.py | 6 ++--- nfu_product/models/product_product.py | 25 +++++++++++++++++++ nfu_product/readme/HISTORY.rst | 1 + nfu_product/static/description/index.html | 1 + nfu_product_bnn_attributes/README.rst | 1 + nfu_product_bnn_attributes/__manifest__.py | 2 +- .../models/product_template.py | 9 ++++++- nfu_product_bnn_attributes/readme/HISTORY.rst | 3 ++- .../static/description/index.html | 1 + 12 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 nfu_product/models/product_product.py diff --git a/nfu_product/README.rst b/nfu_product/README.rst index b7c6b8d..96aa564 100644 --- a/nfu_product/README.rst +++ b/nfu_product/README.rst @@ -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 diff --git a/nfu_product/__manifest__.py b/nfu_product/__manifest__.py index 739d50c..61676bd 100644 --- a/nfu_product/__manifest__.py +++ b/nfu_product/__manifest__.py @@ -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", diff --git a/nfu_product/models/__init__.py b/nfu_product/models/__init__.py index 2c4d9a8..4c7df9d 100644 --- a/nfu_product/models/__init__.py +++ b/nfu_product/models/__init__.py @@ -1 +1,2 @@ from . import product_packaging +from . import product_product diff --git a/nfu_product/models/product_packaging.py b/nfu_product/models/product_packaging.py index 96f09b4..f7d3613 100644 --- a/nfu_product/models/product_packaging.py +++ b/nfu_product/models/product_packaging.py @@ -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 diff --git a/nfu_product/models/product_product.py b/nfu_product/models/product_product.py new file mode 100644 index 0000000..5c23618 --- /dev/null +++ b/nfu_product/models/product_product.py @@ -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 diff --git a/nfu_product/readme/HISTORY.rst b/nfu_product/readme/HISTORY.rst index da2cb2f..e875767 100644 --- a/nfu_product/readme/HISTORY.rst +++ b/nfu_product/readme/HISTORY.rst @@ -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 diff --git a/nfu_product/static/description/index.html b/nfu_product/static/description/index.html index 75a7ba6..777c34e 100644 --- a/nfu_product/static/description/index.html +++ b/nfu_product/static/description/index.html @@ -391,6 +391,7 @@ ul.auto-toc {
diff --git a/nfu_product_bnn_attributes/README.rst b/nfu_product_bnn_attributes/README.rst index 13aadb9..e61cb05 100644 --- a/nfu_product_bnn_attributes/README.rst +++ b/nfu_product_bnn_attributes/README.rst @@ -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 =========== diff --git a/nfu_product_bnn_attributes/__manifest__.py b/nfu_product_bnn_attributes/__manifest__.py index 2b7cf85..e4ca010 100644 --- a/nfu_product_bnn_attributes/__manifest__.py +++ b/nfu_product_bnn_attributes/__manifest__.py @@ -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": {}, diff --git a/nfu_product_bnn_attributes/models/product_template.py b/nfu_product_bnn_attributes/models/product_template.py index 406ce82..4a22a8b 100644 --- a/nfu_product_bnn_attributes/models/product_template.py +++ b/nfu_product_bnn_attributes/models/product_template.py @@ -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( { diff --git a/nfu_product_bnn_attributes/readme/HISTORY.rst b/nfu_product_bnn_attributes/readme/HISTORY.rst index 8d7d5ba..7c7d521 100644 --- a/nfu_product_bnn_attributes/readme/HISTORY.rst +++ b/nfu_product_bnn_attributes/readme/HISTORY.rst @@ -2,4 +2,5 @@ - 16.0.1.0.0: Initial module. - 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 \ No newline at end of file +- 16.0.1.2.0: Add Multi company to packaging +- 16.0.1.2.1: Always write the company in the product packaging \ No newline at end of file diff --git a/nfu_product_bnn_attributes/static/description/index.html b/nfu_product_bnn_attributes/static/description/index.html index 44dd16f..e181023 100644 --- a/nfu_product_bnn_attributes/static/description/index.html +++ b/nfu_product_bnn_attributes/static/description/index.html @@ -391,6 +391,7 @@ ul.auto-toc {
  • 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