From de672595dfd6c16c94099b477cb1ca30f3dc88e5 Mon Sep 17 00:00:00 2001 From: Andreas Zoellner Date: Mon, 12 Apr 2021 11:59:44 +0200 Subject: [PATCH 1/3] [FIX] Break from a loop --- stock_inventory_merge/models/stock_inventory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stock_inventory_merge/models/stock_inventory.py b/stock_inventory_merge/models/stock_inventory.py index 2d87f49e..740cf86d 100644 --- a/stock_inventory_merge/models/stock_inventory.py +++ b/stock_inventory_merge/models/stock_inventory.py @@ -74,7 +74,7 @@ def complete_with_zero(self): item ) == self._get_inventory_line_keys(product_line): found = True - continue + break if not found: # Add the line, if inventory line was not found product_line["product_qty"] = 0 From 89bf633fceb7317f1771e170397a1a95ed61894d Mon Sep 17 00:00:00 2001 From: Andreas Zoellner Date: Mon, 12 Apr 2021 12:02:45 +0200 Subject: [PATCH 2/3] [FIX] Assign new "Complete With Zero" lines to current inventory When clicking on button "Complete With Zero" in an inventory form view, the created inventory lines have to be added to the current inventory. --- stock_inventory_merge/models/stock_inventory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stock_inventory_merge/models/stock_inventory.py b/stock_inventory_merge/models/stock_inventory.py index 740cf86d..20dbed2c 100644 --- a/stock_inventory_merge/models/stock_inventory.py +++ b/stock_inventory_merge/models/stock_inventory.py @@ -78,7 +78,7 @@ def complete_with_zero(self): if not found: # Add the line, if inventory line was not found product_line["product_qty"] = 0 - product_line["inventory_id"] = self.id + product_line["inventory_id"] = inventory.id line_obj.create(product_line) @api.multi From 93ebd394c00ac8a9c8cf1426a3a573baf89c35d7 Mon Sep 17 00:00:00 2001 From: Andreas Zoellner Date: Tue, 22 Jun 2021 16:13:58 +0200 Subject: [PATCH 3/3] [FIX] Prevent "You cannot have two inventory adjustments..." error The duplicate lines need to be deleted *before* writing the total quantity on the kept line, as the write method checks for duplicates, which may trigger that "You cannot have two inventory adjustments..." exception. --- stock_inventory_merge/models/stock_inventory.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/stock_inventory_merge/models/stock_inventory.py b/stock_inventory_merge/models/stock_inventory.py index 20dbed2c..f12b2f76 100644 --- a/stock_inventory_merge/models/stock_inventory.py +++ b/stock_inventory_merge/models/stock_inventory.py @@ -109,14 +109,18 @@ def action_merge_duplicated_line(self): uom_obj.browse(default_uom_id), ) - # Update the first line with the sumed quantity - keeped_line = line_obj.browse(keeped_line_id) - keeped_line.write({"product_qty": sum_quantity}) - # Delete all the other lines line_ids.remove(keeped_line_id) line_obj.browse(line_ids).unlink() + # Update the first line with the sumed quantity + # Note: This has to be done *after* deleting the other lines, + # because the `write()` calls the `_check_no_duplicate_line()` + # which may trigger the "You cannot have two inventory + # adjustments..." exception. + keeped_line = line_obj.browse(keeped_line_id) + keeped_line.write({"product_qty": sum_quantity}) + # Custom Section @api.multi def _get_duplicated_line_ids(self):