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;
} }
......
...@@ -137,6 +137,28 @@ class CagetteProduct(models.Model): ...@@ -137,6 +137,28 @@ class CagetteProduct(models.Model):
package_qty = data["package_qty"] package_qty = data["package_qty"]
price = data["price"] price = data["price"]
# 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)
if (len(res_existing_supplierinfo) > 0):
# A relation already exists, update it's start & end dates
psi_id = res_existing_supplierinfo[0]['id']
today = datetime.date.today().strftime("%Y-%m-%d")
f = {
'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"] 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)
...@@ -174,7 +196,10 @@ class CagetteProduct(models.Model): ...@@ -174,7 +196,10 @@ 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']
# End all active associations in case multiple are open (which shouldn't happen)
for psi in res_supplierinfo:
psi_id = psi['id']
today = datetime.date.today().strftime("%Y-%m-%d") today = datetime.date.today().strftime("%Y-%m-%d")
......
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