Skip to content

Commit

Permalink
refactor(GDPR): Use new Price.receipt_quantity field. ref #499
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Oct 22, 2024
1 parent 783309f commit 64fcd80
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions scripts/gdpr/create_prices_from_gdpr_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"product_name",
"price",
"discount", # extra
"quantity", # extra
"receipt_quantity",
"currency",
"location", # extra
"location_osm_id",
Expand Down Expand Up @@ -47,7 +47,7 @@ def gdpr_source_field_cleanup_rules(gdpr_source, op_field, gdpr_field_value):
gdpr_field_value = gdpr_field_value.strip()

# field-specific rules
if op_field in ["price", "quantity"]:
if op_field in ["price", "receipt_quantity"]:
if gdpr_field_value:
gdpr_field_value = float(gdpr_field_value.replace(",", "."))

Expand Down Expand Up @@ -92,10 +92,12 @@ def gdpr_source_price_cleanup_rules(gdpr_source, gdpr_op_price):
"""
Rules to cleanup the price object
"""
# price must be divided by quantity
if "quantity" in gdpr_op_price:
if gdpr_op_price["quantity"]:
gdpr_op_price["price"] = gdpr_op_price["price"] / gdpr_op_price["quantity"]
# price must be divided by receipt_quantity
if "receipt_quantity" in gdpr_op_price:
if gdpr_op_price["receipt_quantity"]:
gdpr_op_price["price"] = str(
round(gdpr_op_price["price"] / gdpr_op_price["receipt_quantity"], 2)
)

# discount boolean flag
if "discount" in gdpr_op_price:
Expand Down Expand Up @@ -134,7 +136,7 @@ def gdpr_source_filter_rules(op_price_list, gdpr_source=""):
passes_test = False
elif op_price["discount"]:
passes_test = False
elif op_price["quantity"].startswith("-"):
elif op_price["receipt_quantity"].startswith("-"):
passes_test = False
elif gdpr_source == "ELECLERC":
if len(op_price["product_code"]) < 6:
Expand Down

0 comments on commit 64fcd80

Please sign in to comment.