Commit 520b3262 by François C.

Merge branch 'fix_reception_912' into 'dev_cooperatic'

Improve Reception errors tracking and received data backup

See merge request !29
parents 26a8c1ff 9426d217
Pipeline #1054 passed with stage
in 21 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
......
......@@ -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