Commit c4f658a5 by Félicie

Merge branch 'dev_cooperatic' into 3292-alert-message-barrecode

parents be9db336 5916f6b2
Pipeline #2264 passed with stage
in 1 minute 25 seconds
...@@ -1589,7 +1589,8 @@ function send() { ...@@ -1589,7 +1589,8 @@ function send() {
// Save current step updated data // Save current step updated data
orders[order_id].previous_steps_data = {}; orders[order_id].previous_steps_data = {};
orders[order_id].previous_steps_data[reception_status] = { orders[order_id].previous_steps_data[reception_status] = {
updated_products: orders[order_id].updated_products || [] updated_products: orders[order_id].updated_products || [],
user_comments: user_comments
}; };
orders[order_id].reception_status = updateType; orders[order_id].reception_status = updateType;
......
...@@ -13,6 +13,7 @@ from openpyxl.styles import Alignment ...@@ -13,6 +13,7 @@ from openpyxl.styles import Alignment
from reception.models import CagetteReception from reception.models import CagetteReception
from outils.common import OdooAPI from outils.common import OdooAPI
from outils.common import CouchDB
from members.models import CagetteUser from members.models import CagetteUser
from products.models import CagetteProduct from products.models import CagetteProduct
...@@ -260,9 +261,7 @@ def save_error_report(request): ...@@ -260,9 +261,7 @@ def save_error_report(request):
try: try:
for i, order in enumerate(data['orders']) : for i, order in enumerate(data['orders']) :
# list of temp files: 1 report per order & group # 1 report per order & 1 for the group
data['orders'][i]['temp_file_name'] = "temp/" + order['name'] + "_rapport-reception_temp.xlsx"
group_ids.append(order['id']) group_ids.append(order['id'])
orders_name_elts.append(order['name']) orders_name_elts.append(order['name'])
...@@ -286,40 +285,53 @@ def save_error_report(request): ...@@ -286,40 +285,53 @@ def save_error_report(request):
'date_order': data['orders'][0]['date_order'], 'date_order': data['orders'][0]['date_order'],
'amount_total': data['group_amount_total'], 'amount_total': data['group_amount_total'],
'updated_products': data['updated_products'], 'updated_products': data['updated_products'],
'temp_file_name': temp_group_file_name,
'group_ids': group_ids 'group_ids': group_ids
} }
data['orders'].append(group_order) data['orders'].append(group_order) # group "order" has to be last in orders list
else: else:
coop_logger.info("data['orders'] is a single PO (not inside group)") coop_logger.info("data['orders'] is a single PO (not inside group)")
except Exception as e2: except Exception as e2:
coop_logger.error("Save reception report : Error while create group_order %s", str(e2)) coop_logger.error("Save reception report : Error while create group_order %s", str(e2))
# Save qties & comments after step 1 # no action needed after step 1
if data['update_type'] == 'qty_valid': if data['update_type'] == 'qty_valid':
pass # removed, keep check to ensure transition process
# Create report with data from steps 1 & 2
elif data['update_type'] == 'br_valid':
c_db = CouchDB(arg_db='reception')
concat_updated_products = []
concat_user_comments = ''
for order in data['orders']: for order in data['orders']:
try: try:
wb = Workbook() data_qties = {}
ws = wb.active data_comment_s1 = ""
ws.title = "Commande " + order['name']
ws.append(['type', if 'group_ids' in order :
'nom_contenu', # For groups, concatenate orders step 1 data
'supplier_code', step_1_data = {
'barcode', 'updated_products': concat_updated_products,
'old_qty', 'user_comments': concat_user_comments
'product_qty', }
'price_unit', else:
'supplier_shortage']) # Read step 1 data from couch db document
order_id = f"order_{order['name'].split('PO')[1]}"
order_doc = c_db.getDocById(order_id)
# If in group add group name
if len(data['orders']) > 1:
ws.append(['group', orders_name])
try: try:
if 'updated_products' in order: step_1_data = order_doc['previous_steps_data']['False']
for product in order['updated_products']: except KeyError:
# Don't store products with same qties continue # No step 1 data
if 'updated_products' in step_1_data:
# Concatenate updated products from all orders
if 'group_ids' not in order :
concat_updated_products = concat_updated_products + step_1_data['updated_products']
for product in step_1_data['updated_products']:
# Don't store products with unchanged qties in step 1 data
if product['old_qty'] != product['product_qty']: if product['old_qty'] != product['product_qty']:
if 'supplier_code' in product: if 'supplier_code' in product:
supplier_code = str(product['supplier_code']) supplier_code = str(product['supplier_code'])
...@@ -331,63 +343,28 @@ def save_error_report(request): ...@@ -331,63 +343,28 @@ def save_error_report(request):
else: else:
supplier_shortage = '' supplier_shortage = ''
ws.append(['produit', product_name = product['product_id'][1]
product['product_id'][1], data_qties[product_name] = {
supplier_code, 'nom_contenu' : product_name,
str(product['barcode']), 'supplier_code' : supplier_code,
product['old_qty'], 'barcode' : str(product['barcode']),
product['product_qty'], 'old_qty' : product['old_qty'],
product['price_unit'], 'product_qty' : product['product_qty'],
supplier_shortage]) 'price_unit' : product['price_unit'],
except Exception as exp: 'supplier_shortage' : supplier_shortage
coop_logger.error("Error while updating products in report : %s", str(exp)) }
if ('user_comments' in data) and data['user_comments'] != "":
ws.append( ['commentaire', data['user_comments']] )
else:
ws.append( ['commentaire', 'Aucun commentaire.'] )
# Save file if 'user_comments' in step_1_data:
wb.save(filename=order['temp_file_name']) # Get user comments from all orders (same for all group orders)
except Exception as e3: if 'group_ids' not in order\
coop_logger.error("Save reception report : Error while create order Workbook %s", str(e3)) and step_1_data['user_comments'] != ""\
and concat_user_comments != step_1_data['user_comments']:
concat_user_comments = step_1_data['user_comments']
data_comment_s1 = step_1_data['user_comments'] if step_1_data['user_comments'] != "" else 'Aucun commentaire.'
# Create report with data from steps 1 & 2 except Exception as e:
elif data['update_type'] == 'br_valid': data_comment_s1 = "Données de l'étape 1 manquantes (erreur : " + str(e) + ")"
for order in data['orders']:
# Read step 1 data from temp file
data_qties = {}
data_comment_s1 = ""
group_name = ""
# Try to find temp file
try:
wb2 = load_workbook(order['temp_file_name'])
ws = wb2.active
for row in ws.iter_rows(min_row=2, values_only=True):
if row[0] == 'produit':
# products info
data_qties[row[1]] = {
'nom_contenu' : row[1],
'supplier_code' : row[2],
'barcode' : row[3],
'old_qty' : row[4],
'product_qty' : row[5],
'price_unit' : row[6],
'supplier_shortage' : row[7]
}
elif row[0] == 'group':
group_name = row[1] # group's orders name : Unused
elif row[0] == 'commentaire':
data_comment_s1 = row[1] # user comments
# Clear step 1 temp file
os.remove(order['temp_file_name'])
except Exception as e4:
coop_logger.error("Save reception report : reloading first step xlsx file %s", str(e4))
data_comment_s1 = "Données de la première étape absentes !"
# Add data from step 2 # Add data from step 2
data_full = [] data_full = []
......
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