diff --git a/nfu_sale_order_batch_packaging/models/product_template.py b/nfu_sale_order_batch_packaging/models/product_template.py index 8d77185..bcce92b 100644 --- a/nfu_sale_order_batch_packaging/models/product_template.py +++ b/nfu_sale_order_batch_packaging/models/product_template.py @@ -4,6 +4,7 @@ from odoo import models class ProductTemplate(models.Model): _inherit = "product.template" + # TODO: remove here and only use product.product def _get_nfu_packaging(self): self.ensure_one() if self.packaging_ids: diff --git a/nfu_sale_order_batch_packaging/models/sale_order_batch.py b/nfu_sale_order_batch_packaging/models/sale_order_batch.py deleted file mode 100644 index d0dd492..0000000 --- a/nfu_sale_order_batch_packaging/models/sale_order_batch.py +++ /dev/null @@ -1,11 +0,0 @@ -from odoo import models - - -class SaleOrderBatch(models.Model): - _inherit = "sale.order.batch" - - def action_recompute_products(self): - for batch in self: - batch.product_ids.unlink() - for line in batch.sale_order_line_ids: - line._update_batch_product() 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 86544de..2bf71a3 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 @@ -11,6 +11,14 @@ class SaleOrderBatchProduct(models.Model): 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") + @api.depends("sale_order_line_ids.product_uom_max_qty") + def _compute_product_uom_max_qty(self): + for product in self: + if product.sale_order_line_ids: + product.product_uom_max_qty = sum(product.sale_order_line_ids.mapped("product_uom_max_qty")) + else: + product.product_uom_max_qty = False + @api.depends("sale_order_line_ids.product_uom_qty") def _compute_open_packagin_qty(self): for product in self: @@ -21,14 +29,6 @@ class SaleOrderBatchProduct(models.Model): 0 if open_packaging_qty == product.product_packaging_qty else open_packaging_qty ) - @api.depends("sale_order_line_ids.product_uom_max_qty") - def _compute_product_uom_max_qty(self): - for product in self: - if product.sale_order_line_ids: - product.product_uom_max_qty = sum(product.sale_order_line_ids.mapped("product_uom_max_qty")) - else: - product.product_uom_max_qty = 0 - @api.depends("open_packaging_qty", "product_packaging_qty") def _compute_open_packagin_state(self): for product in self: 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 d6ff040..f392b00 100644 --- a/nfu_sale_order_batch_packaging/models/sale_order_line.py +++ b/nfu_sale_order_batch_packaging/models/sale_order_line.py @@ -25,25 +25,18 @@ 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.order_id.batch_id: - batch_id = line.batch_id - product_id = line.product_id - precision_rounding = line.product_id.uom_id.rounding - precision_digits = len(str(precision_rounding).split(".")[1]) - batch_lines = ( - self.env["sale.order.line"] - .sudo() - .search([("batch_id", "=", batch_id.id), ("product_id", "=", product_id.id)]) - ) - line.batch_uom_qty = sum(batch_lines.mapped("product_uom_qty")) - line.batch_uom_max_qty = round(sum(batch_lines.mapped("product_uom_max_qty")), precision_digits) + 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 line.batch_id and line.product_packaging_id: + 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( 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 d70a098..9a3f400 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 @@ -1,15 +1,5 @@ - - Regenerate Products - - - code - - for batch in records: - batch.action_recompute_products() - - sale.order.batch.form.product.min_max_qty sale.order.batch diff --git a/sale_order_batch/models/sale_order_batch_product.py b/sale_order_batch/models/sale_order_batch_product.py index 33dcb0f..3f07556 100644 --- a/sale_order_batch/models/sale_order_batch_product.py +++ b/sale_order_batch/models/sale_order_batch_product.py @@ -32,7 +32,6 @@ class SaleOrderBatchProduct(models.Model): readonly=False, precompute=True, domain="[('sales', '=', True), ('product_id','=',product_id)]", - check_company=True, ) product_packaging_qty = fields.Float(compute="_compute_product_packaging_qty") diff --git a/sale_order_batch/views/sale_order_batch_product_views.xml b/sale_order_batch/views/sale_order_batch_product_views.xml index f366f9f..20bff33 100644 --- a/sale_order_batch/views/sale_order_batch_product_views.xml +++ b/sale_order_batch/views/sale_order_batch_product_views.xml @@ -23,8 +23,13 @@ - + + diff --git a/sale_order_batch/views/sale_order_batch_views.xml b/sale_order_batch/views/sale_order_batch_views.xml index c0bb798..dd80a76 100644 --- a/sale_order_batch/views/sale_order_batch_views.xml +++ b/sale_order_batch/views/sale_order_batch_views.xml @@ -122,11 +122,12 @@ widget="section_and_note_one2many" attrs="{'readonly': [('state', 'in', ('closed'))]}" > - + +