Commit d59c0d4b by Damien Moulard Committed by Alexis Aoun

AAC: fix & upgrade add product to supplier

parent 67eba34c
...@@ -135,7 +135,7 @@ ...@@ -135,7 +135,7 @@
/* -- Bottom action button */ /* -- Bottom action button */
#orders_creation_area { #main_content_footer {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
margin: 15px 0 35px 0; margin: 15px 0 35px 0;
...@@ -160,6 +160,25 @@ ...@@ -160,6 +160,25 @@
cursor: pointer; 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 */ /* - Orders created screen */
.order_created_header { .order_created_header {
......
...@@ -19,7 +19,11 @@ var suppliers_list = [], ...@@ -19,7 +19,11 @@ var suppliers_list = [],
}, },
fingerprint = null, fingerprint = null,
date_format = "dd/mm/yy" date_format = "dd/mm/yy"
product_orders = []; product_orders = [],
new_product_supplier_association = {
package_qty: null,
price: null
};
/* - UTILS */ /* - UTILS */
...@@ -28,9 +32,10 @@ var suppliers_list = [], ...@@ -28,9 +32,10 @@ var suppliers_list = [],
* Reset data that changes between screens * Reset data that changes between screens
*/ */
function reset_data() { function reset_data() {
products = [], products = [];
selected_suppliers = [], selected_suppliers = [];
selected_rows = [], selected_rows = [];
product_orders = [];
order_doc = { order_doc = {
_id: null, _id: null,
date_planned: null, date_planned: null,
...@@ -41,6 +46,10 @@ function reset_data() { ...@@ -41,6 +46,10 @@ function reset_data() {
products: [], products: [],
selected_suppliers: [] selected_suppliers: []
}; };
new_product_supplier_association = {
package_qty: null,
price: null
};
} }
/** /**
...@@ -214,9 +223,24 @@ function remove_supplier(supplier_id) { ...@@ -214,9 +223,24 @@ function remove_supplier(supplier_id) {
function save_supplier_product_association(product, supplier, cell) { function save_supplier_product_association(product, supplier, cell) {
openModal(); 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 = { const data = {
product_tmpl_id: product.id, product_tmpl_id: product.id,
supplier_id: supplier.id supplier_id: supplier.id,
package_qty: package_qty,
price: price,
}; };
// Send request to create association // Send request to create association
...@@ -228,8 +252,18 @@ function save_supplier_product_association(product, supplier, cell) { ...@@ -228,8 +252,18 @@ function save_supplier_product_association(product, supplier, cell) {
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
data: JSON.stringify(data), data: JSON.stringify(data),
success: () => { 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 // Save relation locally
// TODO: save supplierinfo in product
save_supplier_products(supplier, [product]); save_supplier_products(supplier, [product]);
// Update table // Update table
...@@ -663,8 +697,7 @@ function get_order_attachments() { ...@@ -663,8 +697,7 @@ function get_order_attachments() {
$('#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(data) { error: function() {
console.log(data);
$.notify( $.notify(
"Échec de la récupération du lien de téléchargement des fichiers. Nouvelle tentative dans 10s.", "Échec de la récupération du lien de téléchargement des fichiers. Nouvelle tentative dans 10s.",
{ {
...@@ -896,7 +929,7 @@ function prepare_datatable_columns() { ...@@ -896,7 +929,7 @@ function prepare_datatable_columns() {
function display_products(params) { function display_products(params) {
if (products.length == 0) { if (products.length == 0) {
$('.main').hide(); $('.main').hide();
$('#create_orders').hide(); $('#main_content_footer').hide();
$('#do_inventory').hide(); $('#do_inventory').hide();
return -1; return -1;
...@@ -942,7 +975,7 @@ function display_products(params) { ...@@ -942,7 +975,7 @@ function display_products(params) {
}); });
$('.main').show(); $('.main').show();
$('#create_orders').show(); $('#main_content_footer').show();
$('#do_inventory').show(); $('#do_inventory').show();
// On inputs change // On inputs change
...@@ -994,8 +1027,31 @@ function display_products(params) { ...@@ -994,8 +1027,31 @@ function display_products(params) {
'Valider', 'Valider',
false 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 // Select row(s) on checkbox change
$(products_table.table().header()).on('click', 'th #select_all_products_cb', function () { $(products_table.table().header()).on('click', 'th #select_all_products_cb', function () {
if (this.checked) { if (this.checked) {
......
...@@ -54,7 +54,7 @@ def associate_supplier_to_product(request): ...@@ -54,7 +54,7 @@ def associate_supplier_to_product(request):
res = {} res = {}
try: try:
data = json.loads(request.body.decode()) 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: except Exception as e:
res["error"] = str(e) res["error"] = str(e)
return JsonResponse(res, status=500) return JsonResponse(res, status=500)
......
...@@ -128,9 +128,14 @@ class CagetteProduct(models.Model): ...@@ -128,9 +128,14 @@ class CagetteProduct(models.Model):
return res return res
@staticmethod @staticmethod
def associate_supplier_to_product(product_tmpl_id, partner_id): def associate_supplier_to_product(data):
api = OdooAPI() 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"] f = ["id", "standard_price", "purchase_ok"]
c = [['product_tmpl_id', '=', product_tmpl_id]] c = [['product_tmpl_id', '=', product_tmpl_id]]
res_products = api.search_read('product.product', c, f) res_products = api.search_read('product.product', c, f)
...@@ -141,8 +146,9 @@ class CagetteProduct(models.Model): ...@@ -141,8 +146,9 @@ class CagetteProduct(models.Model):
'product_id' : product["id"], 'product_id' : product["id"],
'name' : partner_id, 'name' : partner_id,
'product_purchase_ok': product["purchase_ok"], 'product_purchase_ok': product["purchase_ok"],
'price': product["standard_price"], # By default, use product price 'price': price,
'base_price': product["standard_price"], 'base_price': price,
'package_qty': package_qty
} }
res = api.create('product.supplierinfo', f) res = api.create('product.supplierinfo', f)
......
...@@ -59,11 +59,46 @@ ...@@ -59,11 +59,46 @@
<table id="products_table" class="display" cellspacing="0" width="100%"></table> <table id="products_table" class="display" cellspacing="0" width="100%"></table>
</div> </div>
</div> </div>
<div id="product_form_container" style="margin-bottom: 50px;">
<form action="javascript:;" id="product_form"> <div id="main_content_footer" style="display:none;">
<input type="text" name="article" id="product_input" placeholder="Rechercher un article"> <div class="add_product_container">
<button type="submit" class='btn--primary'>Ajouter l'article</button> <div id="product_form_container">
</form> <form action="javascript:;" id="product_form">
<input type="text" name="article" id="product_input" placeholder="Rechercher un article">
<button type="submit" class='btn--primary'>Ajouter l'article</button>
</form>
</div>
</div>
<button type="button" class='btn--primary' id="create_orders">
Générer les commandes
</button>
</div>
</div>
<div id="orders_created" class="page_content" style="display:none;">
<div id="back_to_order_selection_from_orders_created">
<button type="button" class="btn--danger"><i class="fas fa-arrow-left"></i>&nbsp; Retour</button>
</div>
<div class="order_created_header txtcenter">
<h2>Commandes créées !</h2>
</div>
<div class="txtcenter">
Livraison prévue le : <span id="recap_delivery_date">XX/XX/XX</span>
</div>
<div id="created_orders_area"></div>
<br/><br/><hr/><br/>
<div class="mail_example_container">
<p class="mail_type_text">Mail type :</p>
<div class="mail_example">
Objet : Cde Cagette JJ/MM<br/>
<br/>
Bonjour XXXXXXX,<br/>
<br/>
Voici la commande de La Cagette pour le XX/XX/XX.<br/>
<br/>
Merci d'avance,<br/>
Bonne journée
</div>
</div> </div>
</div> </div>
...@@ -125,6 +160,18 @@ ...@@ -125,6 +160,18 @@
<h3>Attention !</h3> <h3>Attention !</h3>
<p> <p>
Vous vous apprêtez à associer le produit <span class="product_name"></span> au fournisseur <span class="supplier_name"></span>.<br/> 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/> L'association sera sauvegardée dès que vous aurez cliqué sur "Valider".<br/>
</p> </p>
<p>Êtez-vous sûr ?</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