From a5c4855a6b5c05a27184a55261ca01966a91248e Mon Sep 17 00:00:00 2001 From: Ujas Dubal <udu@odoo.com> Date: Mon, 13 Jan 2020 10:01:46 +0000 Subject: [PATCH] [FIX] stock_account: Added default type for 'account.move' line. This commit will fixed the error when product has some stock quants and product category with 'Automated' valuation method, is set to that product. ============================== Steps to product the above mentioned error: 1. Create product with any category which has 'Manual' valuation method. 2. Update 'On Hand' quantity for the same product. 3. Create product category with valuation method set to 'Automated'. 4. Now set the above product category to the same product which you created in step 1. 5. And Click on the save button. ============================== Also edit the test case. closes odoo/odoo#43755 Task: 2155804 X-original-commit: c62dea6a7ce6b63f708831707811e922cd6bddd0 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com> --- addons/stock_account/models/product.py | 2 ++ addons/stock_account/tests/test_stockvaluationlayer.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index 638e39e4d097..e9888e6b49b8 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -487,6 +487,7 @@ class ProductProduct(models.Model): 'credit': abs(value), 'product_id': product.id, })], + 'type': 'entry', } move_vals_list.append(move_vals) return move_vals_list @@ -522,6 +523,7 @@ class ProductProduct(models.Model): 'credit': abs(value), 'product_id': product.id, })], + 'type': 'entry', } move_vals_list.append(move_vals) return move_vals_list diff --git a/addons/stock_account/tests/test_stockvaluationlayer.py b/addons/stock_account/tests/test_stockvaluationlayer.py index 1dd1a9fc2831..cd9098c03846 100644 --- a/addons/stock_account/tests/test_stockvaluationlayer.py +++ b/addons/stock_account/tests/test_stockvaluationlayer.py @@ -778,7 +778,10 @@ class TestStockValuationChangeValuation(TestStockValuationCommon): 'property_stock_journal': self.stock_journal.id, }) - self.product1.categ_id = cat2 + # Try to change the product category with a `default_type` key in the context and + # check it doesn't break the account move generation. + self.product1.with_context(default_type='product').categ_id = cat2 + self.assertEqual(self.product1.categ_id, cat2) self.assertEqual(self.product1.value_svl, 100) self.assertEqual(self.product1.quantity_svl, 10) -- GitLab