generate packagings status quo
This commit is contained in:
parent
f17c61bc7a
commit
4aabadb52e
3 changed files with 40 additions and 4 deletions
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
|
|
@ -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"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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": {},
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue