From c30a567f0f4d4bff4ba797db6e6132c9615380de Mon Sep 17 00:00:00 2001 From: david Date: Fri, 4 Jun 2021 11:41:05 +0200 Subject: [PATCH] [MIG] stock_picking_report_valued_sale_mrp: Migration to 13.0 --- stock_picking_report_valued_sale_mrp/__manifest__.py | 2 +- .../models/stock_move.py | 6 +++++- .../models/stock_move_line.py | 11 +++++++++-- .../readme/CONTRIBUTORS.rst | 1 + .../report/stock_picking_report_valued.xml | 6 +++--- .../tests/test_stock_picking_report_valued_mrp.py | 4 ++++ 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/stock_picking_report_valued_sale_mrp/__manifest__.py b/stock_picking_report_valued_sale_mrp/__manifest__.py index d626354..af7fe8d 100644 --- a/stock_picking_report_valued_sale_mrp/__manifest__.py +++ b/stock_picking_report_valued_sale_mrp/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Valued picking linked with MRP Kits", "summary": "Allow to summarize the picking related with the selled kits", - "version": "12.0.1.0.2", + "version": "13.0.1.0.0", "development_status": "Beta", "category": "Warehouse Management", "website": "https://github.com/OCA/stock-logistics-reporting", diff --git a/stock_picking_report_valued_sale_mrp/models/stock_move.py b/stock_picking_report_valued_sale_mrp/models/stock_move.py index 1b8fa3e..4b459b1 100644 --- a/stock_picking_report_valued_sale_mrp/models/stock_move.py +++ b/stock_picking_report_valued_sale_mrp/models/stock_move.py @@ -12,7 +12,11 @@ class StockMove(models.Model): were manually changed, it could lead to inconsistencies""" self.ensure_one() sale_line = self.sale_line_id - if not sale_line or not sale_line.product_id._is_phantom_bom(): + if ( + not sale_line + or not sale_line.product_id.get_components() + or sale_line.product_id.ids == sale_line.product_id.get_components() + ): return 0 component_demand = sum( sale_line.move_ids.filtered( diff --git a/stock_picking_report_valued_sale_mrp/models/stock_move_line.py b/stock_picking_report_valued_sale_mrp/models/stock_move_line.py index 9bf6778..67278c4 100644 --- a/stock_picking_report_valued_sale_mrp/models/stock_move_line.py +++ b/stock_picking_report_valued_sale_mrp/models/stock_move_line.py @@ -23,8 +23,11 @@ class StockMoveLine(models.Model): @api.depends("sale_line") def _compute_phantom_product_id(self): """Relate every line with its kit product""" + self.write({"phantom_product_id": False}) for line in self.filtered( - lambda x: x.sale_line and x.sale_line.product_id._is_phantom_bom() + lambda x: x.sale_line + and x.sale_line.product_id.get_components() + and x.sale_line.product_id.ids != x.sale_line.product_id.get_components() ): line.phantom_product_id = line.sale_line.product_id @@ -33,7 +36,11 @@ class StockMoveLine(models.Model): avoid duplicate the amounts. We also need to recompute the total amounts according to the corresponding delivered kits""" super()._compute_sale_order_line_fields() - kit_lines = self.filtered("phantom_product_id") + pickings = self.mapped("picking_id") + kit_lines = pickings.move_line_ids.filtered("phantom_product_id") + pickings.move_line_ids.write( + {"phantom_line": False, "phantom_delivered_qty": 0.0} + ) for sale_line in kit_lines.mapped("sale_line"): move_lines = kit_lines.filtered(lambda x: x.sale_line == sale_line) # Deduct the kit quantity from the first component in the picking. diff --git a/stock_picking_report_valued_sale_mrp/readme/CONTRIBUTORS.rst b/stock_picking_report_valued_sale_mrp/readme/CONTRIBUTORS.rst index 94b6ba9..1bed2df 100644 --- a/stock_picking_report_valued_sale_mrp/readme/CONTRIBUTORS.rst +++ b/stock_picking_report_valued_sale_mrp/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * `Tecnativa `_: * David Vidal + * Carlos Roca diff --git a/stock_picking_report_valued_sale_mrp/report/stock_picking_report_valued.xml b/stock_picking_report_valued_sale_mrp/report/stock_picking_report_valued.xml index b66f4c9..60ecdc5 100644 --- a/stock_picking_report_valued_sale_mrp/report/stock_picking_report_valued.xml +++ b/stock_picking_report_valued_sale_mrp/report/stock_picking_report_valued.xml @@ -28,17 +28,17 @@ /> not move_line.phantom_line diff --git a/stock_picking_report_valued_sale_mrp/tests/test_stock_picking_report_valued_mrp.py b/stock_picking_report_valued_sale_mrp/tests/test_stock_picking_report_valued_mrp.py index 0ac2989..2b13685 100644 --- a/stock_picking_report_valued_sale_mrp/tests/test_stock_picking_report_valued_mrp.py +++ b/stock_picking_report_valued_sale_mrp/tests/test_stock_picking_report_valued_mrp.py @@ -69,3 +69,7 @@ class TestStockPickingValuedMrp(TestStockPickingValued): self.assertAlmostEqual(self.order_out_picking.amount_untaxed, 149.5) self.assertAlmostEqual(self.order_out_picking.amount_tax, 14.95) self.assertAlmostEqual(self.order_out_picking.amount_total, 164.45) + # Run the report to detect hidden errors + self.env.ref("stock.action_report_delivery").render_qweb_html( + self.order_out_picking.ids + )