diff --git a/.vscode/launch.json b/.vscode/launch.json index 10199d7..f7805af 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,11 +9,11 @@ "program": "${config:odoo.path}/odoo-bin", "console": "integratedTerminal", "args": [ - "--database=nfu_sale_order_batch_packaging", + "--database=nfu_", "--addons-path=${config:odoo.addons_path},${workspaceFolder}", "--limit-time-real=0", "--limit-time-cpu=0", - "--update=sale_order_batch_stock", + // "--init=", // "--update=", "--dev=xml" ] diff --git a/nfu_product_bnn_attributes/__manifest__.py b/nfu_product_bnn_attributes/__manifest__.py index 4d046ca..92608a6 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.0.0", + "version": "16.0.1.1.0", "depends": ["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 22aa5ca..b2a009a 100644 --- a/nfu_product_bnn_attributes/models/product_template.py +++ b/nfu_product_bnn_attributes/models/product_template.py @@ -1,4 +1,4 @@ -from odoo import fields, models +from odoo import api, fields, models class ProductTemplate(models.Model): @@ -11,3 +11,39 @@ class ProductTemplate(models.Model): origin = fields.Char() packaging_qty = fields.Float(string="Packaging Quantity") packaging_name = fields.Char() + + @api.depends("packaging_qty", "packaging_name") + def generate_packaging_from_bnn(self): + for product in self: + qty = product.packaging_qty + name = product.packaging_name + if qty and name: + packagings = ( + self.env["product.packaging"] + .search([("product_id", "=", product.id)]) + .filtered(lambda p: p.qty == qty) + ) + if packagings: + packagings[0].write({"name": name}) + else: + self.env["product.packaging"].create({"name": name, "qty": qty, "product_id": product.id}) + + def write(self, vals): + res = super().write(vals) + if vals.get("packaging_qty"): + for product in self: + qty = vals.get("packaging_qty") + name = vals.get("packaging_name") if vals.get("packaging_name") else product.packaging_name + if qty and name: + packagings = ( + self.env["product.packaging"] + .search([("product_id", "=", product.id)]) + .filtered(lambda p: p.qty == qty) + ) + if packagings: + packagings[0].write({"name": name}) + else: + self.env["product.packaging"].create( + {"name": name, "qty": qty, "product_id": product.id, "sales": True} + ) + return res