diff --git a/nfu_sale_order_batch_packaging/models/__init__.py b/nfu_sale_order_batch_packaging/models/__init__.py index f6eae4a..b0c450c 100644 --- a/nfu_sale_order_batch_packaging/models/__init__.py +++ b/nfu_sale_order_batch_packaging/models/__init__.py @@ -1,5 +1,4 @@ from . import product_product from . import product_template -from . import sale_order_batch -from . import sale_order_line from . import sale_order_batch_product +from . import sale_order_line diff --git a/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py b/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py index 2bf71a3..9cfd405 100644 --- a/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py +++ b/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py @@ -9,7 +9,7 @@ class SaleOrderBatchProduct(models.Model): product_uom_max_qty = fields.Float("Max Qty", compute="_compute_product_uom_max_qty") open_packaging_qty = fields.Float(compute="_compute_open_packagin_qty", store=True) - open_packaging_state = fields.Selection(selection=PACKAGING_STATES, compute="_compute_open_packagin_state") + # open_packaging_state = fields.Selection(selection=PACKAGING_STATES, compute="_compute_open_packagin_state") @api.depends("sale_order_line_ids.product_uom_max_qty") def _compute_product_uom_max_qty(self): @@ -29,15 +29,15 @@ class SaleOrderBatchProduct(models.Model): 0 if open_packaging_qty == product.product_packaging_qty else open_packaging_qty ) - @api.depends("open_packaging_qty", "product_packaging_qty") - def _compute_open_packagin_state(self): - for product in self: - if product.open_packaging_qty == 0: - product.open_packaging_state = "full" - elif product.open_packaging_qty < product.product_packaging_qty: - product.open_packaging_state = "open" - else: - product.open_packaging_state = "last_open" + # @api.depends("open_packaging_qty", "product_packaging_qty") + # def _compute_open_packagin_state(self): + # for product in self: + # if product.open_packaging_qty == 0: + # product.open_packaging_state = "full" + # elif product.open_packaging_qty < product.product_packaging_qty: + # product.open_packaging_state = "open" + # else: + # product.open_packaging_state = "last_open" @api.model_create_multi def create(self, vals_list): @@ -46,5 +46,6 @@ class SaleOrderBatchProduct(models.Model): packaging = ( self.env["product.product"].search([("id", "=", vals.get("product_id"))])._get_nfu_packaging() ) - vals["product_packaging_id"] = packaging.id + if packaging: + vals["product_packaging_id"] = packaging.id return super().create(vals_list) diff --git a/nfu_sale_order_batch_packaging/models/sale_order_line.py b/nfu_sale_order_batch_packaging/models/sale_order_line.py index f392b00..c3deff5 100644 --- a/nfu_sale_order_batch_packaging/models/sale_order_line.py +++ b/nfu_sale_order_batch_packaging/models/sale_order_line.py @@ -1,6 +1,5 @@ from odoo import _, api, fields, models from odoo.exceptions import UserError -from odoo.tools import float_round class SaleOrderLine(models.Model): @@ -8,8 +7,8 @@ class SaleOrderLine(models.Model): product_uom_ordered_qty = fields.Float(string="Ordered Qty", digits="Product Unit of Measure", default=1.0) product_uom_max_qty = fields.Float(string="Max Qty", digits="Product Unit of Measure") - batch_uom_qty = fields.Float(compute="_compute_batch_uom_qty") - batch_uom_max_qty = fields.Float(compute="_compute_batch_uom_qty") + # batch_uom_qty = fields.Float(compute="_compute_batch_uom_qty") + # batch_uom_max_qty = fields.Float(compute="_compute_batch_uom_qty") @api.constrains("product_uom_qty", "product_uom_max_qty") def _check_product_uom_qty(self): @@ -22,29 +21,29 @@ class SaleOrderLine(models.Model): ) ) - @api.depends("product_uom_qty", "product_uom_max_qty") - def _compute_batch_uom_qty(self): - for line in self: - if line.batch_product_id: - line.batch_uom_qty = line.batch_product_id.product_uom_qty - line.batch_uom_max_qty = line.batch_product_id.product_uom_max_qty - else: - line.batch_uom_max_qty = line.batch_uom_qty = 0 + # @api.depends("product_uom_qty", "product_uom_max_qty") + # def _compute_batch_uom_qty(self): + # for line in self: + # if line.batch_product_id: + # line.batch_uom_qty = line.batch_product_id.product_uom_qty + # line.batch_uom_max_qty = line.batch_product_id.product_uom_max_qty + # else: + # line.batch_uom_max_qty = line.batch_uom_qty = 0 - @api.depends("product_packaging_id", "product_uom", "product_uom_qty", "batch_id") - def _compute_product_packaging_qty(self): - for line in self: - if not line.product_packaging_id: - line.product_packaging_qty = False - elif line.batch_id: - packaging_uom = line.product_packaging_id.product_uom_id - batch_uom_qty = line.product_uom._compute_quantity(line.batch_uom_qty, packaging_uom) - line.product_packaging_qty = float_round( - batch_uom_qty / line.product_packaging_id.qty, precision_rounding=packaging_uom.rounding - ) - else: - super()._compute_product_packaging_qty() - return True + # @api.depends("product_packaging_id", "product_uom", "product_uom_qty", "batch_id") + # def _compute_product_packaging_qty(self): + # for line in self: + # if not line.product_packaging_id: + # line.product_packaging_qty = False + # elif line.batch_id: + # packaging_uom = line.product_packaging_id.product_uom_id + # batch_uom_qty = line.product_uom._compute_quantity(line.batch_uom_qty, packaging_uom) + # line.product_packaging_qty = float_round( + # batch_uom_qty / line.product_packaging_id.qty, precision_rounding=packaging_uom.rounding + # ) + # else: + # super()._compute_product_packaging_qty() + # return True @api.model_create_multi def create(self, vals_list): diff --git a/nfu_sale_order_batch_packaging/views/sale_order_batch_views.xml b/nfu_sale_order_batch_packaging/views/sale_order_batch_views.xml index 9a3f400..1a1258f 100644 --- a/nfu_sale_order_batch_packaging/views/sale_order_batch_views.xml +++ b/nfu_sale_order_batch_packaging/views/sale_order_batch_views.xml @@ -18,10 +18,10 @@ - + - + -