Commit 8e27f5d4 by Damien Moulard Committed by Alexis Aoun

AAC: linting

parent 53a5e9dc
...@@ -112,7 +112,7 @@ function add_product() { ...@@ -112,7 +112,7 @@ function add_product() {
products.unshift(data); products.unshift(data);
update_main_screen({'sort_order_dir':'desc'}); update_main_screen({'sort_order_dir':'desc'});
} else { } else {
alert("L'article n'a pas toutes les caractéristiques pour être ajouté.") alert("L'article n'a pas toutes les caractéristiques pour être ajouté.");
} }
$("#product_input").val(''); $("#product_input").val('');
}, },
...@@ -134,13 +134,17 @@ function add_product() { ...@@ -134,13 +134,17 @@ function add_product() {
* Set the computed qty for the first supplier only. * Set the computed qty for the first supplier only.
*/ */
function compute_products_coverage_qties() { function compute_products_coverage_qties() {
for (const [key, product] of Object.entries(products)) { for (const [
key,
product
] of Object.entries(products)) {
let purchase_qty_for_coverage = null; let purchase_qty_for_coverage = null;
// Durée couverture produit = (stock + qté entrante + qté commandée ) / conso quotidienne // Durée couverture produit = (stock + qté entrante + qté commandée ) / conso quotidienne
const stock = product.qty_available; const stock = product.qty_available;
const incoming_qty = product.incoming_qty; const incoming_qty = product.incoming_qty;
const daily_conso = product.daily_conso; const daily_conso = product.daily_conso;
purchase_qty_for_coverage = order_doc.coverage_days * daily_conso - stock - incoming_qty; purchase_qty_for_coverage = order_doc.coverage_days * daily_conso - stock - incoming_qty;
purchase_qty_for_coverage = (purchase_qty_for_coverage < 0) ? 0 : purchase_qty_for_coverage; purchase_qty_for_coverage = (purchase_qty_for_coverage < 0) ? 0 : purchase_qty_for_coverage;
...@@ -193,6 +197,7 @@ function add_supplier() { ...@@ -193,6 +197,7 @@ function add_supplier() {
selected_suppliers.push(supplier); selected_suppliers.push(supplier);
let url = "/orders/get_supplier_products"; let url = "/orders/get_supplier_products";
url += "?sid=" + encodeURIComponent(supplier.id); url += "?sid=" + encodeURIComponent(supplier.id);
// Fetch supplier products // Fetch supplier products
...@@ -265,7 +270,8 @@ function save_supplier_product_association(product, supplier, cell) { ...@@ -265,7 +270,8 @@ function save_supplier_product_association(product, supplier, cell) {
// If value is a number // If value is a number
if (isNaN(package_qty) || isNaN(price)) { if (isNaN(package_qty) || isNaN(price)) {
closeModal(); closeModal();
alert(`Les champs "Prix" et "Colisage" doivent être remplis et valides. L'association n'a pas été sauvegardée.`) alert(`Les champs "Prix" et "Colisage" doivent être remplis et valides. L'association n'a pas été sauvegardée.`);
return -1; return -1;
} }
...@@ -273,7 +279,7 @@ function save_supplier_product_association(product, supplier, cell) { ...@@ -273,7 +279,7 @@ function save_supplier_product_association(product, supplier, cell) {
product_tmpl_id: product.id, product_tmpl_id: product.id,
supplier_id: supplier.id, supplier_id: supplier.id,
package_qty: package_qty, package_qty: package_qty,
price: price, price: price
}; };
// Send request to create association // Send request to create association
...@@ -286,15 +292,15 @@ function save_supplier_product_association(product, supplier, cell) { ...@@ -286,15 +292,15 @@ function save_supplier_product_association(product, supplier, cell) {
data: JSON.stringify(data), data: JSON.stringify(data),
success: () => { success: () => {
// Save supplierinfo in product // Save supplierinfo in product
if (!'suppliersinfo' in product) { if (!('suppliersinfo' in product)) {
product.suppliersinfo = [] product.suppliersinfo = [];
} }
product.suppliersinfo.push({ product.suppliersinfo.push({
supplier_id: supplier.id, supplier_id: supplier.id,
package_qty: package_qty, package_qty: package_qty,
price: price price: price
}) });
// Save relation locally // Save relation locally
save_supplier_products(supplier, [product]); save_supplier_products(supplier, [product]);
...@@ -324,6 +330,8 @@ function save_supplier_product_association(product, supplier, cell) { ...@@ -324,6 +330,8 @@ function save_supplier_product_association(product, supplier, cell) {
alert('Erreur lors de la sauvegarde de l\'association. Veuillez ré-essayer plus tard.'); alert('Erreur lors de la sauvegarde de l\'association. Veuillez ré-essayer plus tard.');
} }
}); });
return 0;
} }
/** /**
...@@ -409,6 +417,7 @@ function set_product_npa(p_id, npa) { ...@@ -409,6 +417,7 @@ function set_product_npa(p_id, npa) {
data: JSON.stringify(data), data: JSON.stringify(data),
success: () => { success: () => {
const index = products.findIndex(p => p.id == p_id); const index = products.findIndex(p => p.id == p_id);
products[index].purchase_ok = data["purchase_ok"]; products[index].purchase_ok = data["purchase_ok"];
update_cdb_order(); update_cdb_order();
...@@ -645,7 +654,7 @@ function create_orders() { ...@@ -645,7 +654,7 @@ function create_orders() {
'price_unit': p_supplierinfo.price, 'price_unit': p_supplierinfo.price,
'supplier_taxes_id': p.supplier_taxes_id, 'supplier_taxes_id': p.supplier_taxes_id,
'product_variant_ids': p.product_variant_ids 'product_variant_ids': p.product_variant_ids
}) });
} }
} }
} }
...@@ -653,6 +662,7 @@ function create_orders() { ...@@ -653,6 +662,7 @@ function create_orders() {
if (Object.keys(orders_data.suppliers_data).length === 0) { if (Object.keys(orders_data.suppliers_data).length === 0) {
closeModal(); closeModal();
alert("Commande non créée : vous n'avez rentré aucune quantité !"); alert("Commande non créée : vous n'avez rentré aucune quantité !");
return -1; return -1;
} }
...@@ -674,9 +684,10 @@ function create_orders() { ...@@ -674,9 +684,10 @@ function create_orders() {
'id': new_order.id_po, 'id': new_order.id_po,
'supplier_id': new_order.supplier_id, 'supplier_id': new_order.supplier_id,
'supplier_name': supplier_name 'supplier_name': supplier_name
}) });
let new_order_template = $("#templates #new_order_item_template"); let new_order_template = $("#templates #new_order_item_template");
new_order_template.find(".new_order_supplier_name").text(supplier_name); new_order_template.find(".new_order_supplier_name").text(supplier_name);
new_order_template.find(".new_order_po").text(`PO${new_order.id_po}`); new_order_template.find(".new_order_po").text(`PO${new_order.id_po}`);
new_order_template.find(".download_order_file_button").attr('id', `download_attachment_${new_order.id_po}`); new_order_template.find(".download_order_file_button").attr('id', `download_attachment_${new_order.id_po}`);
...@@ -697,7 +708,8 @@ function create_orders() { ...@@ -697,7 +708,8 @@ function create_orders() {
closeModal(); closeModal();
}, },
error: function(data) { error: function(data) {
let msg = "erreur serveur lors de la création des product orders" let msg = "erreur serveur lors de la création des product orders";
err = {msg: msg, ctx: 'save_supplier_product_association', data: orders_data}; err = {msg: msg, ctx: 'save_supplier_product_association', data: orders_data};
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;
...@@ -708,6 +720,8 @@ function create_orders() { ...@@ -708,6 +720,8 @@ function create_orders() {
alert('Erreur lors de la création des commandes. Veuillez ré-essayer plus tard.'); alert('Erreur lors de la création des commandes. Veuillez ré-essayer plus tard.');
} }
}); });
return 0;
} }
/** /**
...@@ -730,11 +744,11 @@ function get_order_attachments() { ...@@ -730,11 +744,11 @@ function get_order_attachments() {
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
success: function(data) { success: function(data) {
for (let res_po of data.res) { for (let res_po of data.res) {
$(`#download_attachment_${res_po.id_po}`).attr('href', `${odoo_server}/web/content/${res_po.id_attachment}?download=true`) $(`#download_attachment_${res_po.id_po}`).attr('href', `${odoo_server}/web/content/${res_po.id_attachment}?download=true`);
} }
$('#created_orders_area .download_order_file_loading').hide() $('#created_orders_area .download_order_file_loading').hide();
$('#created_orders_area .download_order_file_button').show() $('#created_orders_area .download_order_file_button').show();
}, },
error: function() { error: function() {
$.notify( $.notify(
...@@ -776,8 +790,10 @@ function back() { ...@@ -776,8 +790,10 @@ function back() {
* Create a string to represent a supplier column in product data * Create a string to represent a supplier column in product data
* @returns String * @returns String
*/ */
function supplier_column_name(supplier) { function supplier_column_name(supplier) {
const supplier_id = ('supplier_id' in supplier) ? supplier.supplier_id : supplier.id const supplier_id = ('supplier_id' in supplier) ? supplier.supplier_id : supplier.id;
return `qty_supplier_${supplier_id}`; return `qty_supplier_${supplier_id}`;
} }
...@@ -828,6 +844,7 @@ function _compute_product_data(product) { ...@@ -828,6 +844,7 @@ function _compute_product_data(product) {
for (let p_supplierinfo of product.suppliersinfo) { for (let p_supplierinfo of product.suppliersinfo) {
// Preset qty for input if product related to supplier: existing qty or null (null -> qty to be set, display an empty input) // Preset qty for input if product related to supplier: existing qty or null (null -> qty to be set, display an empty input)
let supplier_qty = ("qty" in p_supplierinfo) ? p_supplierinfo.qty : null; let supplier_qty = ("qty" in p_supplierinfo) ? p_supplierinfo.qty : null;
item[supplier_column_name(p_supplierinfo)] = supplier_qty; item[supplier_column_name(p_supplierinfo)] = supplier_qty;
// Update product's total qty to buy if qty set for this supplier // Update product's total qty to buy if qty set for this supplier
...@@ -848,7 +865,7 @@ function _compute_product_data(product) { ...@@ -848,7 +865,7 @@ function _compute_product_data(product) {
} }
} }
if (p_package_qties.length == 0 || !p_package_qties.every( (val, i, arr) => val === arr[0] )) { if (p_package_qties.length == 0 || !p_package_qties.every((val, i, arr) => val === arr[0])) {
// Don't display package qty if no supplierinf or if not all package qties are equals, // Don't display package qty if no supplierinf or if not all package qties are equals,
item.package_qty = 'X'; item.package_qty = 'X';
} else { } else {
...@@ -859,6 +876,7 @@ function _compute_product_data(product) { ...@@ -859,6 +876,7 @@ function _compute_product_data(product) {
/* Coverage related data */ /* Coverage related data */
if (order_doc.coverage_days !== null) { if (order_doc.coverage_days !== null) {
let unmet_needs = product.daily_conso * order_doc.coverage_days - product.qty_available - product.incoming_qty - purchase_qty; let unmet_needs = product.daily_conso * order_doc.coverage_days - product.qty_available - product.incoming_qty - purchase_qty;
unmet_needs = -Math.round(unmet_needs); unmet_needs = -Math.round(unmet_needs);
unmet_needs = (unmet_needs > 0) ? 0 : unmet_needs; unmet_needs = (unmet_needs > 0) ? 0 : unmet_needs;
...@@ -867,7 +885,7 @@ function _compute_product_data(product) { ...@@ -867,7 +885,7 @@ function _compute_product_data(product) {
item.unmet_needs = 'X'; item.unmet_needs = 'X';
} }
return item return item;
} }
/** /**
...@@ -988,13 +1006,16 @@ function prepare_datatable_columns() { ...@@ -988,13 +1006,16 @@ function prepare_datatable_columns() {
if (full.package_qty === 'X') { if (full.package_qty === 'X') {
let product_data = products.find(p => p.id == full.id); let product_data = products.find(p => p.id == full.id);
if (product_data !== undefined) { if (product_data !== undefined) {
let supplierinfo = product_data.suppliersinfo.find(psi => psi.supplier_id == supplier.id); let supplierinfo = product_data.suppliersinfo.find(psi => psi.supplier_id == supplier.id);
content += `<span class="supplier_package_qty">Colisage : ${supplierinfo.package_qty}</span>`; content += `<span class="supplier_package_qty">Colisage : ${supplierinfo.package_qty}</span>`;
} }
} }
content += `</div>` content += `</div>`;
return content; return content;
} }
} }
...@@ -1053,6 +1074,7 @@ function display_products(params) { ...@@ -1053,6 +1074,7 @@ function display_products(params) {
const data = prepare_datatable_data(); const data = prepare_datatable_data();
const columns = prepare_datatable_columns(); const columns = prepare_datatable_columns();
let sort_order_dir = "asc"; let sort_order_dir = "asc";
if (params != undefined && typeof params.sort_order_dir != "undefined") { if (params != undefined && typeof params.sort_order_dir != "undefined") {
sort_order_dir = params.sort_order_dir; sort_order_dir = params.sort_order_dir;
} }
...@@ -1090,6 +1112,7 @@ function display_products(params) { ...@@ -1090,6 +1112,7 @@ function display_products(params) {
// On inputs change // On inputs change
$('#products_table').on('change', 'tbody td .product_qty_input', function () { $('#products_table').on('change', 'tbody td .product_qty_input', function () {
let val = ($(this).val() == '') ? 0 : $(this).val(); let val = ($(this).val() == '') ? 0 : $(this).val();
val = parseFloat(val); val = parseFloat(val);
// If value is a number // If value is a number
...@@ -1105,7 +1128,9 @@ function display_products(params) { ...@@ -1105,7 +1128,9 @@ function display_products(params) {
// Update row // Update row
const product = products.find(p => p.id == prod_id); const product = products.find(p => p.id == prod_id);
const new_row_data = prepare_datatable_data([product.id])[0]; const new_row_data = prepare_datatable_data([product.id])[0];
products_table.row($(this).closest('tr')).data(new_row_data).draw();
products_table.row($(this).closest('tr')).data(new_row_data)
.draw();
update_cdb_order(); update_cdb_order();
} else { } else {
...@@ -1143,6 +1168,7 @@ function display_products(params) { ...@@ -1143,6 +1168,7 @@ function display_products(params) {
// Find existing price in another supplierinfo // Find existing price in another supplierinfo
let default_price = null; let default_price = null;
let default_package_qty = 1; // Default package qty is 1 let default_package_qty = 1; // Default package qty is 1
for (let psi of product.suppliersinfo) { for (let psi of product.suppliersinfo) {
if ('price' in psi && psi.price !== null) { if ('price' in psi && psi.price !== null) {
default_price = psi.price; default_price = psi.price;
...@@ -1159,7 +1185,7 @@ function display_products(params) { ...@@ -1159,7 +1185,7 @@ function display_products(params) {
new_product_supplier_association = { new_product_supplier_association = {
package_qty: default_package_qty, package_qty: default_package_qty,
price: default_price price: default_price
} };
$('.new_product_supplier_price').on('input', function () { $('.new_product_supplier_price').on('input', function () {
new_product_supplier_association.price = $(this).val(); new_product_supplier_association.price = $(this).val();
...@@ -1194,6 +1220,7 @@ function display_products(params) { ...@@ -1194,6 +1220,7 @@ function display_products(params) {
// Save / unsave selected row // Save / unsave selected row
const p_id = products_table.row($(this).closest('tr')).data().id; const p_id = products_table.row($(this).closest('tr')).data().id;
if (this.checked) { if (this.checked) {
selected_rows.push(p_id); selected_rows.push(p_id);
} else { } else {
...@@ -1283,7 +1310,9 @@ function update_main_screen(params) { ...@@ -1283,7 +1310,9 @@ function update_main_screen(params) {
if (order_doc.date_planned !== null) { if (order_doc.date_planned !== null) {
// Switch format from yy-mm-dd hh:mm:ss to readable dd/mm/yy // Switch format from yy-mm-dd hh:mm:ss to readable dd/mm/yy
let date_to_format = order_doc.date_planned.split(' ')[0]; let date_to_format = order_doc.date_planned.split(' ')[0];
let readable_date = date_to_format.split('-').reverse().join('/'); let readable_date = date_to_format.split('-').reverse()
.join('/');
$("#date_planned_input").val(readable_date); $("#date_planned_input").val(readable_date);
} else { } else {
$("#date_planned_input").val(''); $("#date_planned_input").val('');
...@@ -1422,6 +1451,7 @@ $(document).ready(function() { ...@@ -1422,6 +1451,7 @@ $(document).ready(function() {
$("#coverage_form").on("submit", function(e) { $("#coverage_form").on("submit", function(e) {
e.preventDefault(); e.preventDefault();
let val = $("#coverage_days_input").val(); let val = $("#coverage_days_input").val();
val = parseInt(val); val = parseInt(val);
if (!isNaN(val)) { if (!isNaN(val)) {
...@@ -1431,7 +1461,7 @@ $(document).ready(function() { ...@@ -1431,7 +1461,7 @@ $(document).ready(function() {
update_main_screen(); update_main_screen();
} else { } else {
$("#coverage_days_input").val(order_doc.coverage_days); $("#coverage_days_input").val(order_doc.coverage_days);
alert(`Valeur non valide pour le nombre de jours de couverture !`) alert(`Valeur non valide pour le nombre de jours de couverture !`);
} }
}); });
...@@ -1455,8 +1485,9 @@ $(document).ready(function() { ...@@ -1455,8 +1485,9 @@ $(document).ready(function() {
$('#create_orders').on('click', function() { $('#create_orders').on('click', function() {
if (order_doc.date_planned === null) { if (order_doc.date_planned === null) {
alert("Veuillez rentrer une date de livraison prévue.") alert("Veuillez rentrer une date de livraison prévue.");
return -1
return -1;
} }
let modal_create_order = $('#templates #modal_create_order'); let modal_create_order = $('#templates #modal_create_order');
...@@ -1469,6 +1500,8 @@ $(document).ready(function() { ...@@ -1469,6 +1500,8 @@ $(document).ready(function() {
'Valider', 'Valider',
false false
); );
return 0;
}); });
$.datepicker.regional['fr'] = { $.datepicker.regional['fr'] = {
...@@ -1495,12 +1528,13 @@ $(document).ready(function() { ...@@ -1495,12 +1528,13 @@ $(document).ready(function() {
'Ve', 'Ve',
'Sa' 'Sa'
], ],
dateFormat: date_format, dateFormat: date_format
}; };
$.datepicker.setDefaults($.datepicker.regional['fr']); $.datepicker.setDefaults($.datepicker.regional['fr']);
const tomorrow = new Date() const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1)
tomorrow.setDate(tomorrow.getDate() + 1);
$("#date_planned_input") $("#date_planned_input")
.datepicker({ .datepicker({
...@@ -1514,7 +1548,10 @@ $(document).ready(function() { ...@@ -1514,7 +1548,10 @@ $(document).ready(function() {
// No exception raised: date is valid. // No exception raised: date is valid.
// Change format from readable (dd/mm/yy) to ISO (yy-mm-dd) // Change format from readable (dd/mm/yy) to ISO (yy-mm-dd)
let formatted_date = $(this).val().split('/').reverse().join('-') + ' 00:00:00'; let formatted_date = $(this).val()
.split('/')
.reverse()
.join('-') + ' 00:00:00';
// Update doc if changed // Update doc if changed
if (formatted_date !== order_doc.date_planned) { if (formatted_date !== order_doc.date_planned) {
...@@ -1586,11 +1623,13 @@ $(document).ready(function() { ...@@ -1586,11 +1623,13 @@ $(document).ready(function() {
"ö": "o" "ö": "o"
}; };
var normalize = function( term ) { var normalize = function(term) {
var ret = ""; var ret = "";
for ( var i = 0; i < term.length; i++ ) {
for (var i = 0; i < term.length; i++) {
ret += accentMap[ term.charAt(i) ] || term.charAt(i); ret += accentMap[ term.charAt(i) ] || term.charAt(i);
} }
return ret; return ret;
}; };
...@@ -1605,12 +1644,14 @@ $(document).ready(function() { ...@@ -1605,12 +1644,14 @@ $(document).ready(function() {
// Set up autocomplete on product input // Set up autocomplete on product input
$("#product_input").autocomplete({ $("#product_input").autocomplete({
source: function( request, response ) { source: function(request, response) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex( request.term ), "i" ); var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
response( $.grep( products_list.map(a => a.display_name), function( value ) {
response($.grep(products_list.map(a => a.display_name), function(value) {
value = value.label || value.value || value; value = value.label || value.value || value;
return matcher.test( value ) || matcher.test( normalize( value ) );
}) ); return matcher.test(value) || matcher.test(normalize(value));
}));
}, },
position: {collision: "flip" } position: {collision: "flip" }
}); });
......
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