Commit e425a6e9 by Colin MORAND

modifié : reception/models.py

	modifié :         reception/static/js/reception_produits.js
	modifié :         reception/urls.py
	modifié :         reception/views.py
parent bc0bdfc8
Pipeline #1200 failed with stage
in 1 minute 22 seconds
......@@ -31,12 +31,13 @@ class CagetteReception(models.Model):
pids.append(int(r['purchase_id'][0]))
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", 'create_uid']
# 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']]]
orders = api.search_read('purchase.order', c, f)
print(orders)
except Exception as e:
print(str(e))
return orders
......@@ -48,6 +49,25 @@ class CagetteReception(models.Model):
def get_order_lines_by_po(id_po, nullQty=False):
"""Return all purchases order lines linked with purchase order id in Odoo."""
return Order(id_po).get_lines(withNullQty=nullQty)
def get_mail_create_po(id_po):
"""Return name et email from id_po of order"""
try:
api = OdooAPI()
f = ["create_uid"]
c = [['id', '=', id_po]]
res = api.search_read('purchase.order', c, f)
f = ["email", "display_name"]
c = [['user_ids', '=', int(res[0]['create_uid'][0])]]
res = api.search_read('res.partner', c, f)
except Exception as e:
print(str(e))
return res
def implies_scale_file_generation(self):
answer = False
......
......@@ -1214,7 +1214,37 @@ function send() {
error_report_data.group_amount_total += orders[i].amount_total;
error_report_data.orders.push(orders[i]);
}
//Create list of articl with no barcode
no_barcode_list = [];
for (var i = 0; i < list_processed.length; i++) {
if (list_processed[i].product_qty != 0 && (list_processed[i].barcode == false || list_processed[i].barcode == null || list_processed[i].barcode == "")) {
no_barcode_list.push([list_processed[i]["product_id"][0], list_processed[i]["product_id"][1]]);
}
}
data_send_no_barcode={
"order" : orders[order_data['id_po']],
"no_barcode_list" : no_barcode_list
}
// Send of articl with no barcode to mail send
if (no_barcode_list.length > 0){
$.ajax({
type: "POST",
url: "../send_mail_no_barcode",
dataType: "json",
traditional: true,
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data_send_no_barcode),
success: function() {},
error: function() {
alert('Erreur dans l\'envoi des produite sont barre code.');
}
});
}
// Send request for error report
$.ajax({
type: "POST",
......@@ -1257,7 +1287,7 @@ function send() {
document.getElementById("nothingToDo").hidden = true;
barcodes_to_print = true;
} else if (list_processed[i].barcode == false || list_processed[i].barcode == null || list_processed[i].barcode == "") {
} /* else if (list_processed[i].barcode == false || list_processed[i].barcode == null || list_processed[i].barcode == "") {
// Products with no barcode
var node = document.createElement('li');
let textNode = document.createTextNode(list_processed[i]["product_id"][1]);
......@@ -1269,7 +1299,19 @@ function send() {
document.getElementById("barcodesEmpty").hidden = false;
document.getElementById("nothingToDo").hidden = true;
}
}
}*/
}
}
for (var i = 0; i < no_barcode_list.length; i++) {
var node = document.createElement('li');
let textNode = document.createTextNode(no_barcode_list[i]);
node.appendChild(textNode);
document.getElementById('barcodesEmpty_list').appendChild(node);
if (document.getElementById("barcodesEmpty").hidden) {
document.getElementById("barcodesEmpty").hidden = false;
document.getElementById("nothingToDo").hidden = true;
}
}
......
......@@ -16,5 +16,6 @@ urlpatterns = [
url(r'^reception_qtiesValidated', views.reception_qtiesValidated),
url(r'^reception_pricesValidated', views.reception_pricesValidated),
# url(r'^update_order_status/([0-9]+)$', views.tmp_update_order_status),
url(r'^po_process_picking$', views.po_process_picking)
url(r'^po_process_picking$', views.po_process_picking),
url(r'^send_mail_no_barcode', views.send_mail_no_barcode)
]
......@@ -170,6 +170,7 @@ def update_orders(request):
m = CagetteReception(order_id)
try:
for order_line in order['po']:
print(order_line)
if order_line['indicative_package'] is False:
m.remove_package_restriction(order_line)
......@@ -639,3 +640,39 @@ def reception_pricesValidated(request):
def po_process_picking(request):
res = CagetteReception.process_enqueued_po_to_finalyze()
return JsonResponse(res, safe=False)
def send_mail_no_barcode(request):
"""
Receive json data with liste of product with no barcode
Send mail to order maker
"""
from django.core.mail import send_mail
if request.method == 'POST':
data = None
try:
myJson = request.body
data = json.loads(myJson.decode())
data_partner = CagetteReception.get_mail_create_po(int(data['order']['id']))
msg = settings.NO_BARCODE_MAIL_MSG
for barcode in data["no_barcode_list"]:
msg = msg + ' -' + str(barcode[0]) + '---' + str(barcode[1])+ '\n'
send_mail(settings.NO_BARCODE_MAIL_SUBJECT.format(data['order']['name']),
msg.format(data_partner[0]['display_name'], data['order']['name'],data['order']['date_order'], data['order']['partner']),
settings.DEFAULT_FROM_EMAIL,
[data_partner[0]['email']],
fail_silently=False,)
except Exception as e1:
coop_logger.error("Send_mail_no_barcode : Unable to load data %s (%s)", str(e1), str(myJson))
print(str(e1)+'\n'+ str(myJson))
return JsonResponse("ok", safe=False)
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