Commit 37bd4c98 by Damien Moulard

AAC: fix & upgrade add product to supplier

parent 32241a99
Pipeline #1110 failed with stage
in 1 minute 17 seconds
......@@ -135,7 +135,7 @@
/* -- Bottom action button */
#orders_creation_area {
#main_content_footer {
display: flex;
justify-content: space-between;
margin: 15px 0 35px 0;
......@@ -160,6 +160,25 @@
cursor: pointer;
}
/* -- Attach product to supplier modal */
.new_product_supplier_input_area {
margin-bottom: 15px;
width: 100%;
display: flex;
justify-content: center;
}
.new_product_supplier_input, .new_product_supplier_label {
width:50%;
margin: 0 15px 0 15px;
}
.new_product_supplier_label {
display: flex;
justify-content: flex-end;
align-items: center;
}
/* - Orders created screen */
.order_created_header {
......
......@@ -19,7 +19,11 @@ var suppliers_list = [],
},
fingerprint = null,
date_format = "dd/mm/yy"
product_orders = [];
product_orders = [],
new_product_supplier_association = {
package_qty: null,
price: null
};
/* - UTILS */
......@@ -28,9 +32,10 @@ var suppliers_list = [],
* Reset data that changes between screens
*/
function reset_data() {
products = [],
selected_suppliers = [],
selected_rows = [],
products = [];
selected_suppliers = [];
selected_rows = [];
product_orders = [];
order_doc = {
_id: null,
date_planned: null,
......@@ -41,6 +46,10 @@ function reset_data() {
products: [],
selected_suppliers: []
};
new_product_supplier_association = {
package_qty: null,
price: null
};
}
/**
......@@ -225,9 +234,24 @@ function remove_supplier(supplier_id) {
function save_supplier_product_association(product, supplier, cell) {
openModal();
$('.new_product_supplier_price').off();
$('.new_product_supplier_package_pty').off();
const package_qty = parseFloat(new_product_supplier_association.package_qty);
const price = parseFloat(new_product_supplier_association.price);
// If value is a number
if (isNaN(package_qty) || isNaN(price)) {
closeModal();
alert(`Les champs "Prix" et "Colisage" doivent être remplis et valides. L'association n'a pas été sauvegardée.`)
return -1;
}
const data = {
product_tmpl_id: product.id,
supplier_id: supplier.id
supplier_id: supplier.id,
package_qty: package_qty,
price: price,
};
// Send request to create association
......@@ -239,8 +263,18 @@ function save_supplier_product_association(product, supplier, cell) {
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
success: () => {
// Save supplierinfo in product
if (!'suppliersinfo' in product) {
product.suppliersinfo = []
}
product.suppliersinfo.push({
supplier_id: supplier.id,
package_qty: package_qty,
price: price
})
// Save relation locally
// TODO: save supplierinfo in product
save_supplier_products(supplier, [product]);
// Update table
......@@ -674,8 +708,7 @@ function get_order_attachments() {
$('#created_orders_area .download_order_file_loading').hide()
$('#created_orders_area .download_order_file_button').show()
},
error: function(data) {
console.log(data);
error: function() {
$.notify(
"Échec de la récupération du lien de téléchargement des fichiers. Nouvelle tentative dans 10s.",
{
......@@ -907,7 +940,7 @@ function prepare_datatable_columns() {
function display_products(params) {
if (products.length == 0) {
$('.main').hide();
$('#create_orders').hide();
$('#main_content_footer').hide();
$('#do_inventory').hide();
return -1;
......@@ -953,7 +986,7 @@ function display_products(params) {
});
$('.main').show();
$('#create_orders').show();
$('#main_content_footer').show();
$('#do_inventory').show();
// On inputs change
......@@ -1005,8 +1038,31 @@ function display_products(params) {
'Valider',
false
);
});
// Find existing price in another supplierinfo
let default_price = null;
for (let psi of product.suppliersinfo) {
if ('price' in psi && psi.price !== null) {
default_price = psi.price;
break;
}
}
// Set default value for price & package qty for new supplierinfo
$(".new_product_supplier_package_pty").val(1); // Default package qty is 1
$(".new_product_supplier_price").val(default_price); // Default price is existing price for other supplier
new_product_supplier_association = {
package_qty: 1,
price: default_price
}
$('.new_product_supplier_price').on('input', function () {
new_product_supplier_association.price = $(this).val();
});
$('.new_product_supplier_package_pty').on('input', function () {
new_product_supplier_association.package_qty = $(this).val();
});
});
// Select row(s) on checkbox change
$(products_table.table().header()).on('click', 'th #select_all_products_cb', function () {
if (this.checked) {
......
......@@ -54,7 +54,7 @@ def associate_supplier_to_product(request):
res = {}
try:
data = json.loads(request.body.decode())
res = CagetteProduct.associate_supplier_to_product(data["product_tmpl_id"], data["supplier_id"])
res = CagetteProduct.associate_supplier_to_product(data)
except Exception as e:
res["error"] = str(e)
return JsonResponse(res, status=500)
......
......@@ -128,9 +128,14 @@ class CagetteProduct(models.Model):
return res
@staticmethod
def associate_supplier_to_product(product_tmpl_id, partner_id):
def associate_supplier_to_product(data):
api = OdooAPI()
product_tmpl_id = data["product_tmpl_id"]
partner_id = data["supplier_id"]
package_qty = data["package_qty"]
price = data["price"]
f = ["id", "standard_price", "purchase_ok"]
c = [['product_tmpl_id', '=', product_tmpl_id]]
res_products = api.search_read('product.product', c, f)
......@@ -141,8 +146,9 @@ class CagetteProduct(models.Model):
'product_id' : product["id"],
'name' : partner_id,
'product_purchase_ok': product["purchase_ok"],
'price': product["standard_price"], # By default, use product price
'base_price': product["standard_price"],
'price': price,
'base_price': price,
'package_qty': package_qty
}
res = api.create('product.supplierinfo', f)
......
......@@ -60,7 +60,7 @@
</div>
</div>
<div id="orders_creation_area">
<div id="main_content_footer" style="display:none;">
<div class="add_product_container">
<div id="product_form_container">
<form action="javascript:;" id="product_form">
......@@ -69,7 +69,7 @@
</form>
</div>
</div>
<button type="button" class='btn--primary' id="create_orders" style="display:none;">
<button type="button" class='btn--primary' id="create_orders">
Générer les commandes
</button>
</div>
......@@ -160,6 +160,18 @@
<h3>Attention !</h3>
<p>
Vous vous apprêtez à associer le produit <span class="product_name"></span> au fournisseur <span class="supplier_name"></span>.<br/>
</p>
<br/>
<div class="new_product_supplier_input_area">
<span class="new_product_supplier_label">Prix du produit chez ce fournisseur: </span>
<input type="number" class="new_product_supplier_input new_product_supplier_price" >
</div>
<div class="new_product_supplier_input_area">
<span class="new_product_supplier_label">Colisage chez ce fournisseur: </span>
<input type="number" class="new_product_supplier_input new_product_supplier_package_pty">
</div>
<br/>
<p>
L'association sera sauvegardée dès que vous aurez cliqué sur "Valider".<br/>
</p>
<p>Êtez-vous sûr ?</p>
......
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