Commit 191b57a5 by Damien Moulard

Merge branch 'aide_a_la_commande' into dev_cooperatic

parents 32fe6120 e94b0ad6
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
position: relative; position: relative;
} }
.page_content { .page_content, .login_area {
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
...@@ -154,6 +154,10 @@ ...@@ -154,6 +154,10 @@
cursor: pointer; cursor: pointer;
} }
.product_not_from_supplier:hover {
background-color: #c7cace;
}
.product_name, .supplier_name, .product_npa { .product_name, .supplier_name, .product_npa {
font-weight: bold; font-weight: bold;
} }
......
...@@ -187,7 +187,7 @@ function check_products_data() { ...@@ -187,7 +187,7 @@ function check_products_data() {
"Vérfication des informations produits...", "Vérfication des informations produits...",
{ {
globalPosition:"top left", globalPosition:"top left",
className: "warning" className: "info"
} }
); );
...@@ -823,6 +823,8 @@ function create_orders() { ...@@ -823,6 +823,8 @@ function create_orders() {
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
data: JSON.stringify(orders_data), data: JSON.stringify(orders_data),
success: (result) => { success: (result) => {
$('#created_orders_area').empty();
// Display new orders // Display new orders
for (let new_order of result.res.created) { for (let new_order of result.res.created) {
const supplier_name = suppliers_list.find(s => s.id == new_order.supplier_id).display_name; const supplier_name = suppliers_list.find(s => s.id == new_order.supplier_id).display_name;
...@@ -1037,12 +1039,11 @@ function _compute_product_data(product) { ...@@ -1037,12 +1039,11 @@ function _compute_product_data(product) {
let days_covered = 0; let days_covered = 0;
if (product.daily_conso !== 0) { if (product.daily_conso !== 0) {
qty_not_covered = product.daily_conso * order_doc.coverage_days - product.qty_available - product.incoming_qty - purchase_qty; qty_not_covered = product.daily_conso * order_doc.coverage_days - product.qty_available - product.incoming_qty - purchase_qty;
days_covered = qty_not_covered / product.daily_conso;
qty_not_covered = -Math.ceil(qty_not_covered); // round up, so if a value is not fully covered display it qty_not_covered = -Math.ceil(qty_not_covered); // round up, so if a value is not fully covered display it
qty_not_covered = (qty_not_covered > 0) ? 0 : qty_not_covered; // only display qty not covered (neg value) qty_not_covered = (qty_not_covered > 0) ? 0 : qty_not_covered; // only display qty not covered (neg value)
days_covered = -Math.ceil(days_covered); days_covered = (product.qty_available + product.incoming_qty + purchase_qty) / product.daily_conso;
days_covered = Math.floor(days_covered);
} }
item.qty_not_covered = qty_not_covered; item.qty_not_covered = qty_not_covered;
...@@ -1469,7 +1470,7 @@ function display_total_values() { ...@@ -1469,7 +1470,7 @@ function display_total_values() {
let order_total_value = 0; let order_total_value = 0;
for (let supplier of selected_suppliers) { for (let supplier of selected_suppliers) {
$(`#pill_supplier_${supplier.id}`).find('.supplier_total_value').text(supplier.total_value); $(`#pill_supplier_${supplier.id}`).find('.supplier_total_value').text(parseFloat(supplier.total_value).toFixed(2));
order_total_value += supplier.total_value; order_total_value += supplier.total_value;
} }
...@@ -1637,243 +1638,250 @@ function init_pouchdb_sync() { ...@@ -1637,243 +1638,250 @@ function init_pouchdb_sync() {
$(document).ready(function() { $(document).ready(function() {
fingerprint = new Fingerprint({canvas: true}).get(); if (coop_is_connected()) {
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } }); $('#new_order_form').show();
$('#existing_orders_area').show();
openModal(); fingerprint = new Fingerprint({canvas: true}).get();
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } });
init_pouchdb_sync(); openModal();
// Main screen init_pouchdb_sync();
$("#coverage_form").on("submit", function(e) {
e.preventDefault(); // Main screen
if (is_time_to('submit_coverage_form', 1000)) { $("#coverage_form").on("submit", function(e) {
let val = $("#coverage_days_input").val(); e.preventDefault();
if (is_time_to('submit_coverage_form', 1000)) {
val = parseInt(val); let val = $("#coverage_days_input").val();
if (!isNaN(val)) { val = parseInt(val);
order_doc.coverage_days = val;
compute_products_coverage_qties(); if (!isNaN(val)) {
update_cdb_order(); order_doc.coverage_days = val;
update_main_screen(); compute_products_coverage_qties();
} else { update_cdb_order();
$("#coverage_days_input").val(order_doc.coverage_days); update_main_screen();
alert(`Valeur non valide pour le nombre de jours de couverture !`); } else {
$("#coverage_days_input").val(order_doc.coverage_days);
alert(`Valeur non valide pour le nombre de jours de couverture !`);
}
} }
} });
});
$("#supplier_form").on("submit", function(e) { $("#supplier_form").on("submit", function(e) {
e.preventDefault(); e.preventDefault();
if (is_time_to('add_product', 1000)) { if (is_time_to('add_product', 1000)) {
add_supplier(); add_supplier();
} }
}); });
$("#product_form").on("submit", function(e) { $("#product_form").on("submit", function(e) {
e.preventDefault(); e.preventDefault();
if (is_time_to('add_product', 1000)) { if (is_time_to('add_product', 1000)) {
add_product(); add_product();
} }
}); });
$("#do_inventory").on("click", function() { $("#do_inventory").on("click", function() {
if (is_time_to('generate_inventory', 1000)) { if (is_time_to('generate_inventory', 1000)) {
generate_inventory(); generate_inventory();
} }
}); });
$('#back_to_order_selection_from_main').on('click', function() { $('#back_to_order_selection_from_main').on('click', function() {
if (is_time_to('back_to_order_selection_from_main', 1000)) { if (is_time_to('back_to_order_selection_from_main', 1000)) {
back(); back();
} }
}); });
$('#create_orders').on('click', function() { $('#create_orders').on('click', function() {
if (is_time_to('create_orders', 1000)) { if (is_time_to('create_orders', 1000)) {
let modal_create_order = $('#templates #modal_create_order'); let modal_create_order = $('#templates #modal_create_order');
modal_create_order.find('.suppliers_date_planned_area').empty(); modal_create_order.find('.suppliers_date_planned_area').empty();
for (let supplier of selected_suppliers) {
let supplier_date_planned_template = $('#templates #modal_create_order__supplier_date_planned');
supplier_date_planned_template.find(".supplier_name").text(supplier.display_name); for (let supplier of selected_suppliers) {
supplier_date_planned_template.find(".modal_input_container").attr('id', `container_date_planned_supplier_${supplier.id}`); let supplier_date_planned_template = $('#templates #modal_create_order__supplier_date_planned');
modal_create_order.find('.suppliers_date_planned_area').append(supplier_date_planned_template.html());
}
openModal(
modal_create_order.html(),
() => {
if (is_time_to('validate_create_orders')) {
create_orders();
}
},
'Valider',
false
);
// Add id to input once modal is displayed
for (let supplier of selected_suppliers) {
$(`#modal #container_date_planned_supplier_${supplier.id}`).find(".supplier_date_planned").attr('id', `date_planned_supplier_${supplier.id}`);
}
$("#modal .supplier_date_planned")
.datepicker({
defaultDate: "+1d",
minDate: new Date()
})
.on('change', function() {
try {
// When date input changes, try to read date
$.datepicker.parseDate(date_format, $(this).val());
} catch {
alert('Date invalide');
$(this).val('');
}
});
}
return 0; supplier_date_planned_template.find(".supplier_name").text(supplier.display_name);
}); supplier_date_planned_template.find(".modal_input_container").attr('id', `container_date_planned_supplier_${supplier.id}`);
modal_create_order.find('.suppliers_date_planned_area').append(supplier_date_planned_template.html());
}
openModal(
modal_create_order.html(),
() => {
if (is_time_to('validate_create_orders')) {
create_orders();
}
},
'Valider',
false
);
// Add id to input once modal is displayed
for (let supplier of selected_suppliers) {
$(`#modal #container_date_planned_supplier_${supplier.id}`).find(".supplier_date_planned").attr('id', `date_planned_supplier_${supplier.id}`);
}
$("#modal .supplier_date_planned")
.datepicker({
defaultDate: "+1d",
minDate: new Date()
})
.on('change', function() {
try {
// When date input changes, try to read date
$.datepicker.parseDate(date_format, $(this).val());
} catch {
alert('Date invalide');
$(this).val('');
}
});
}
return 0;
});
$.datepicker.regional['fr'] = { $.datepicker.regional['fr'] = {
monthNames: [ monthNames: [
'Janvier', 'Janvier',
'Fevrier', 'Fevrier',
'Mars', 'Mars',
'Avril', 'Avril',
'Mai', 'Mai',
'Juin', 'Juin',
'Juillet', 'Juillet',
'Aout', 'Aout',
'Septembre', 'Septembre',
'Octobre', 'Octobre',
'Novembre', 'Novembre',
'Decembre' 'Decembre'
], ],
dayNamesMin: [ dayNamesMin: [
'Di', 'Di',
'Lu', 'Lu',
'Ma', 'Ma',
'Me', 'Me',
'Je', 'Je',
'Ve', 'Ve',
'Sa' 'Sa'
], ],
dateFormat: date_format dateFormat: date_format
}; };
$.datepicker.setDefaults($.datepicker.regional['fr']); $.datepicker.setDefaults($.datepicker.regional['fr']);
// Order selection screen // Order selection screen
update_order_selection_screen(); update_order_selection_screen();
$("#new_order_form").on("submit", function(e) { $("#new_order_form").on("submit", function(e) {
e.preventDefault(); e.preventDefault();
if (is_time_to('submit_new_order_form', 1000)) { if (is_time_to('submit_new_order_form', 1000)) {
create_cdb_order(); create_cdb_order();
} }
}); });
// Orders created screen // Orders created screen
$('#back_to_order_selection_from_orders_created').on('click', function() { $('#back_to_order_selection_from_orders_created').on('click', function() {
if (is_time_to('back_to_order_selection_from_orders_created', 1000)) { if (is_time_to('back_to_order_selection_from_orders_created', 1000)) {
switch_screen('order_selection', 'orders_created'); switch_screen('order_selection', 'orders_created');
} }
}); });
// Get suppliers // Get suppliers
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: "/orders/get_suppliers", url: "/orders/get_suppliers",
dataType:"json", dataType:"json",
traditional: true, traditional: true,
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
success: function(data) { success: function(data) {
suppliers_list = data.res; suppliers_list = data.res;
// Set up autocomplete on supplier input // Set up autocomplete on supplier input
$("#supplier_input").autocomplete({ $("#supplier_input").autocomplete({
source: suppliers_list.map(a => a.display_name) source: suppliers_list.map(a => a.display_name)
}); });
}, },
error: function(data) { error: function(data) {
err = {msg: "erreur serveur lors de la récupération des fournisseurs", ctx: 'get_suppliers'}; err = {msg: "erreur serveur lors de la récupération des fournisseurs", ctx: 'get_suppliers'};
if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') { if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') {
err.msg += ' : ' + data.responseJSON.error; err.msg += ' : ' + data.responseJSON.error;
}
report_JS_error(err, 'orders');
closeModal();
alert('Erreur lors de la récupération des fournisseurs, rechargez la page plus tard');
} }
report_JS_error(err, 'orders'); });
closeModal(); //Get products
alert('Erreur lors de la récupération des fournisseurs, rechargez la page plus tard'); var accentMap = {
} "á": "a",
}); "à": "a",
"â": "a",
"é": "e",
"è": "e",
"ê": "e",
"ë": "e",
"ç": "c",
"ù": "u",
"ü": "u",
"ö": "o"
};
//Get products var normalize = function(term) {
var accentMap = { var ret = "";
"á": "a",
"à": "a",
"â": "a",
"é": "e",
"è": "e",
"ê": "e",
"ë": "e",
"ç": "c",
"ù": "u",
"ü": "u",
"ö": "o"
};
var normalize = function(term) { for (var i = 0; i < term.length; i++) {
var ret = ""; ret += accentMap[ term.charAt(i) ] || term.charAt(i);
}
for (var i = 0; i < term.length; i++) { return ret;
ret += accentMap[ term.charAt(i) ] || term.charAt(i); };
}
return ret; $.ajax({
}; type: 'GET',
url: "/products/simple_list",
dataType:"json",
traditional: true,
contentType: "application/json; charset=utf-8",
success: function(data) {
products_list = data.list;
$.ajax({ // Set up autocomplete on product input
type: 'GET', $("#product_input").autocomplete({
url: "/products/simple_list", source: function(request, response) {
dataType:"json", var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
traditional: true,
contentType: "application/json; charset=utf-8",
success: function(data) {
products_list = data.list;
// Set up autocomplete on product input response($.grep(products_list.map(a => a.display_name), function(value) {
$("#product_input").autocomplete({ value = value.label || value.value || value;
source: function(request, response) {
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
response($.grep(products_list.map(a => a.display_name), function(value) { return matcher.test(value) || matcher.test(normalize(value));
value = value.label || value.value || value; }));
},
position: {collision: "flip" }
});
return matcher.test(value) || matcher.test(normalize(value)); closeModal();
})); },
}, error: function(data) {
position: {collision: "flip" } err = {msg: "erreur serveur lors de la récupération des articles", ctx: 'get_products'};
}); if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') {
err.msg += ' : ' + data.responseJSON.error;
}
report_JS_error(err, 'orders');
closeModal(); closeModal();
}, alert('Erreur lors de la récupération des articles, rechargez la page plus tard');
error: function(data) {
err = {msg: "erreur serveur lors de la récupération des articles", ctx: 'get_products'};
if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') {
err.msg += ' : ' + data.responseJSON.error;
} }
report_JS_error(err, 'orders'); });
} else {
closeModal(); $('#not_connected_content').show();
alert('Erreur lors de la récupération des articles, rechargez la page plus tard'); }
}
});
}); });
...@@ -148,7 +148,8 @@ class CagetteProduct(models.Model): ...@@ -148,7 +148,8 @@ class CagetteProduct(models.Model):
'product_purchase_ok': product["purchase_ok"], 'product_purchase_ok': product["purchase_ok"],
'price': price, 'price': price,
'base_price': price, 'base_price': price,
'package_qty': package_qty 'package_qty': package_qty,
'sequence': 1000 # lowest priority for the new suppliers
} }
res = api.create('product.supplierinfo', f) res = api.create('product.supplierinfo', f)
...@@ -503,8 +504,8 @@ class CagetteProducts(models.Model): ...@@ -503,8 +504,8 @@ class CagetteProducts(models.Model):
sales_average_params = { sales_average_params = {
'ids': ptids, 'ids': ptids,
# 'from': '2019-04-10', 'from': '2019-04-10',
# 'to': '2019-08-10', 'to': '2019-08-10',
} }
sales = CagetteProducts.get_template_products_sales_average(sales_average_params) sales = CagetteProducts.get_template_products_sales_average(sales_average_params)
......
...@@ -16,14 +16,20 @@ ...@@ -16,14 +16,20 @@
{% block content %} {% block content %}
<div class="page_body"> <div class="page_body">
<div id="select_order_content" class="page_content txtcenter"> <div id="select_order_content" class="page_content txtcenter">
<div class="login_area">
{% include "common/conn_admin.html" %}
</div>
<div id="new_order_area"> <div id="new_order_area">
<h2>Créer une nouvelle commande</h2> <h2>Créer une nouvelle commande</h2>
<form id="new_order_form"> <div class="txtcenter" id="not_connected_content" style="display:none;">
<p>Vous devez vous connecter avec un compte Odoo pour accéder au module d'aide à la commande.</p>
</div>
<form id="new_order_form" style="display:none;">
<input type="text" id="new_order_name" placeholder="Nom de la commande..."> <input type="text" id="new_order_name" placeholder="Nom de la commande...">
<button type="submit" class="btn btn--primary">Valider</button> <button type="submit" class="btn btn--primary">C'est parti !</button>
</form> </form>
</div> </div>
<div id="existing_orders_area"> <div id="existing_orders_area" style="display:none;">
<h2>Ou, continuer une commande en cours de création</h2> <h2>Ou, continuer une commande en cours de création</h2>
<div id="existing_orders"></div> <div id="existing_orders"></div>
</div> </div>
...@@ -34,9 +40,11 @@ ...@@ -34,9 +40,11 @@
<button type="button" class="btn--danger" id="back_to_order_selection_from_main"> <button type="button" class="btn--danger" id="back_to_order_selection_from_main">
<i class="fas fa-arrow-left"></i>&nbsp; Retour <i class="fas fa-arrow-left"></i>&nbsp; Retour
</button> </button>
<button type="button" class='btn--primary' id="do_inventory" style="display:none;"> <div class="rights_buttons">
Faire un inventaire <button type="button" class='btn--primary' id="do_inventory" style="display:none;">
</button> Faire un inventaire
</button>
</div>
</div> </div>
<div class="header txtcenter"> <div class="header txtcenter">
......
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