Commit ff8bc7e6 by Damien Moulard

update supplierinfo instead of creating a new onewhen reassociating

parent 8347a3c1
Pipeline #1281 passed with stage
in 1 minute 21 seconds
...@@ -291,7 +291,7 @@ ...@@ -291,7 +291,7 @@
margin: 30px 0 20px 0; margin: 30px 0 20px 0;
position: -webkit-sticky; position: -webkit-sticky;
position: sticky; position: sticky;
top: 150px; top: 140px;
z-index: 5; z-index: 5;
} }
......
...@@ -196,21 +196,21 @@ function compute_products_coverage_qties() { ...@@ -196,21 +196,21 @@ function compute_products_coverage_qties() {
] of Object.entries(products)) { ] of Object.entries(products)) {
if ('suppliersinfo' in product && product.suppliersinfo.length > 0) { if ('suppliersinfo' in product && product.suppliersinfo.length > 0) {
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;
// Reduce to nb of packages to purchase // Reduce to nb of packages to purchase
purchase_package_qty_for_coverage = purchase_qty_for_coverage / product.suppliersinfo[0].package_qty; purchase_package_qty_for_coverage = purchase_qty_for_coverage / product.suppliersinfo[0].package_qty;
// Round up to unit for all products // Round up to unit for all products
purchase_package_qty_for_coverage = Math.ceil(purchase_package_qty_for_coverage); purchase_package_qty_for_coverage = Math.ceil(purchase_package_qty_for_coverage);
// Set qty to purchase for first supplier only // Set qty to purchase for first supplier only
products[key].suppliersinfo[0].qty = purchase_package_qty_for_coverage; products[key].suppliersinfo[0].qty = purchase_package_qty_for_coverage;
} }
......
...@@ -136,30 +136,52 @@ class CagetteProduct(models.Model): ...@@ -136,30 +136,52 @@ class CagetteProduct(models.Model):
partner_id = data["supplier_id"] partner_id = data["supplier_id"]
package_qty = data["package_qty"] package_qty = data["package_qty"]
price = data["price"] 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)
product = res_products[0]
today = datetime.date.today().strftime("%Y-%m-%d") # Look for existing association
f = ["id"]
c = [['product_tmpl_id', '=', product_tmpl_id], ['name', '=', partner_id]]
res_existing_supplierinfo = api.search_read('product.supplierinfo', c, f)
f = { if (len(res_existing_supplierinfo) > 0):
'product_tmpl_id' : product_tmpl_id, # A relation already exists, update it's start & end dates
'product_id' : product["id"], psi_id = res_existing_supplierinfo[0]['id']
'name' : partner_id,
'product_purchase_ok': product["purchase_ok"],
'price': price,
'base_price': price,
'package_qty': package_qty,
'date_start': today,
'sequence': 1000 # lowest priority for the new suppliers
}
try: today = datetime.date.today().strftime("%Y-%m-%d")
res['create'] = api.create('product.supplierinfo', f)
except Exception as e: f = {
res['error'] = str(e) 'date_start': today,
'date_end': False
}
try:
res["update"] = api.update('product.supplierinfo', psi_id, f)
except Exception as e:
res['error'] = str(e)
else:
# Relation doesn't exists, create one
f = ["id", "standard_price", "purchase_ok"]
c = [['product_tmpl_id', '=', product_tmpl_id]]
res_products = api.search_read('product.product', c, f)
product = res_products[0]
today = datetime.date.today().strftime("%Y-%m-%d")
f = {
'product_tmpl_id' : product_tmpl_id,
'product_id' : product["id"],
'name' : partner_id,
'product_purchase_ok': product["purchase_ok"],
'price': price,
'base_price': price,
'package_qty': package_qty,
'date_start': today,
'sequence': 1000 # lowest priority for the new suppliers
}
try:
res['create'] = api.create('product.supplierinfo', f)
except Exception as e:
res['error'] = str(e)
return res return res
...@@ -174,18 +196,21 @@ class CagetteProduct(models.Model): ...@@ -174,18 +196,21 @@ class CagetteProduct(models.Model):
f = ["id"] f = ["id"]
c = [['product_tmpl_id', '=', product_tmpl_id], ['name', '=', partner_id], ['date_end', '=', False]] c = [['product_tmpl_id', '=', product_tmpl_id], ['name', '=', partner_id], ['date_end', '=', False]]
res_supplierinfo = api.search_read('product.supplierinfo', c, f) res_supplierinfo = api.search_read('product.supplierinfo', c, f)
psi_id = res_supplierinfo[0]['id']
today = datetime.date.today().strftime("%Y-%m-%d") # End all active associations in case multiple are open (which shouldn't happen)
for psi in res_supplierinfo:
psi_id = psi['id']
f = { today = datetime.date.today().strftime("%Y-%m-%d")
'date_end': today
}
try: f = {
res["update"] = api.update('product.supplierinfo', psi_id, f) 'date_end': today
except Exception as e: }
res['error'] = str(e)
try:
res["update"] = api.update('product.supplierinfo', psi_id, f)
except Exception as e:
res['error'] = str(e)
return res return res
......
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