dodil/erp-brick-product
tests/test_v6.py
"""Spec v6: the price answer's line carries category_code, PRD-40 (a whole list on a date), make/mrp when manufacturing is composed."""
from conftest import DEFAULT, PRICING, SALES, api, categories, mk_list, mk_product, must, row
from erp_platform import seam
from fastapi import FastAPI
from test_v4_slice_b import TOMORROW, cola75, inventory, site # noqa: F401
def test_the_price_answers_line_carries_the_products_category_code():
categories(("FOOD", None), ("COFFEE", "FOOD"))
mk_product("HOST-M", category_code="COFFEE")
mk_list("LIST-GBP", rows=[row("HOST-M", "2026-11-01", "120.00")], default_from=DEFAULT)
line = must(api("GET", "/products/HOST-M/price", SALES, {"currency": "GBP"}))["line"]
assert line["category_code"] == "COFFEE"
def test_prd40_a_whole_published_list_on_a_date_with_the_day_it_goes_stale():
mk_product("HOST-M")
mk_product("HOST-L", name="Hosting large")
mk_list("LIST-GBP", rows=[row("HOST-M", "2026-11-01", "120.00"), row("HOST-L", "2026-11-01", "300.00"),
row("HOST-L", "2026-12-01", "320.00")], default_from=DEFAULT)
out = must(api("GET", "/price-lists/LIST-GBP/prices", SALES, {"on": "2026-11-20"}))
assert [(p["product_id"], p["unit_code"], p["from_quantity"], p["unit_price"]) for p in out["prices"]] == \
[("HOST-L", "MON", "1", "300.00"), ("HOST-M", "MON", "1", "120.00")]
assert out["next_change_on"] == "2026-12-01" and out["currency"] == "GBP" and out["more"] is False and out["prices_include_tax"] is False
later = must(api("GET", "/price-lists/LIST-GBP/prices", SALES, {"on": "2026-12-05"}))
assert [p["unit_price"] for p in later["prices"]] == ["320.00", "120.00"] and later["next_change_on"] is None
page = must(api("GET", "/price-lists/LIST-GBP/prices", SALES, {"on": "2026-11-20", "limit": 1}))
assert len(page["prices"]) == 1 and page["more"] is True
# the same answers find_price gives
for p in out["prices"]:
assert must(api("GET", f"/products/{p['product_id']}/price", SALES, {"currency": "GBP", "priced_on": "2026-11-20"}))["unit_price"] == p["unit_price"]
def test_prd40_a_draft_list_is_a_404():
mk_product("HOST-M")
mk_list("LIST-DRAFT", rows=[row("HOST-M", "2026-11-01", "120.00")], publish=False)
assert api("GET", "/price-lists/LIST-DRAFT/prices", SALES, {})[0] == 404
assert api("GET", "/price-lists/LIST-DRAFT/prices", PRICING, {})[0] == 404
def test_make_and_mrp_are_accepted_only_when_manufacturing_is_in_the_composition(inventory):
cola75()
for kw in ({"procurement_type": "make"}, {"planning_method": "mrp"}):
s, b = site("WH1", **kw)
assert s == 409 and "need the production module" in b["detail"] # gate manufacturing_installed
seam.register_local("manufacturing", FastAPI())
try:
made = must(site("WH1", procurement_type="make", planning_method="mrp"))
assert (made["procurement_type"], made["planning_method"], made["valid_from"]) == ("make", "mrp", TOMORROW)
finally:
seam.unregister_local("manufacturing")