feat(price): detect quantity discounts via baseprice, show Disc. badge
GoMag sends baseprice (catalog price) alongside price (discounted). When baseprice > price, the item is volume-discounted — skip ROA price comparison and show amber "Disc." badge instead of false mismatch. Strikethrough baseprice in price column for transparency. Pipeline: parse baseprice → store in SQLite → skip in validation → pass flag to frontend → render badge (desktop + mobile pill badge with aria-label, opacity 0.6 for dark mode). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@ class OrderItem:
|
||||
price: float
|
||||
quantity: float
|
||||
vat: float
|
||||
baseprice: float = 0.0
|
||||
|
||||
@dataclass
|
||||
class OrderBilling:
|
||||
@@ -116,7 +117,8 @@ def _parse_order(order_id: str, data: dict, source_file: str) -> OrderData:
|
||||
name=str(item.get("name", "")),
|
||||
price=float(item.get("price", 0) or 0),
|
||||
quantity=float(item.get("quantity", 0) or 0),
|
||||
vat=float(item.get("vat", 0) or 0)
|
||||
vat=float(item.get("vat", 0) or 0),
|
||||
baseprice=float(item.get("baseprice", 0) or 0)
|
||||
))
|
||||
|
||||
# Parse billing
|
||||
|
||||
@@ -200,16 +200,17 @@ async def save_orders_batch(orders_data: list[dict]):
|
||||
all_items.append((
|
||||
d["order_number"],
|
||||
item.get("sku"), item.get("product_name"),
|
||||
item.get("quantity"), item.get("price"), item.get("vat"),
|
||||
item.get("quantity"), item.get("price"), item.get("baseprice"),
|
||||
item.get("vat"),
|
||||
item.get("mapping_status"), item.get("codmat"),
|
||||
item.get("id_articol"), item.get("cantitate_roa")
|
||||
))
|
||||
if all_items:
|
||||
await db.executemany("""
|
||||
INSERT OR IGNORE INTO order_items
|
||||
(order_number, sku, product_name, quantity, price, vat,
|
||||
mapping_status, codmat, id_articol, cantitate_roa)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
(order_number, sku, product_name, quantity, price, baseprice,
|
||||
vat, mapping_status, codmat, id_articol, cantitate_roa)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""", all_items)
|
||||
|
||||
await db.commit()
|
||||
@@ -535,13 +536,14 @@ async def add_order_items(order_number: str, items: list):
|
||||
try:
|
||||
await db.executemany("""
|
||||
INSERT OR IGNORE INTO order_items
|
||||
(order_number, sku, product_name, quantity, price, vat,
|
||||
mapping_status, codmat, id_articol, cantitate_roa)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
(order_number, sku, product_name, quantity, price, baseprice,
|
||||
vat, mapping_status, codmat, id_articol, cantitate_roa)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""", [
|
||||
(order_number,
|
||||
item.get("sku"), item.get("product_name"),
|
||||
item.get("quantity"), item.get("price"), item.get("vat"),
|
||||
item.get("quantity"), item.get("price"), item.get("baseprice"),
|
||||
item.get("vat"),
|
||||
item.get("mapping_status"), item.get("codmat"),
|
||||
item.get("id_articol"), item.get("cantitate_roa"))
|
||||
for item in items
|
||||
|
||||
@@ -265,7 +265,8 @@ async def run_sync(id_pol: int = None, id_sectie: int = None, run_id: str = None
|
||||
shipping_name, billing_name, customer, payment_method, delivery_method = _derive_customer_info(order)
|
||||
order_items_data = [
|
||||
{"sku": item.sku, "product_name": item.name,
|
||||
"quantity": item.quantity, "price": item.price, "vat": item.vat,
|
||||
"quantity": item.quantity, "price": item.price,
|
||||
"baseprice": item.baseprice, "vat": item.vat,
|
||||
"mapping_status": "unknown", "codmat": None,
|
||||
"id_articol": None, "cantitate_roa": None}
|
||||
for item in order.items
|
||||
@@ -590,7 +591,8 @@ async def run_sync(id_pol: int = None, id_sectie: int = None, run_id: str = None
|
||||
id_comanda_roa = existing_map.get(order.number)
|
||||
order_items_data = [
|
||||
{"sku": item.sku, "product_name": item.name,
|
||||
"quantity": item.quantity, "price": item.price, "vat": item.vat,
|
||||
"quantity": item.quantity, "price": item.price,
|
||||
"baseprice": item.baseprice, "vat": item.vat,
|
||||
"mapping_status": "mapped" if item.sku in validation["mapped"] else "direct",
|
||||
"codmat": None, "id_articol": None, "cantitate_roa": None}
|
||||
for item in order.items
|
||||
@@ -630,7 +632,8 @@ async def run_sync(id_pol: int = None, id_sectie: int = None, run_id: str = None
|
||||
shipping_name, billing_name, customer, payment_method, delivery_method = _derive_customer_info(order)
|
||||
order_items_data = [
|
||||
{"sku": item.sku, "product_name": item.name,
|
||||
"quantity": item.quantity, "price": item.price, "vat": item.vat,
|
||||
"quantity": item.quantity, "price": item.price,
|
||||
"baseprice": item.baseprice, "vat": item.vat,
|
||||
"mapping_status": "missing" if item.sku in validation["missing"] else
|
||||
"mapped" if item.sku in validation["mapped"] else "direct",
|
||||
"codmat": None, "id_articol": None, "cantitate_roa": None}
|
||||
@@ -778,7 +781,8 @@ async def run_sync(id_pol: int = None, id_sectie: int = None, run_id: str = None
|
||||
ms = "mapped" if item.sku in validation["mapped"] else "direct"
|
||||
order_items_data.append({
|
||||
"sku": item.sku, "product_name": item.name,
|
||||
"quantity": item.quantity, "price": item.price, "vat": item.vat,
|
||||
"quantity": item.quantity, "price": item.price,
|
||||
"baseprice": item.baseprice, "vat": item.vat,
|
||||
"mapping_status": ms, "codmat": None, "id_articol": None,
|
||||
"cantitate_roa": None
|
||||
})
|
||||
|
||||
@@ -714,6 +714,13 @@ def get_prices_for_order(items: list[dict], app_settings: dict, conn=None) -> di
|
||||
result_items[idx]["kit"] = True
|
||||
continue
|
||||
|
||||
# Quantity discount: baseprice > price means GoMag applied a volume discount
|
||||
baseprice = float(item.get("baseprice") or 0)
|
||||
if baseprice > 0 and baseprice > pret_gomag + 0.01:
|
||||
result_items[idx]["quantity_discount"] = True
|
||||
result_items[idx]["baseprice"] = baseprice
|
||||
continue
|
||||
|
||||
pret_roa_total = 0.0
|
||||
all_resolved = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user