feat: each product's metres are summed and rounded once, and the 1 m minimum is once per order (Marcus, 2026-12-03)
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 8m24s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m14s
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 8m24s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m14s
Marcus: "o pedido mínimo de um metro deve ser somente para o primeiro metro, após isso deve se somar a metragem de cada arquivo", "Soma tudo e arredonda uma vez só", and for different products "Pode ser sim": each product apart at its price, the minimum for the whole order. Order #246 (three ready sheets of 3,74, 0,24 and 0,22 m) was 5,80 m with 1 m per item; it is now 4,20 m. pricing.bill_order replaces the per-item minimum and bill_splits: per product the exact lengths (a ready sheet without its gaps) are rounded once with the 8 mm grace, the minimum's difference goes to the first item's product, and each product's total is shared back to its items in 10 cm steps (each its length rounded down, the missing steps to the largest fractions, the minimum to the product's first item), for Tiny's 10 cm SKUs and the cards. A share of 0 m adds no Tiny line. The print file's guard allows an item one 10 cm step under its length. The Site cart shares the same way (cobrarPedido), split sheets round once, the buy box says the items of a product are summed and rounded once, and the Montador's estimate rounds its sum once. Contract: output/revisao/contrato-minimo-pedido.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -621,6 +621,12 @@ try{
|
||||
}finally{carregarPdfJs=realLoader;window.setTimeout=realTimer;temWorker=realWorker;}
|
||||
})()`);
|
||||
assert.deepEqual(timeoutCleanup,{timedOut:true,destroyed:true});
|
||||
// One rounding per product and the 1 m minimum once per order (Marcus,
|
||||
// 2026-12-03): the same shares as app/core/pricing.py bill_order.
|
||||
assert.deepEqual(await evaluate(`cobrarPedido([{modo:'file',exato:3.7364},{modo:'file',exato:0.2447},{modo:'file',exato:0.2164}])`),[3.7,0.3,0.2]);
|
||||
assert.deepEqual(await evaluate(`cobrarPedido([{modo:'file',exato:0.25},{modo:'avulsa',exato:0.31}])`),[0.6,0.4]);
|
||||
assert.deepEqual(await evaluate(`cobrarPedido([{modo:'file',exato:0.3}])`),[1]);
|
||||
assert.deepEqual(await evaluate(`cobrarPedido([{modo:'file',exato:2.004},{modo:'file',exato:3.004}])`),[2,3]);
|
||||
// Proof pop-up (Marcus, 2026-12-02): only above 10 m, not mandatory; closing
|
||||
// it is going on without a proof, and the cart summary follows the answer.
|
||||
assert.deepEqual(await evaluate(`[pedidoLongo([{cob:10}]),pedidoLongo([{cob:6},{cob:4.5}])]`),[false,true]);
|
||||
@@ -653,6 +659,6 @@ try{
|
||||
console.log('Supplied image:',JSON.stringify(layout));
|
||||
}
|
||||
assert.deepEqual(errors,[]);
|
||||
console.log('PASS: PNG upload and drop, JPG refused, packed copies, 5 mm gaps, aspect ratio, live width/quantity/rotation/mirror, metres, ready-sheet pricing/repeats, residue and solid background stop the order, UV, proof pop-up above 10 m, stale renders, strict inline CSP.');
|
||||
console.log('PASS: PNG upload and drop, JPG refused, packed copies, 5 mm gaps, aspect ratio, live width/quantity/rotation/mirror, metres, ready-sheet pricing/repeats, residue and solid background stop the order, UV, proof pop-up above 10 m, one rounding per product, stale renders, strict inline CSP.');
|
||||
}catch(error){console.error(error);if(stderr)console.error(stderr.slice(-1200));process.exitCode=1;}
|
||||
finally{ws?.close();chrome.kill();server.closeAllConnections();await new Promise(r=>server.close(r));}
|
||||
|
||||
@@ -148,7 +148,11 @@ def carts():
|
||||
|
||||
class CartPricingCharacterizationTest(unittest.TestCase):
|
||||
def test_price_items_matches_todays_approval(self):
|
||||
# Since 2026-12-03 the 1 m minimum is once per order, not per item:
|
||||
# only a cart with an item under 1 m beside others bills differently.
|
||||
for name, cart in carts().items():
|
||||
if name == 'mixed-modes':
|
||||
continue
|
||||
with self.subTest(cart=name):
|
||||
self.assertEqual(
|
||||
price_items(cart['items'], cart['names'], cart['catalog'], cart['manual']),
|
||||
@@ -170,6 +174,26 @@ class CartPricingCharacterizationTest(unittest.TestCase):
|
||||
floating = priced('band-floating-metres')[0]
|
||||
self.assertEqual((floating['billed_metres'], floating['total_cents']), ('2.8', 23800))
|
||||
|
||||
def test_one_rounding_per_product_and_one_minimum_per_order(self):
|
||||
# Marcus, 2026-12-03: "Soma tudo e arredonda uma vez só"; the minimum
|
||||
# once for the order; products apart, each at its price ("Pode ser sim").
|
||||
lengths = ['3.7364', '0.2447', '0.2164'] # order #246, three ready sheets
|
||||
priced = price_items([item('file', m, uid=f'u{i}') for i, m in enumerate(lengths)],
|
||||
{}, catalog_now(), 0)
|
||||
self.assertEqual([p['billed_metres'] for p in priced], ['3.7', '0.3', '0.2'])
|
||||
self.assertEqual(sum(p['total_cents'] for p in priced), 8358) # 4,20 m, not 5,80 m
|
||||
# An item under 1 m beside others is not raised to 1 m any more.
|
||||
mixed = carts()['mixed-modes']
|
||||
priced = price_items(mixed['items'], mixed['names'], mixed['catalog'], 0)
|
||||
self.assertEqual([p['billed_metres'] for p in priced], ['1', '2', '0.5', '3'])
|
||||
# Alone under 1 m: the order minimum, on the first item.
|
||||
self.assertEqual(price_items([item('file', '0.3')], {}, catalog_now(), 0)[0]['billed_metres'], '1')
|
||||
# Two products under 1 m together: the difference on the first one's product.
|
||||
priced = price_items([item('file', '0.25', uid='u1'), item('avulsa', '0.31', uid='u2')],
|
||||
{'u1': 'A.PNG', 'u2': 'B.PNG'}, catalog_now(), 0)
|
||||
self.assertEqual([p['billed_metres'] for p in priced], ['0.6', '0.4'])
|
||||
self.assertEqual(sum(p['total_cents'] for p in priced), 6 * 199 + 4 * 219)
|
||||
|
||||
def test_a_ready_sheet_is_billed_without_its_gaps(self):
|
||||
# Marcus, 2026-12-03 ("por hora pode tirar a cobrança"): the Lais case,
|
||||
# one 100 cm sheet and another with 4 copies, 4 gaps of 8 mm = 503,2 cm.
|
||||
|
||||
@@ -37,7 +37,7 @@ class SheetGapTests(unittest.TestCase):
|
||||
item = sheet(copies=10).model_dump(mode='json')
|
||||
item['billed_metres'] = '2'
|
||||
check_layout(item, [(5700, 2000)])
|
||||
item['billed_metres'] = '1.9'
|
||||
item['billed_metres'] = '1.8' # more than one 10 cm step short
|
||||
with self.assertRaises(Unsupported):
|
||||
check_layout(item, [(5700, 2000)])
|
||||
|
||||
|
||||
@@ -660,6 +660,16 @@ class TinySkuTests(FakeTinyCase):
|
||||
self.tiny.deliver('k3', TEXTIL)
|
||||
self.assertNotIn(('POST', '/pedidos'), self.calls)
|
||||
|
||||
def test_an_item_sharing_no_metres_has_no_line(self):
|
||||
# One rounding per product (Marcus, 2026-12-03): a very short sheet
|
||||
# beside others may share 0 m of the total; it adds no Tiny line.
|
||||
self.tiny.deliver('k1', TEXTIL)
|
||||
zero = {**TEXTIL['order']['items'][0], 'billed_metres': '0', 'total_cents': 0}
|
||||
with_zero = {**TEXTIL, 'number': 43, 'order': {**TEXTIL['order'],
|
||||
'items': TEXTIL['order']['items'] + [zero]}}
|
||||
self.tiny.deliver('k2', with_zero)
|
||||
self.assertEqual(len(self.orders[1]['itens']), len(self.orders[0]['itens']))
|
||||
|
||||
def test_other_modes_keep_their_product_id(self):
|
||||
self.tiny.deliver('k4', PAID)
|
||||
self.assertEqual(self.orders[0]['itens'][0]['produto'], {'id': 102})
|
||||
|
||||
Reference in New Issue
Block a user