Commit f53fd634 by Damien Moulard

Merge branch 'aide_a_la_commande' into dev_cooperatic

parents 313c7e0f 2d254598
...@@ -292,7 +292,9 @@ class Order(models.Model): ...@@ -292,7 +292,9 @@ class Order(models.Model):
res = { res = {
'id_po': id_po, 'id_po': id_po,
'confirm_po': True 'confirm_po': True,
'supplier_id': supplier_id,
'date_planned': date_planned
} }
return res return res
......
...@@ -91,11 +91,11 @@ ...@@ -91,11 +91,11 @@
#supplier_input { #supplier_input {
width: 350px; width: 350px;
border-radius: 8px; border-radius: 3px;
} }
#date_planned_input, #coverage_days_input { #date_planned_input, #coverage_days_input {
border-radius: 8px; border-radius: 3px;
} }
/* -- Table */ /* -- Table */
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
#products_table_filter input{ #products_table_filter input{
height: 35px; height: 35px;
width: 300px; width: 300px;
border-radius: 10px; border-radius: 3px;
} }
#products_table .help {cursor: help;} #products_table .help {cursor: help;}
#table_header_select_all{ #table_header_select_all{
...@@ -154,12 +154,34 @@ ...@@ -154,12 +154,34 @@
cursor: pointer; cursor: pointer;
} }
/* -- Bottom action button */ /* -- Footer */
#main_content_footer { #main_content_footer {
margin: 10px 0 35px 0;
}
#footer_orders_recap {
width: 100%;
display: flex;
justify-content: space-evenly;
margin-bottom: 15px;
}
#footer_actions {
width: 100%;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
margin: 15px 0 35px 0; }
#suppliers_total_values {
display: flex;
}
.supplier_total_item {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
} }
/* -- Suppliers list */ /* -- Suppliers list */
...@@ -182,27 +204,32 @@ ...@@ -182,27 +204,32 @@
} }
/* -- Attach product to supplier modal */ /* -- Attach product to supplier modal */
.new_product_supplier_input_area { .modal_input_area {
margin-bottom: 15px; margin-bottom: 15px;
width: 100%; width: 100%;
display: flex; display: flex;
justify-content: center; justify-content: center;
} }
.new_product_supplier_input, .new_product_supplier_label { .modal_input_container, .modal_input_label {
width:50%; width:50%;
margin: 0 15px 0 15px; margin: 0 15px 0 15px;
} }
.new_product_supplier_label { .modal_input_label {
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
align-items: center; align-items: center;
} }
.modal_input {
width: 90%;
}
/* - Orders created screen */ /* - Orders created screen */
.order_created_header { .order_created_header {
margin-top: 5px;
margin-bottom: 40px; margin-bottom: 40px;
} }
...@@ -227,6 +254,14 @@ ...@@ -227,6 +254,14 @@
text-decoration: none; text-decoration: none;
color: white; color: white;
} }
.download_order_file_button:active {
text-decoration: none;
color: white;
}
.download_order_file_button:focus {
text-decoration: none;
color: white;
}
#recap_delivery_date { #recap_delivery_date {
font-weight: bold; font-weight: bold;
......
...@@ -41,8 +41,8 @@ def get_suppliers(request): ...@@ -41,8 +41,8 @@ def get_suppliers(request):
def get_supplier_products(request): def get_supplier_products(request):
""" Get supplier products """ """ Get supplier products """
sid = request.GET.get('sid', '') suppliers_id = request.GET.getlist('sids', '')
res = CagetteProducts.get_products_for_order_helper(sid) res = CagetteProducts.get_products_for_order_helper(suppliers_id)
if 'error' in res: if 'error' in res:
return JsonResponse(res, status=500) return JsonResponse(res, status=500)
...@@ -69,8 +69,13 @@ def create_orders(request): ...@@ -69,8 +69,13 @@ def create_orders(request):
# suppliers id are keys in request data # suppliers id are keys in request data
for supplier_id in data["suppliers_data"].keys(): for supplier_id in data["suppliers_data"].keys():
res_created = Order.create(supplier_id, data["date_planned"], data["suppliers_data"][supplier_id]) supplier_data = data["suppliers_data"][supplier_id]
res_created["supplier_id"] = supplier_id
res_created = Order.create(
supplier_id,
supplier_data["date_planned"],
supplier_data["lines"]
)
res["created"].append(res_created) res["created"].append(res_created)
except Exception as e: except Exception as e:
......
...@@ -455,11 +455,11 @@ class CagetteProducts(models.Model): ...@@ -455,11 +455,11 @@ class CagetteProducts(models.Model):
return res return res
@staticmethod @staticmethod
def get_products_for_order_helper(supplier_id, pids = []): def get_products_for_order_helper(supplier_ids, pids = []):
""" """
One of the two parameters must be set. One of the two parameters must be not empty.
Get products by supplier if a supplier_id is set. Get products by supplier if one or more supplier_id is set.
If supplier_id is None, get products specified in pids. If supplier_ids is empty, get products specified in pids. In this case, suppliers info won't be fetched.
""" """
api = OdooAPI() api = OdooAPI()
res = {} res = {}
...@@ -468,10 +468,10 @@ class CagetteProducts(models.Model): ...@@ -468,10 +468,10 @@ class CagetteProducts(models.Model):
try: try:
today = datetime.date.today().strftime("%Y-%m-%d") today = datetime.date.today().strftime("%Y-%m-%d")
if supplier_id is not None: if len(supplier_ids) > 0:
# Get products/supplier relation # Get products/supplier relation
f = ["product_tmpl_id", 'date_start', 'date_end', 'package_qty', 'price'] f = ["product_tmpl_id", 'date_start', 'date_end', 'package_qty', 'price', 'name']
c = [['name', '=', int(supplier_id)]] c = [['name', 'in', [ int(x) for x in supplier_ids]]]
psi = api.search_read('product.supplierinfo', c, f) psi = api.search_read('product.supplierinfo', c, f)
# Filter valid data # Filter valid data
...@@ -503,8 +503,8 @@ class CagetteProducts(models.Model): ...@@ -503,8 +503,8 @@ class CagetteProducts(models.Model):
sales_average_params = { sales_average_params = {
'ids': ptids, 'ids': ptids,
# 'from': '2019-06-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)
...@@ -515,10 +515,10 @@ class CagetteProducts(models.Model): ...@@ -515,10 +515,10 @@ class CagetteProducts(models.Model):
# Add supplier data to product data # Add supplier data to product data
for i, fp in enumerate(filtered_products_t): for i, fp in enumerate(filtered_products_t):
if supplier_id is not None: if len(supplier_ids) > 0:
psi_item = next(item for item in psi if item["product_tmpl_id"] is not False and item["product_tmpl_id"][0] == fp["id"]) psi_item = next(item for item in psi if item["product_tmpl_id"] is not False and item["product_tmpl_id"][0] == fp["id"])
filtered_products_t[i]['suppliersinfo'] = [{ filtered_products_t[i]['suppliersinfo'] = [{
'supplier_id': int(supplier_id), 'supplier_id': int(psi_item["name"][0]),
'package_qty': psi_item["package_qty"], 'package_qty': psi_item["package_qty"],
'price': psi_item["price"] 'price': psi_item["price"]
}] }]
...@@ -531,7 +531,7 @@ class CagetteProducts(models.Model): ...@@ -531,7 +531,7 @@ class CagetteProducts(models.Model):
res["products"] = filtered_products_t res["products"] = filtered_products_t
except Exception as e: except Exception as e:
coop_logger.error('get_products_for_order_helper %s (%s)', str(e), str(supplier_id)) coop_logger.error('get_products_for_order_helper %s (%s)', str(e))
res["error"] = str(e) res["error"] = str(e)
return res return res
......
...@@ -53,7 +53,6 @@ ...@@ -53,7 +53,6 @@
<input type="text" name="supplier" id="supplier_input" placeholder="Rechercher un fournisseur par son nom"> <input type="text" name="supplier" id="supplier_input" placeholder="Rechercher un fournisseur par son nom">
<button type="submit" class='btn--primary'>Ajouter le fournisseur</button> <button type="submit" class='btn--primary'>Ajouter le fournisseur</button>
</form> </form>
<input type="text" name="date_planned" id="date_planned_input" placeholder="Date de livraison souhaitée">
</div> </div>
<div class="txtcenter" id="suppliers_container"></div> <div class="txtcenter" id="suppliers_container"></div>
...@@ -65,18 +64,28 @@ ...@@ -65,18 +64,28 @@
</div> </div>
<div id="main_content_footer" style="display:none;"> <div id="main_content_footer" style="display:none;">
<div class="add_product_container"> <div id="footer_orders_recap">
<div id="product_form_container"> <div id="suppliers_total_values">
<form action="javascript:;" id="product_form"> <h4>Total /fournisseur : </h4><div id="suppliers_total_values_container"></div>
<input type="text" name="article" id="product_input" placeholder="Rechercher un article"> </div>
<button type="submit" class='btn--primary'>Ajouter l'article</button> <div id="order_total_value_container">
</form> <h4>Total : <span id="order_total_value"></span></h4>
</div> </div>
</div> </div>
<button type="button" class='btn--primary' id="create_orders"> <div id="footer_actions">
Générer les commandes <div class="add_product_container">
</button> <div id="product_form_container">
</div> <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> </div>
<div id="orders_created" class="page_content" style="display:none;"> <div id="orders_created" class="page_content" style="display:none;">
...@@ -88,9 +97,6 @@ ...@@ -88,9 +97,6 @@
<div class="order_created_header txtcenter"> <div class="order_created_header txtcenter">
<h2>Commandes créées !</h2> <h2>Commandes créées !</h2>
</div> </div>
<div class="txtcenter">
Livraison prévue le : <span id="recap_delivery_date">XX/XX/XX</span>
</div>
<div id="created_orders_area"></div> <div id="created_orders_area"></div>
<br/><br/><hr/><br/> <br/><br/><hr/><br/>
<div class="mail_example_container"> <div class="mail_example_container">
...@@ -128,6 +134,7 @@ ...@@ -128,6 +134,7 @@
<div class="new_order_item"> <div class="new_order_item">
<h3 class="new_order_supplier_name"></h3> <h3 class="new_order_supplier_name"></h3>
<h3 class="new_order_po"></h3> <h3 class="new_order_po"></h3>
<h4 class="new_order_date_planned"></h4>
<div class='download_order_file'> <div class='download_order_file'>
<i class="fas fa-spinner fa-spin download_order_file_loading"></i> <i class="fas fa-spinner fa-spin download_order_file_loading"></i>
<a class='btn--success download_order_file_button' style="display:none;" href="#"> <a class='btn--success download_order_file_button' style="display:none;" href="#">
...@@ -168,13 +175,17 @@ ...@@ -168,13 +175,17 @@
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> </p>
<br/> <br/>
<div class="new_product_supplier_input_area"> <div class="modal_input_area">
<span class="new_product_supplier_label">Prix du produit chez ce fournisseur: </span> <span class="modal_input_label">Prix du produit chez ce fournisseur: </span>
<input type="number" class="new_product_supplier_input new_product_supplier_price" > <div class="modal_input_container">
<input type="number" class="modal_input new_product_supplier_price" >
</div>
</div> </div>
<div class="new_product_supplier_input_area"> <div class="modal_input_area">
<span class="new_product_supplier_label">Colisage chez ce fournisseur: </span> <span class="modal_input_label">Colisage chez ce fournisseur: </span>
<input type="number" class="new_product_supplier_input new_product_supplier_package_pty"> <div class="modal_input_container">
<input type="number" class="modal_input new_product_supplier_package_pty">
</div>
</div> </div>
<br/> <br/>
<p> <p>
...@@ -196,20 +207,35 @@ ...@@ -196,20 +207,35 @@
<h3>Attention !</h3> <h3>Attention !</h3>
<p> <p>
Vous vous apprêtez à passer le produit <span class="product_name"></span> en <span class="product_npa"></span>.<br/> Vous vous apprêtez à passer le produit <span class="product_name"></span> en <span class="product_npa"></span>.<br/>
L'information sera enregistrée dès que vous aurez cliqué sur "Valider". Dès que vous aurez cliqué sur "Valider", le produit sera retiré du tableau et l'information sera enregistrée dans Odoo.
</p> </p>
<p>Êtez-vous sûr ?</p> <p>Êtez-vous sûr ?</p>
<hr/> <hr/>
</div> </div>
<div id="modal_create_order"> <div id="modal_create_order">
<h3>Attention !</h3> <h3>Dernière étape...</h3>
<br/>
<p> <p>
Vous vous apprêtez à générer les commandes à partir des données rentrées dans le tableau. Vous vous apprêtez à générer les commandes à partir des données rentrées dans le tableau.
</p> </p>
<p>Êtez-vous sûr ?</p> <p>
Vous pouvez rentrer une date de livraison prévue pour chaque fournisseur (optionnel, la date par défaut sera celle de demain).
</p>
<br/>
<div class="suppliers_date_planned_area"></div>
<br/>
<hr/> <hr/>
</div> </div>
<div id="modal_create_order__supplier_date_planned">
<div class="modal_input_area">
<span class="modal_input_label supplier_name"></span>
<div class="modal_input_container">
<input type="text" class="modal_input supplier_date_planned" placeholder="Date de livraison prévue">
</div>
</div>
</div>
</div> </div>
</div> </div>
......
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