Commit 6aa391b6 by François C. Committed by Alexis Aoun

Improve Reception errors tracking and received data backup

parent de06a817
Received reception data are stored in this directory (could be desactivated if RECEPTION_DATA_BACKUP is set to False in config.py)
\ No newline at end of file
...@@ -34,11 +34,11 @@ class CagetteReception(models.Model): ...@@ -34,11 +34,11 @@ class CagetteReception(models.Model):
f=["id","name","date_order", "partner_id", "date_planned", "amount_untaxed", "amount_total", "x_reception_status"] f=["id","name","date_order", "partner_id", "date_planned", "amount_untaxed", "amount_total", "x_reception_status"]
# Only get orders that need to be treated in Reception # Only get orders that need to be treated in Reception
c=[['id', 'in', pids], ["x_reception_status", "in", [False, 'qty_valid', 'valid_pending', 'br_valid', 'error_pack_op', 'uprice_valid']]] c = [['id', 'in', pids], ["x_reception_status", "in", [False, 'qty_valid', 'valid_pending', 'error_pack_op', 'uprice_valid']]]
orders = api.search_read('purchase.order', c, f) orders = api.search_read('purchase.order', c, f)
except Exception as e: except Exception as e:
print (str(e)) print(str(e))
return orders return orders
def get_order_unprocessable_products(id_po): def get_order_unprocessable_products(id_po):
...@@ -63,7 +63,7 @@ class CagetteReception(models.Model): ...@@ -63,7 +63,7 @@ class CagetteReception(models.Model):
"""Update purchase.order.line with qty data and/or price""" """Update purchase.order.line with qty data and/or price"""
result = None result = None
try: try:
f={} f = {}
if updateType == "qty_valid" or updateType == "br_valid": if updateType == "qty_valid" or updateType == "br_valid":
f['package_qty'] = pakageQty f['package_qty'] = pakageQty
...@@ -76,7 +76,8 @@ class CagetteReception(models.Model): ...@@ -76,7 +76,8 @@ class CagetteReception(models.Model):
res = self.o_api.update('purchase.order.line', idOnLine, f) res = self.o_api.update('purchase.order.line', idOnLine, f)
result = True result = True
except: except Exception as e:
coop_logger.error("update_line : %s (fields values = %s, line_id = %s)",str(e), str(f), str(idOnLine))
result = False result = False
return result return result
......
...@@ -179,6 +179,16 @@ def update_orders(request): ...@@ -179,6 +179,16 @@ def update_orders(request):
if request.is_ajax(): if request.is_ajax():
if request.method == 'PUT': if request.method == 'PUT':
data = json.loads(request.body.decode()) data = json.loads(request.body.decode())
if getattr(settings, 'RECEPTION_DATA_BACKUP', True) is True:
try:
file_name = ''
for order_id, order in data['orders'].items():
file_name += str(order_id) + '_'
file_name += data['update_type'] + '_' + str(round(time.time() * 1000)) + '.json'
with open('data/receptions_backup/' + file_name, 'w') as data_file:
json.dump(data, data_file)
except Exception as ef:
coop_logger.error("Enable to save data : %s (data = %s)",str(ef), str(data))
answer_data = {} answer_data = {}
print_labels = True print_labels = True
if hasattr(settings, 'RECEPTION_SHELF_LABEL_PRINT'): if hasattr(settings, 'RECEPTION_SHELF_LABEL_PRINT'):
...@@ -234,6 +244,8 @@ def update_orders(request): ...@@ -234,6 +244,8 @@ def update_orders(request):
except KeyError: except KeyError:
coop_logger.info("No line to update.") coop_logger.info("No line to update.")
except Exception as e:
coop_logger.error("update_orders : %s", str(e))
answer_data[order_id]['order_data'] = order answer_data[order_id]['order_data'] = order
answer_data[order_id]['errors'] = errors answer_data[order_id]['errors'] = errors
...@@ -260,7 +272,8 @@ def update_orders(request): ...@@ -260,7 +272,8 @@ def update_orders(request):
except Exception as e: except Exception as e:
# no saved groups # no saved groups
print(str(e)) print(str(e))
else:
coop_logger.error("update_orders errors : %s", str(errors))
rep = JsonResponse(answer_data, safe=False) rep = JsonResponse(answer_data, safe=False)
return rep return rep
......
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