Commit c63e52f5 by François C.

Change way of printing shelf labels after prices change (resulting of reception data)

parent a9f292ef
Pipeline #2622 failed with stage
in 1 minute 26 seconds
......@@ -101,7 +101,7 @@ class Order(models.Model):
for l in res_bc:
for p in res:
if p['product_id'][0] == l['id']:
coop_logger.info(str(l))
# coop_logger.info(str(l))
p['shelf_sortorder'] = 'X'
p['barcode'] = l['barcode']
p['product_tmpl_id'] = l['product_tmpl_id'][0]
......
......@@ -75,7 +75,7 @@ class CagetteReception(models.Model):
def implies_scale_file_generation(self):
answer = False
lines_data = Order(self.id).get_lines()
bc_pattern = re.compile('^0493|0499')
bc_pattern = re.compile('^0493|0499') # TODO : Adjust for other pattern (such as Supercoop)
for l in lines_data['lines']:
if not (bc_pattern.match(str(l['barcode'])) is None):
answer = True
......@@ -196,7 +196,32 @@ class CagetteReception(models.Model):
success = True
else:
success = False
return {'errors': errors, 'processed': processed, 'success': success}
return {'errors': errors, 'processed': processed, 'success': success, 'lines': order_lines}
def print_shelf_labels_for_updated_prices(self, lines):
import requests
# don't print barcode which begin with these codes
noprint_list = ["0493", "0492", "0499"]
pids = []
for l in lines:
pids.append(l['product_id'][0])
products_to_print = self.o_api.search_read('product.product', [['id','in', pids]], ['product_tmpl_id', 'barcode', 'to_print'])
if products_to_print:
to_reset = []
for p_to_print in products_to_print:
coop_logger.info('candidate to print %s', str(p_to_print))
if p_to_print['to_print'] is True and p_to_print['barcode'][:4] not in noprint_list:
try:
tools_url = settings.TOOLS_SERVER + '/products/label_print/'
tools_url += str(p_to_print['product_tmpl_id'][0])
requests.get(tools_url)
to_reset.append(p_to_print['id'])
except Exception as e:
coop_logger.error("Shelf label printing : %s",str(e))
if len(to_reset) > 0:
self.o_api.update('product.product', to_reset, {'to_print': 0})
def finalyze_picking(self):
......@@ -236,6 +261,8 @@ class CagetteReception(models.Model):
new_x_reception_status += '/error_uprice'
if new_x_reception_status == '':
new_x_reception_status = 'done'
self.print_shelf_labels_for_updated_prices(price_update['lines'])
if result != 'already done':
self.o_api.update('purchase.order', [self.id], {'x_reception_status': new_x_reception_status})
......@@ -277,6 +304,7 @@ class CagetteReception(models.Model):
print_label = m.implies_scale_file_generation()
if fp == 'processed' or fp == 'already done':
os.remove(p['file'])
processed.append({p['id']: fp})
os.remove('data/po_in_process_' + str(p['id']))
if print_label is True:
......
......@@ -221,14 +221,15 @@ def update_orders(request):
errors.append('error registering shortage on p'+order_line['id']+':'+str(e))
# Print etiquette with new price if update if successful and barcode is authorized
if (print_labels is True) and (update is True) and (data['update_type'] == 'br_valid') and order_line['new_shelf_price'] and order_line['barcode'][:4] not in noprint_list:
try:
tools_url = settings.TOOLS_SERVER + '/products/label_print/'
tools_url += str(order_line['product_tmpl_id']) + '/'
tools_url += str(order_line['new_shelf_price'])
requests.get(tools_url)
except Exception as e:
coop_logger.error("Shelf label printing : %s",str(e))
# Printing at that point is inhibited because of random ununderstandable wrong new_shelf_price
# if (print_labels is True) and (update is True) and (data['update_type'] == 'br_valid') and order_line['new_shelf_price'] and order_line['barcode'][:4] not in noprint_list:
# try:
# tools_url = settings.TOOLS_SERVER + '/products/label_print/'
# tools_url += str(order_line['product_tmpl_id']) + '/'
# tools_url += str(order_line['new_shelf_price'])
# requests.get(tools_url)
# except Exception as e:
# coop_logger.error("Shelf label printing : %s",str(e))
except KeyError:
coop_logger.info("No line to update.")
......@@ -303,8 +304,8 @@ def save_error_report(request):
}
data['orders'].append(group_order) # group "order" has to be last in orders list
else:
coop_logger.info("data['orders'] is a single PO (not inside group)")
# else:
# coop_logger.info("data['orders'] is a single PO (not inside group)")
except Exception as e2:
coop_logger.error("Save reception report : Error while create group_order %s", str(e2))
......
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