hello, i have a doctype named ‘part’ with a table on it named ‘provider_part’, in a python y scripted a function that call a api and assign the prices to a variable named a1.
i customize a button who runs the function on ‘part’
on ‘provider_part’ i have a custom fields named in function of the quantity of the product where i want to save the prices that returns me the api.
the problem is: when i push the button, he runs the code on python, but that didn’t set the prices where i want
there are some pictures and code:
@frappe.whitelist()
def octopart_api(part,name):
objPart = frappe.get_doc(part,name)
queries = [{'mpn':objPart.mpn}]
queries = json.dumps(queries)
octoKey = {'apikey':'8c941dcc','queries':queries}
obj = requests.get("https://octopart.com/api/v3/parts/match",params = octoKey)
print(obj.url)
obj = obj.json()
for offer in objPart.part_provider:
a1 = []
for offerOct in obj["results"][0]["items"][0]["offers"]:
if offerOct["seller"]["name"] == offer.provider:
if offerOct["prices"].has_key("USD"):
aux=offerOct["prices"]["USD"]
a1.append(aux)
if len(a1) == 0:
print ('a1 = error')
else:
for uprice in a1[0]:
if uprice[0] <= 10000:
tablaplace = getattr(offer,'10000')
tablaplace =
elif uprice[0] <= 5000:
tablaplace = getattr(offer,'5000')
tablaplace = float(uprice[1])
elif uprice[0] <= 1000:
tablaplace = getattr(offer,'1000')
tablaplace = float(uprice[1])
elif uprice[0] <= 500:
tablaplace = getattr(offer,'500')
tablaplace = float(uprice[1])
elif uprice[0] <= 100:
tablaplace = getattr(offer,'100')
tablaplace = float(uprice[1])
elif uprice[0] <= 50:
tablaplace = getattr(offer,'50')
tablaplace = float(uprice[1])
elif uprice[0] <= 25:
tablaplace = getattr(offer,'25')
tablaplace = float(uprice[1])
elif uprice[0] <= 10:
tablaplace = getattr(offer,'10')
tablaplace = float(uprice[1])
elif uprice[0] <= 1:
tablaplace = getattr(offer,'1')
tablaplace = float(uprice[1])