feat: progressive price bands per product (front 8.2)

A price may carry up to five bands, "from N m, R$ Y": the order's total
billed metres of that product chooses one price for its whole quantity,
the manual-file extra still on top. Bands start and become history with
their price row. The Site charges the same band for the cart, shows
"Faltam X m para R$ Y o metro" and lists the bands under the price
table; the Kanban's Site tab edits them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-09 14:30:15 -03:00
parent c5e7a80b64
commit 2a6732eb37
16 changed files with 334 additions and 23 deletions

View File

@@ -81,6 +81,37 @@ def run():
assert approved['items'][0]['unit_cents'] == 12345, approved
assert approved['items'][0]['total_cents'] == 12345, approved
# Bands (front 8.2): from 2 m the metre costs less; two items of uv
# (2 m together) pay the band price on both.
made = manager.call(f'/operator/site/products/{UV}/prices', {
'unit_cents': 12345, 'bands': [{'from_metres': '2', 'unit_cents': 10000}]})
prices.append(made['id'])
bands = client.call('/session')['products'][UV]['bands']
assert bands == [{'from_metres': 2.0, 'unit_cents': 10000}], bands
entry = next(product for product in manager.call('/operator/site/products')['products']
if product['id'] == UV)
assert entry['bands'] == [{'from_metres': '2', 'unit_cents': 10000}], entry
banded = client.call('/quotes', {'request_key': str(uuid4()),
'customer': {'cnpj': '11222333000181', 'zap': '11999999999', 'mail': mail},
'items': [item, item], 'freight': {'service': 'pickup'}})
assert banded['status'] == 'approved', banded
approved = client.call('/quotes/' + banded['id'])['approved']
assert [line['unit_cents'] for line in approved['items']] == [10000, 10000], approved
assert [line['total_cents'] for line in approved['items']] == [10000, 10000], approved
assert approved['total_cents'] == 20000, approved
# Invalid bands are refused with 422 and do not become prices.
manager.call(f'/operator/site/products/{UV}/prices', {
'unit_cents': 12345, 'bands': [{'from_metres': '5', 'unit_cents': 1900},
{'from_metres': '5', 'unit_cents': 1800}]}, expected=422)
manager.call(f'/operator/site/products/{UV}/prices', {
'unit_cents': 12345, 'bands': [{'from_metres': '0', 'unit_cents': 1900}]}, expected=422)
manager.call(f'/operator/site/products/{UV}/prices', {
'unit_cents': 12345, 'bands': [{'from_metres': str(i), 'unit_cents': 1900}
for i in range(1, 7)]}, expected=422)
manager.call('/operator/site/products/tratamento/prices', {
'unit_cents': 1000, 'bands': [{'from_metres': '5', 'unit_cents': 900}]}, expected=422)
# A profile without "manage" cannot see or change the Site tab.
email = f'site-staff-{tag}@example.test'
user = manager.call('/operator/users', {'name': 'Teste Site', 'email': email,