Commit 9426d217 by François C.

Improve Reception errors tracking and received data backup

parent 26a8c1ff
Pipeline #1053 passed with stage
in 23 seconds
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):
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
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)
except Exception as e:
print (str(e))
print(str(e))
return orders
def get_order_unprocessable_products(id_po):
......@@ -63,7 +63,7 @@ class CagetteReception(models.Model):
"""Update purchase.order.line with qty data and/or price"""
result = None
try:
f={}
f = {}
if updateType == "qty_valid" or updateType == "br_valid":
f['package_qty'] = pakageQty
......@@ -76,7 +76,8 @@ class CagetteReception(models.Model):
res = self.o_api.update('purchase.order.line', idOnLine, f)
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
return result
......
......@@ -28,7 +28,7 @@ def home(request):
"""Page de selection de la commande suivant un fournisseurs"""
# Get grouped orders stored on the server
try:
try:
with open('temp/grouped_order.json', 'r') as json_file:
saved_groups = json.load(json_file)
except Exception:
......@@ -132,7 +132,7 @@ def data_validation(request):
return JsonResponse({'error': str(e)}, status=500)
def save_order_group(request):
"""
"""
When an order group is created, save it to force group these orders later.
Raise an error if one of the orders is already in a group.
"""
......@@ -156,11 +156,11 @@ def save_order_group(request):
# All good, save group
with open('temp/grouped_order.json', 'w+') as json_file:
saved_groups.append(order_ids)
saved_groups.append(order_ids)
json.dump(saved_groups, json_file)
msg = 'Group saved'
return JsonResponse({'message': msg})
return JsonResponse({'message': msg})
except Exception as e:
print(str(e))
return JsonResponse({'message': str(e)}, status=500)
......@@ -177,6 +177,16 @@ def update_orders(request):
if request.is_ajax():
if request.method == 'PUT':
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 = {}
print_labels = True
if hasattr(settings, 'RECEPTION_SHELF_LABEL_PRINT'):
......@@ -232,6 +242,8 @@ def update_orders(request):
except KeyError:
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]['errors'] = errors
......@@ -258,7 +270,8 @@ def update_orders(request):
except Exception as e:
# no saved groups
print(str(e))
else:
coop_logger.error("update_orders errors : %s", str(errors))
rep = JsonResponse(answer_data, safe=False)
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