diff --git a/nfu_product/README.rst b/nfu_product/README.rst index c49a93c..17d8f41 100644 --- a/nfu_product/README.rst +++ b/nfu_product/README.rst @@ -22,6 +22,7 @@ NFU Product |badge1| |badge2| |badge3| +* Relate company_ids from packages to product.product * Remove company_id and add company_ids to views **Table of contents** @@ -35,6 +36,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 +- 16.0.1.2.0: Relate package companies to products Bug Tracker diff --git a/nfu_product/models/__init__.py b/nfu_product/models/__init__.py index 4c7df9d..2c4d9a8 100644 --- a/nfu_product/models/__init__.py +++ b/nfu_product/models/__init__.py @@ -1,2 +1 @@ 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 f7d3613..43802a3 100644 --- a/nfu_product/models/product_packaging.py +++ b/nfu_product/models/product_packaging.py @@ -1,14 +1,8 @@ -from odoo import api, models +from odoo import fields, models class ProductPackaging(models.Model): _inherit = ["multi.company.abstract", "product.packaging"] _name = "product.packaging" - @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) - return res + company_ids = fields.Many2many(related="product_id.company_ids") diff --git a/nfu_product/models/product_product.py b/nfu_product/models/product_product.py deleted file mode 100644 index e78139a..0000000 --- a/nfu_product/models/product_product.py +++ /dev/null @@ -1,29 +0,0 @@ -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/DESCRIPTION.rst b/nfu_product/readme/DESCRIPTION.rst index 88b0bdf..adbe3f4 100644 --- a/nfu_product/readme/DESCRIPTION.rst +++ b/nfu_product/readme/DESCRIPTION.rst @@ -1 +1,2 @@ +* Relate company_ids from packages to product.product * Remove company_id and add company_ids to views \ No newline at end of file diff --git a/nfu_product/readme/HISTORY.rst b/nfu_product/readme/HISTORY.rst index e875767..dc46835 100644 --- a/nfu_product/readme/HISTORY.rst +++ b/nfu_product/readme/HISTORY.rst @@ -1,4 +1,5 @@ - 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 +- 16.0.1.2.0: Relate package companies to products diff --git a/nfu_product/static/description/index.html b/nfu_product/static/description/index.html index 7ca2cf7..86498cc 100644 --- a/nfu_product/static/description/index.html +++ b/nfu_product/static/description/index.html @@ -371,6 +371,7 @@ ul.auto-toc { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
Table of contents
@@ -392,6 +393,7 @@ ul.auto-toc {