Skip to content

Commit c7143dd

Browse files
committed
fix bugs in example 002
1 parent 0c2bd2f commit c7143dd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

examples/002-extra-field-to-column.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
CURRENCY_EUROS = 4
2121

2222
# we need to use _preload_content=False here so we can access the metadata properly
23-
response = items_client.read_items(cat=1, limit=9999, _preload_content=False)
23+
response = items_client.read_items(cat=RESOURCE_CATEGORY_ID, limit=9999, _preload_content=False)
2424
items = json.loads(response.data.decode('utf-8'))
2525
for item in items:
2626
metadata = item.get('metadata', None)
@@ -31,8 +31,13 @@
3131
meta = json.loads(metadata)
3232
extra_fields = meta.get('extra_fields', None)
3333
if extra_fields is not None:
34-
proc_pack_qty = extra_fields.get("Quantity", 1).get("value")
35-
proc_price_notax = extra_fields.get("Price", 0.00).get("value")
34+
proc_pack_qty = extra_fields.get("Quantity", {"value": "1"}).get("value")
35+
proc_price_notax = extra_fields.get("Price", {"value": "0.00"}).get("value")
36+
# ensure we have a dot separator and a string
37+
proc_price_notax = str(proc_price_notax).replace(",",".")
38+
# ensure empty value is 0.00
39+
if proc_price_notax == "":
40+
proc_price_notax = "0.00"
3641
proc_price_tax = float(proc_price_notax) * 1.2
3742
# no patch the item with these values
3843
print(f"INFO: Patching item with id {item.get('id')}")

0 commit comments

Comments
 (0)