Commit aaf35830 by Arnaud B

Merge remote-tracking branch 'origin/dev_cooperatic' into ticket_820

# Conflicts:
#	reception/views.py
parents 6580b448 f520fc11
Pipeline #1035 passed with stage
in 21 seconds
...@@ -102,4 +102,8 @@ ENTRANCE_COME_FOR_SHOPING_MSG = "Hey coucou toi ! Cet été nous sommes plus de ...@@ -102,4 +102,8 @@ ENTRANCE_COME_FOR_SHOPING_MSG = "Hey coucou toi ! Cet été nous sommes plus de
UNSUBSCRIBED_MSG = 'Vous êtes désincrit·e, merci de remplir <a href="https://docs.google.com/forms/d/e/1FAIpQLSfPiC2PkSem9x_B5M7LKpoFNLDIz0k0V5I2W3Mra9AnqnQunw/viewform">ce formulaire</a> pour vous réinscrire sur un créneau.<br />Vous pouvez également contacter le Bureau des Membres en remplissant <a href="https://docs.google.com/forms/d/e/1FAIpQLSeZP0m5-EXPVJxEKJk6EjwSyZJtnbiGdYDuAeFI3ENsHAOikg/viewform">ce formulaire</a>' UNSUBSCRIBED_MSG = 'Vous êtes désincrit·e, merci de remplir <a href="https://docs.google.com/forms/d/e/1FAIpQLSfPiC2PkSem9x_B5M7LKpoFNLDIz0k0V5I2W3Mra9AnqnQunw/viewform">ce formulaire</a> pour vous réinscrire sur un créneau.<br />Vous pouvez également contacter le Bureau des Membres en remplissant <a href="https://docs.google.com/forms/d/e/1FAIpQLSeZP0m5-EXPVJxEKJk6EjwSyZJtnbiGdYDuAeFI3ENsHAOikg/viewform">ce formulaire</a>'
CONFIRME_PRESENT_BTN = 'Clique ici pour valider ta présence' CONFIRME_PRESENT_BTN = 'Clique ici pour valider ta présence'
RECEPTION_PB = "Ici, vous pouvez signaler toute anomalie lors d'une réception, les produits non commandés, cassés ou pourris. \
Merci d'indiquer un maximum d'informations, le nom du produit et son code barre. \
Dans le cas de produits déteriorés, merci d'envoyer une photo avec votre téléphone à [Adresse_email]"
...@@ -29,11 +29,13 @@ class CagetteReception(models.Model): ...@@ -29,11 +29,13 @@ class CagetteReception(models.Model):
if res and len(res) > 0: if res and len(res) > 0:
for r in res: for r in res:
pids.append(int(r['purchase_id'][0])) pids.append(int(r['purchase_id'][0]))
if len(pids): if len(pids):
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']]] c=[['id', 'in', pids], ["x_reception_status", "in", [False, 'qty_valid', 'valid_pending', 'br_valid', '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))
......
...@@ -374,17 +374,40 @@ $(document).ready(function() { ...@@ -374,17 +374,40 @@ $(document).ready(function() {
title:"Statut", title:"Statut",
className:"dt-body-center", className:"dt-body-center",
render: function (data) { render: function (data) {
switch (data) { switch (data) {
case 'qty_valid': case 'qty_valid':
return "<span class='btn--success'>Mettre à jour les prix</span>"; return "<span class='btn--success'>Mettre à jour les prix</span>";
case 'br_valid': case 'br_valid':
return "<span class='btn'><i class='far fa-check-circle'></i> Réception OK</span>"; return "<span class='btn'><i class='far fa-check-circle'></i> Réception OK</span>";
default: case 'False':
return "<span class='btn--primary'>Compter les produits</span>"; return "<span class='btn--primary'>Compter les produits</span>";
case 'done':
return "<span class='btn'><i class='far fa-check-circle'></i> Terminé</span>";
case 'uprice_valid':
return "<span class='btn--primary'>Mise à jour du prix OK</span>";
case "valid_pending":
return "<span class='btn--info'>En attente de validation</span>";
case 'legacy':
return "<span class='btn--success'>Legacy</span>";
case 'error_pack_op':
return "<span class='btn--danger'>Erreur pack operations</span>";
case 'error_transfer':
return "<span class='btn--danger'>Erreur de transfert</span>";
case 'error_picking':
return "<span class='btn--danger'>Erreur validation quantité</span>";
case '/error_uprice':
return "<span class='btn--danger'>Erreur mise à jour du prix</span>";
default:
return "<span class='btn--warning'>Status inconnu : " + data + "</span>";
} }
}, },
width: "20%" width: "20%"
} } //error_transfert ou error_pack_op
], ],
dom: 'rtip', dom: 'rtip',
order: [ order: [
......
...@@ -1351,7 +1351,7 @@ function openErrorReport() { ...@@ -1351,7 +1351,7 @@ function openErrorReport() {
var textarea = document.getElementById("error_report"); var textarea = document.getElementById("error_report");
textarea.value = user_comments; textarea.value = (user_comments != undefined) ? user_comments : "";
textarea.focus(); textarea.focus();
textarea.setSelectionRange(textarea.value.length, textarea.value.length); textarea.setSelectionRange(textarea.value.length, textarea.value.length);
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
from outils.common_imports import * from outils.common_imports import *
from outils.for_view_imports import * from outils.for_view_imports import *
from django.views.generic import View from django.views.generic import View
from django.http import HttpResponse
from django.http import JsonResponse
import os import os
from datetime import date from datetime import date
from openpyxl import Workbook from openpyxl import Workbook
...@@ -13,6 +15,9 @@ from outils.common import OdooAPI ...@@ -13,6 +15,9 @@ from outils.common import OdooAPI
from members.models import CagetteUser from members.models import CagetteUser
from products.models import CagetteProduct from products.models import CagetteProduct
# create temp directory if needed
if not os.path.exists("temp"):
os.mkdir("temp")
def as_text(value): def as_text(value):
""" Utils """ """ Utils """
return str(value) if value is not None else "" return str(value) if value is not None else ""
...@@ -74,11 +79,10 @@ def produits(request, id): ...@@ -74,11 +79,10 @@ def produits(request, id):
} }
fixed_barcode_prefix = '0490' fixed_barcode_prefix = '0490'
if hasattr(settings, 'RECEPTION_PB'):
if hasattr(settings, 'RECEPTION_PB_EMAIL'): context['RECEPTION_PB'] = settings.RECEPTION_PB
context['RECEPTION_PB_EMAIL'] = settings.RECEPTION_PB_EMAIL
else: else:
context['RECEPTION_PB_EMAIL'] = ' [mail à renseigner dans config.py]' context['RECEPTION_PB'] = ' [texte à renseigner dans config.py]'
if hasattr(settings, 'FIXED_BARCODE_PREFIX'): if hasattr(settings, 'FIXED_BARCODE_PREFIX'):
fixed_barcode_prefix = settings.FIXED_BARCODE_PREFIX fixed_barcode_prefix = settings.FIXED_BARCODE_PREFIX
...@@ -165,6 +169,9 @@ def update_orders(request): ...@@ -165,6 +169,9 @@ def update_orders(request):
import requests import requests
# don't print barcode which begin with these codes
noprint_list = ["0493", "0492", "0499"]
rep = HttpResponse("Not") rep = HttpResponse("Not")
if request.is_ajax(): if request.is_ajax():
if request.method == 'PUT': if request.method == 'PUT':
...@@ -212,8 +219,8 @@ def update_orders(request): ...@@ -212,8 +219,8 @@ def update_orders(request):
except Exception as e: except Exception as e:
errors.append('error registering shortage on p'+order_line['id']+':'+str(e)) errors.append('error registering shortage on p'+order_line['id']+':'+str(e))
# Print etiquette with new price if update if successful # 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']: 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: try:
tools_url = settings.TOOLS_SERVER + '/products/label_print/' tools_url = settings.TOOLS_SERVER + '/products/label_print/'
tools_url += str(order_line['product_tmpl_id']) + '/' tools_url += str(order_line['product_tmpl_id']) + '/'
...@@ -235,6 +242,7 @@ def update_orders(request): ...@@ -235,6 +242,7 @@ def update_orders(request):
# Remove order's group # Remove order's group
try: try:
if os.path.exists('temp/grouped_order.json'):
with open('temp/grouped_order.json', 'r') as json_file: with open('temp/grouped_order.json', 'r') as json_file:
saved_groups = json.load(json_file) saved_groups = json.load(json_file)
...@@ -292,6 +300,7 @@ def save_error_report(request): ...@@ -292,6 +300,7 @@ def save_error_report(request):
orders_partner = orders_partner + ', ' orders_partner = orders_partner + ', '
orders_partner = orders_partner + order['partner'] + ' du ' + order['date_order'] orders_partner = orders_partner + order['partner'] + ' du ' + order['date_order']
# If group of orders # If group of orders
if len(data['orders']) > 1 : if len(data['orders']) > 1 :
temp_group_file_name = "temp/" + orders_name + "_rapport-reception_temp.xlsx" temp_group_file_name = "temp/" + orders_name + "_rapport-reception_temp.xlsx"
...@@ -309,6 +318,7 @@ def save_error_report(request): ...@@ -309,6 +318,7 @@ def save_error_report(request):
data['orders'].append(group_order) data['orders'].append(group_order)
# Save qties & comments after step 1 # Save qties & comments after step 1
if data['update_type'] == 'qty_valid': if data['update_type'] == 'qty_valid':
for order in data['orders']: for order in data['orders']:
...@@ -328,8 +338,8 @@ def save_error_report(request): ...@@ -328,8 +338,8 @@ def save_error_report(request):
# If in group add group name # If in group add group name
if len(data['orders']) > 1 : if len(data['orders']) > 1 :
ws.append( ['group', orders_name] ) ws.append( ['group', orders_name] )
try: try:
if 'updated_products' in order:
for product in order['updated_products']: for product in order['updated_products']:
# Don't store products with same qties # Don't store products with same qties
if product['old_qty'] != product['product_qty']: if product['old_qty'] != product['product_qty']:
...@@ -351,10 +361,9 @@ def save_error_report(request): ...@@ -351,10 +361,9 @@ def save_error_report(request):
product['product_qty'], product['product_qty'],
product['price_unit'], product['price_unit'],
supplier_shortage] ) supplier_shortage] )
except: except Exception as exp:
# no updated products, do nothing print("Error while updating products")
pass print(exp)
if ('user_comments' in data) and data['user_comments'] != "": if ('user_comments' in data) and data['user_comments'] != "":
ws.append( ['commentaire', data['user_comments']] ) ws.append( ['commentaire', data['user_comments']] )
else: else:
...@@ -363,6 +372,8 @@ def save_error_report(request): ...@@ -363,6 +372,8 @@ def save_error_report(request):
# Save file # Save file
wb.save(filename=order['temp_file_name']) wb.save(filename=order['temp_file_name'])
# Create report with data from steps 1 & 2 # Create report with data from steps 1 & 2
else: else:
for order in data['orders']: for order in data['orders']:
...@@ -397,7 +408,6 @@ def save_error_report(request): ...@@ -397,7 +408,6 @@ def save_error_report(request):
os.remove(order['temp_file_name']) os.remove(order['temp_file_name'])
except: except:
data_comment_s1 = "Rapport de la première étape absent !" data_comment_s1 = "Rapport de la première étape absent !"
# Add data from step 2 # Add data from step 2
data_full = [] data_full = []
error_total = 0 error_total = 0
...@@ -409,6 +419,7 @@ def save_error_report(request): ...@@ -409,6 +419,7 @@ def save_error_report(request):
# Concatenate products info from each step # Concatenate products info from each step
try: try:
if "updated_products" in order:
for product in order['updated_products']: for product in order['updated_products']:
if 'supplier_code' in product: if 'supplier_code' in product:
supplier_code = str(product['supplier_code']) supplier_code = str(product['supplier_code'])
...@@ -453,10 +464,10 @@ def save_error_report(request): ...@@ -453,10 +464,10 @@ def save_error_report(request):
error_total_abs += abs(item['error_line']) error_total_abs += abs(item['error_line'])
data_full.append(item) data_full.append(item)
except: except Exception as exp:
# no updated products, do nothing # no updated products, do nothing
pass print("Error while updating products")
print(exp)
# Add remaining products, the ones edited only in step 1 # Add remaining products, the ones edited only in step 1
for product in data_qties.values(): for product in data_qties.values():
item = { item = {
...@@ -486,7 +497,6 @@ def save_error_report(request): ...@@ -486,7 +497,6 @@ def save_error_report(request):
wb = Workbook() wb = Workbook()
ws = wb.active ws = wb.active
ws.title = "Commande " + order['name'] ws.title = "Commande " + order['name']
# Group # Group
if 'group_ids' in order : if 'group_ids' in order :
ws.append( ['Rapport de réception d\'un groupe de commandes'] ) ws.append( ['Rapport de réception d\'un groupe de commandes'] )
...@@ -528,7 +538,6 @@ def save_error_report(request): ...@@ -528,7 +538,6 @@ def save_error_report(request):
round(product['expected_amount'], 2), round(product['expected_amount'], 2),
round(product['error_line'], 2), round(product['error_line'], 2),
product['supplier_shortage']] ) product['supplier_shortage']] )
ws.append( [] ) ws.append( [] )
ws.append( ['Montant total de l\'erreur :', '', '', '', '', '', '', '', round(error_total, 2)] ) ws.append( ['Montant total de l\'erreur :', '', '', '', '', '', '', '', round(error_total, 2)] )
ws.append( ['Montant total en valeur absolue :', '', '', '', '', '', '', '', round(error_total_abs, 2)] ) ws.append( ['Montant total en valeur absolue :', '', '', '', '', '', '', '', round(error_total_abs, 2)] )
...@@ -563,7 +572,6 @@ def save_error_report(request): ...@@ -563,7 +572,6 @@ def save_error_report(request):
top_left_cell.alignment = Alignment(vertical="top") top_left_cell.alignment = Alignment(vertical="top")
top_left_cell = ws['B'+str(merge_begin)] top_left_cell = ws['B'+str(merge_begin)]
top_left_cell.alignment = Alignment(vertical="top") top_left_cell.alignment = Alignment(vertical="top")
# "Auto fit" columns width to content # "Auto fit" columns width to content
for column_cells in ws.columns: for column_cells in ws.columns:
length = max(len(as_text(cell.value)) for cell in column_cells) length = max(len(as_text(cell.value)) for cell in column_cells)
...@@ -572,23 +580,23 @@ def save_error_report(request): ...@@ -572,23 +580,23 @@ def save_error_report(request):
length = 20 length = 20
ws.column_dimensions[column_cells[3].column_letter].width = length ws.column_dimensions[column_cells[3].column_letter].width = length
# Save file # Save file
fileName = "temp/" + order['name'] + "_rapport-reception.xlsx" fileName = "temp/" + order['name'] + "_rapport-reception.xlsx"
try:
wb.save(filename=fileName) wb.save(filename=fileName)
except Exception as exp:
print("Error while saving file %s"%fileName)
print(str(exp))
#Attach file to order #Attach file to order
if 'group_ids' in order : # group report if 'group_ids' in order : # group report
# Attach group report to each order # Attach group report to each order
for group_item_id in order['group_ids'] : for group_item_id in order['group_ids'] :
m = CagetteReception(group_item_id) m = CagetteReception(group_item_id)
m.attach_file(fileName, False) m.attach_file(fileName, False)
os.remove(fileName) os.remove(fileName)
else: else:
m = CagetteReception(order['id']) m = CagetteReception(order['id'])
m.attach_file(fileName) m.attach_file(fileName)
return JsonResponse("ok", safe=False) return JsonResponse("ok", safe=False)
def reception_FAQ(request): def reception_FAQ(request):
......
...@@ -27,7 +27,7 @@ class CagetteSales(models.Model): ...@@ -27,7 +27,7 @@ class CagetteSales(models.Model):
# Get payment lines # Get payment lines
cond = [['statement_id', 'in', statements]] cond = [['statement_id', 'in', statements]]
fields = ["partner_id", "amount", "journal_id", "create_date", "date"] fields = ["partner_id", "amount", "journal_id", "create_date", "date"]
payments = self.o_api.search_read('account.bank.statement.line', cond, fields, order="create_date ASC") payments = self.o_api.search_read('account.bank.statement.line', cond, fields, order="create_date ASC", limit=50000)
item = None item = None
try: try:
......
...@@ -120,9 +120,7 @@ ...@@ -120,9 +120,7 @@
<hr /> <hr />
<p class="txtleft"> <p class="txtleft">
Ici, vous pouvez signaler toute anomalie lors d'une réception, les produits non commandés, cassés ou pourris. {{RECEPTION_PB}}
Merci d'indiquer un maximum d'informations, le nom du produit et son code barre.
Dans le cas de produits déteriorés, merci d'envoyer une photo avec votre téléphone à <strong>{{RECEPTION_PB_EMAIL}}</strong>
</p> </p>
<br> <br>
<textarea id="error_report"></textarea> <textarea id="error_report"></textarea>
......
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