Good morning.
If I update a custom module after having edited the python code, (sao or ssh / all 3 py_cache dirs deleted), sometimes the code is written as if nothing had changed. (tested 20 times in a row with the same python code)
The day after, whereas I haven’t done anything since the day before, the code is executed with the changes.
ced
(Cédric Krier)
October 17, 2019, 3:36pm
2
What kind of Python code?
Did you restart the server? Did you restart the client?
I meant “read” instead of “written”.
I restart trytond.service and ip:8000 before calling the cronjob again.
This kind of code :
wcapi = API(
url="https://www.xyz.com/",
consumer_key='aaaaaaaaaaaaaaaaaaaaaaaa', #"clé 003"
consumer_secret='bbbbbbbbbbbbbbbbbbbbbbbbb',
#wp_api=True,
#version="wc/v3",
#query_string_auth=True,
#verify_ssl=False
)
############################################### produits ###############################################
d1 = datetime.datetime.now()
d2 = datetime.datetime.strptime(d1.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S') + datetime.timedelta(days=-10, hours=2, minutes=-15)
WP_obj = Pool().get('woocommerce.products')
dicts = []
for product in wcapi.get("products").json():
if product['id'] is not None and WP_obj.search_count(('product_id', '=', product['id'])) == 0:
#if (datetime.datetime.strptime(product['id'], '%Y-%m-%dT%H:%M:%S') > d2):
dict = {'json':str(product), 'product_id':product['id']}
dicts.append(dict)
if len(dicts) != 0:
WP_obj.create(dicts)
dicts = []
f = codecs.open('/opt/clients/paging/woocommerce_api/WoocommerceProducts_' + d1.strftime('%Y_%m_%d_%H_%M_%S') + '.txt', mode='ab+', encoding="utf-8")
datas = '' + str(product['id']) + "\r\n" + str(product) + "\r\n\n"
f.write(datas)
f.close()
dicts_tryton_product_template = []
tryton_product_template = {
'name':product['name'],
'salable':True,
'default_uom':1,
'sale_uom':1,
'account_category':1
}
WPrTe_obj = Pool().get('product.template')
dicts_tryton_product_template.append(tryton_product_template)
new_pt_ids = WPrTe_obj.create(dicts_tryton_product_template)
for t in WPrTe_obj.browse(new_pt_ids):
product_template_id = t.id
dicts_tryton_product = []
tryton_product = {
'template':product_template_id,
'description':product['description'],
'id_produit_woocommerce':product['id']
}
dicts_tryton_product.append(tryton_product)
WPP_obj = Pool().get('product.product')
new_p_ids = WPP_obj.create(dicts_tryton_product)
for p in WPP_obj.browse(new_p_ids):
product_id = p.id
dicts_tryton_product_cost_price = []
tryton_product_cost_price = {
'product':product_id,
'cost_price':product['price'],
'company':1
}
dicts_tryton_product_cost_price.append(tryton_product_cost_price)
WCP_obj = Pool().get('product.cost_price')
WCP_obj.create(dicts_tryton_product_cost_price)
# delete record cost price = 0
cp_ids = WCP_obj.search([('product', '=', product_id),('cost_price', '=', 0),('company', '=', 1)])
WCP_obj.delete(WCP_obj.browse(cp_ids))
dicts_tryton_product_list_price = []
tryton_list_price = {
'template':product_template_id,
# on n'a pas le prix de revient
#'list_price':product['regular_price']
'list_price':product['price']
}
dicts_tryton_product_list_price.append(tryton_list_price)
WLP_obj = Pool().get('product.list_price')
WLP_obj.create(dicts_tryton_product_list_price)