From bea1613f11e1def53bc3c558f82b8edc4633091a Mon Sep 17 00:00:00 2001 From: Swapnesh Shah Date: Mon, 16 Mar 2020 18:11:15 +0000 Subject: [PATCH] [FIX] stock,stock_account: fix undefined variable and return True Fixes #29694 Close #47204 Fix #37554 Before this commit, There was Traceback on calling this method w/o any inventories as variable `res` was not declared but Returned or Calling this methord over RPC will raise TypeError as this method does not returns amything. In this commit, We return True at original `post_inventory` method and Declare `res` to prevent undefined variable. closes odoo/odoo#51320 X-original-commit: cfb2f00ae2fcbe33184d76383e3b624700101a75 Signed-off-by: Nicolas Martinelli (nim) --- addons/stock/models/stock_inventory.py | 1 + addons/stock_account/models/stock_inventory.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/stock/models/stock_inventory.py b/addons/stock/models/stock_inventory.py index 08ec874c996..9fa8f655e2a 100644 --- a/addons/stock/models/stock_inventory.py +++ b/addons/stock/models/stock_inventory.py @@ -127,6 +127,7 @@ class Inventory(models.Model): # as they will be moved to inventory loss, and other quants will be created to the encoded quant location. This is a normal behavior # as quants cannot be reuse from inventory location (users can still manually move the products before/after the inventory if they want). self.mapped('move_ids').filtered(lambda move: move.state != 'done')._action_done() + return True def action_check(self): """ Checks the inventory and computes the stock move to do """ diff --git a/addons/stock_account/models/stock_inventory.py b/addons/stock_account/models/stock_inventory.py index ce00ed251c5..03522076eae 100644 --- a/addons/stock_account/models/stock_inventory.py +++ b/addons/stock_account/models/stock_inventory.py @@ -35,10 +35,11 @@ class StockInventory(models.Model): return action_data def post_inventory(self): + res = True acc_inventories = self.filtered(lambda inventory: inventory.accounting_date) for inventory in acc_inventories: - super(StockInventory, inventory.with_context(force_period_date=inventory.accounting_date)).post_inventory() + res = super(StockInventory, inventory.with_context(force_period_date=inventory.accounting_date)).post_inventory() other_inventories = self - acc_inventories if other_inventories: - super(StockInventory, other_inventories).post_inventory() - + res = super(StockInventory, other_inventories).post_inventory() + return res