From e6fae76b1484167bb78ccd2206e0dbb8e5ccb1d9 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Thu, 3 Sep 2020 09:02:08 +0200 Subject: [PATCH 1/2] stock_vertical_lift: make pkg compute more solid Somehow sometimes you can get a move line without product while computing product packaging in inventory. Make it more defensive and skip packaging rendering if no product is there. --- stock_vertical_lift/models/vertical_lift_operation_base.py | 6 ++++-- .../models/vertical_lift_operation_inventory.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/stock_vertical_lift/models/vertical_lift_operation_base.py b/stock_vertical_lift/models/vertical_lift_operation_base.py index c96e78c997f9..c6404353fb44 100644 --- a/stock_vertical_lift/models/vertical_lift_operation_base.py +++ b/stock_vertical_lift/models/vertical_lift_operation_base.py @@ -229,6 +229,8 @@ def button_release(self): self.next_step() def _render_product_packagings(self, product): + if not product: + return "" return self.env["ir.qweb"].render( "stock_vertical_lift.packagings", self._prepare_values_for_product_packaging(product), @@ -343,10 +345,10 @@ def on_barcode_scanned(self, barcode): @api.depends("current_move_line_id.product_id.packaging_ids") def _compute_product_packagings(self): for record in self: - if not record.current_move_line_id: + product = record.mapped("current_move_line_id.product_id") + if not product: record.product_packagings = "" continue - product = record.current_move_line_id.product_id content = self._render_product_packagings(product) record.product_packagings = content diff --git a/stock_vertical_lift/models/vertical_lift_operation_inventory.py b/stock_vertical_lift/models/vertical_lift_operation_inventory.py index 5d9eadaa6326..21dc2332b873 100644 --- a/stock_vertical_lift/models/vertical_lift_operation_inventory.py +++ b/stock_vertical_lift/models/vertical_lift_operation_inventory.py @@ -143,10 +143,10 @@ def _compute_tray_data(self): @api.depends("current_inventory_line_id.product_id.packaging_ids") def _compute_product_packagings(self): for record in self: - if not record.current_inventory_line_id: + product = record.mapped("current_inventory_line_id.product_id") + if not product: record.product_packagings = "" continue - product = record.current_inventory_line_id.product_id content = self._render_product_packagings(product) record.product_packagings = content From 36c97ca649c6248646a61d8df910fa3573ac8be1 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Thu, 3 Sep 2020 13:08:52 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- stock_vertical_lift/models/vertical_lift_operation_base.py | 2 +- stock_vertical_lift/models/vertical_lift_operation_inventory.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stock_vertical_lift/models/vertical_lift_operation_base.py b/stock_vertical_lift/models/vertical_lift_operation_base.py index c6404353fb44..5b9dc84d7ed2 100644 --- a/stock_vertical_lift/models/vertical_lift_operation_base.py +++ b/stock_vertical_lift/models/vertical_lift_operation_base.py @@ -345,7 +345,7 @@ def on_barcode_scanned(self, barcode): @api.depends("current_move_line_id.product_id.packaging_ids") def _compute_product_packagings(self): for record in self: - product = record.mapped("current_move_line_id.product_id") + product = record.current_move_line_id.product_id if not product: record.product_packagings = "" continue diff --git a/stock_vertical_lift/models/vertical_lift_operation_inventory.py b/stock_vertical_lift/models/vertical_lift_operation_inventory.py index 21dc2332b873..93805a4a19ba 100644 --- a/stock_vertical_lift/models/vertical_lift_operation_inventory.py +++ b/stock_vertical_lift/models/vertical_lift_operation_inventory.py @@ -143,7 +143,7 @@ def _compute_tray_data(self): @api.depends("current_inventory_line_id.product_id.packaging_ids") def _compute_product_packagings(self): for record in self: - product = record.mapped("current_inventory_line_id.product_id") + product = record.current_inventory_line_id.product_id if not product: record.product_packagings = "" continue