Commit 6b4f9909 by Yvon Kerdoncuff

factorize method calling action_validate, rework it and use it as a replacement…

factorize method calling action_validate, rework it and use it as a replacement of api calls using removed action_done odoo stock inventory method
parent dd55db61
Pipeline #3918 canceled with stage
......@@ -367,7 +367,7 @@ class CagetteInventory(models.Model):
missed.append({'product': p, 'msg': str(e)})
if len(missed) == 0:
api.execute('stock.inventory', 'action_done', [inv])
CagetteInventory.stock_inventory_action_validate(inv)
done.append('Closed inventory')
return {'missed': missed, 'unchanged': unchanged, 'done': done}
......@@ -416,26 +416,12 @@ class CagetteInventory(models.Model):
missed.append({'product': p, 'msg': str(e)})
# Set inventory as 'done' even if some products missed
res = api.execute('stock.inventory', 'action_validate', [inv])
if not res:
CagetteInventory.stock_inventory_action_validate(inv)
done.append('Closed inventory')
else:
action_validate_issue = "Action validate returned something."
coop_logger.error(action_validate_issue)
errors.append(action_validate_issue)
if isinstance(res, dict) and 'name' in res:
coop_logger.error('Action validate wanted to return wizard named %s which is not possible from third-party app.', res['name'])
error.extend([
'Action validate wanted to return wizard named :',
res['name'],
'which is not possible from third-party app.'
])
else: #well, in that case, just try to print the value returned by res to help debugging...
coop_logger.error(res)
errors.append(res)
except Exception as e:
if not (MARSHALL_ERROR in str(e)):
coop_logger.error("update_stock_with_shelf_inventory_data %s",str(e))
coop_logger.error("update_products_stock %s", str(e))
errors.append(str(e))
return {'errors': errors,
......@@ -445,6 +431,23 @@ class CagetteInventory(models.Model):
'inv_id': inv}
@staticmethod
def stock_inventory_action_validate(inv):
api = OdooAPI()
res = api.execute('stock.inventory', 'action_validate', [inv])
if res: # if action_validate returns something, there is something wrong
if isinstance(res, dict) and 'name' in res:
want_to_return_wiz_err_msg\
= ('Action validate wanted to return wizard named '
+ res['name'] + ' which is not possible from third-party app.')
coop_logger.error(want_to_return_wiz_err_msg)
raise Exception(want_to_return_wiz_err_msg)
else:
action_validate_generic_issue = "Action validate returned something."
coop_logger.error(action_validate_issue)
raise Exception(action_validate_generic_issue)
@staticmethod
def raz_archived_stock():
missed = []
done = []
......@@ -469,7 +472,7 @@ class CagetteInventory(models.Model):
done.append({'product': p, 'id': li})
except Exception as e:
missed.append({'product': p, 'msg': str(e)})
api.execute('stock.inventory', 'action_done', [inv])
CagetteInventory.stock_inventory_action_validate(inv)
return {'missed': missed, 'done': done}
@staticmethod
......@@ -497,7 +500,7 @@ class CagetteInventory(models.Model):
done.append({'product': p, 'id': li})
except Exception as e:
missed.append({'product': p, 'msg': str(e)})
api.execute('stock.inventory', 'action_done', [inv])
CagetteInventory.stock_inventory_action_validate(inv)
return {'missed': missed, 'done': done}
@staticmethod
......@@ -524,7 +527,7 @@ class CagetteInventory(models.Model):
done.append({'product': p, 'id': li})
except Exception as e:
missed.append({'product': p, 'msg': str(e)})
api.execute('stock.inventory', 'action_done', [inv])
CagetteInventory.stock_inventory_action_validate(inv)
return {'missed': missed, 'done': done}
......
......@@ -328,13 +328,13 @@ class CagetteStock(models.Model):
invLi = o_api.create('stock.inventory.line', fields)
if not (invLi is None):
try:
o_api.execute('stock.inventory', 'action_done', [inv])
except:
print ('Probleme action_done avec ' + str(data['idArticle']))
CagetteInventory.stock_inventory_action_validate(inv)
except Exception as e:
print('Probleme action_validate avec ' + str(data['idArticle']) + ' ' + str(e))
else:
print('Probleme invLi avec ' + str(data['idArticle']))
else:
print ('Probleme inv avec ' + str(data['idArticle']))
print('Probleme inv avec ' + str(data['idArticle']))
return inv
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment