[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) <nim@odoo.com>
This commit is contained in:
Swapnesh Shah
2020-05-15 09:14:06 +00:00
committed by Nicolas Martinelli
parent 0cc6a76891
commit bea1613f11
2 changed files with 5 additions and 3 deletions
+1
View File
@@ -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 """
@@ -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