feat: Ajuste Fino Redesenho in the cart (Marcus 12/11, slice R1)
Under each art the Prumo warns about, the customer can choose Ajuste Fino or Ajuste Fino Redesenho (vectorize or redraw, per art, +48 h, no batch price). It is a disabled product until Gestão prices it in the Site tab; the server charges it per chosen art, Tiny gets a DTFIMP.AJF.RED line and two more business days, the card shows 'Redesenho · N artes' and the designer gate applies. The preview loop is slice R2. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,10 +8,21 @@ extra. app/cart_pricing.price_items must return exactly the same list.
|
||||
import unittest
|
||||
from decimal import Decimal
|
||||
|
||||
from uuid import uuid4
|
||||
|
||||
from app import catalog
|
||||
from app.cart_pricing import price_items, treatment_price
|
||||
from app.cart_pricing import (designer_hours, needs_designer, price_items,
|
||||
redesign_price, treatment_price)
|
||||
from app.core import pricing
|
||||
|
||||
try:
|
||||
from pydantic import ValidationError
|
||||
from app.core.models import QuoteRequest
|
||||
except ImportError:
|
||||
# The validate job runs this file on the host, without the runtime image's
|
||||
# dependencies; the runtime suites exercise the model there.
|
||||
QuoteRequest = ValidationError = None
|
||||
|
||||
|
||||
BASE = {'file': 1990, 'avulsa': 2190, 'uvfile': 7990, 'uv': 8990}
|
||||
UV_BANDS = [{'from_metres': '5', 'unit_cents': 8000},
|
||||
@@ -24,6 +35,7 @@ def catalog_now(bands=None, prices=None):
|
||||
now = {mode: {'enabled': True, 'unit_cents': prices[mode],
|
||||
'bands': bands.get(mode, [])} for mode in BASE}
|
||||
now['tratamento'] = {'enabled': True, 'unit_cents': 1000, 'bands': []}
|
||||
now['redesenho'] = {'enabled': True, 'unit_cents': 2990, 'bands': []}
|
||||
return now
|
||||
|
||||
|
||||
@@ -171,6 +183,67 @@ class CartPricingCharacterizationTest(unittest.TestCase):
|
||||
self.assertEqual(treatment_price(items, [], offer), {})
|
||||
self.assertEqual(treatment_price(items, True, {**offer, 'enabled': False}), {})
|
||||
|
||||
def test_redesenho_is_per_art_never_a_band(self):
|
||||
# Front 1b: R$ 29,90 per art, and the basic batch band never applies.
|
||||
offer = {'enabled': True, 'unit_cents': 2990,
|
||||
'bands': [{'from_metres': '10', 'unit_cents': 690}]}
|
||||
items = [item('file', '1', uid='u1'), item('file', '1', uid='u2')]
|
||||
self.assertEqual(redesign_price(items, [[0, 0], [1, 0]], offer),
|
||||
{'cents': 5980, 'hours': 48, 'arts': 2, 'unit_cents': 2990})
|
||||
self.assertEqual(redesign_price(items, [], offer), {})
|
||||
self.assertEqual(redesign_price(items, [[0, 0]], {**offer, 'enabled': False}), {})
|
||||
self.assertEqual(redesign_price(items, [[0, 0]], {**offer, 'unit_cents': 0}), {})
|
||||
|
||||
def test_the_basic_band_counts_only_basic_arts(self):
|
||||
offer = {'enabled': True, 'unit_cents': 990,
|
||||
'bands': [{'from_metres': '10', 'unit_cents': 690}]}
|
||||
items = [item('avulsa', '1', uid=f'u{index}') for index in range(10)]
|
||||
basic = [[index, 0] for index in range(9)]
|
||||
self.assertEqual(treatment_price(items, basic, offer),
|
||||
{'cents': 8910, 'hours': 24, 'arts': 9, 'unit_cents': 990})
|
||||
redesign = redesign_price(items, [[9, 0]], offer={**offer, 'unit_cents': 2990})
|
||||
self.assertEqual(redesign['arts'], 1)
|
||||
|
||||
def test_designer_helpers_read_both_services(self):
|
||||
self.assertEqual(designer_hours({}), 0)
|
||||
self.assertEqual(designer_hours({'treatment': {'cents': 990}}), 24)
|
||||
self.assertEqual(designer_hours({'redesign': {'cents': 2990}}), 48)
|
||||
self.assertEqual(designer_hours({'treatment': {'cents': 990},
|
||||
'redesign': {'cents': 2990}}), 48)
|
||||
self.assertFalse(needs_designer({}))
|
||||
self.assertTrue(needs_designer({'treatment': {'cents': 990}}))
|
||||
self.assertTrue(needs_designer({'redesign': {'cents': 2990}}))
|
||||
|
||||
@unittest.skipUnless(QuoteRequest, 'pydantic is only in the runtime image')
|
||||
def test_a_pair_cannot_be_basic_and_redesenho(self):
|
||||
def quote(treatment=None, redesign=None, items=1):
|
||||
entries = []
|
||||
for _ in range(items):
|
||||
uid = str(uuid4())
|
||||
data = item('avulsa', '1', uid=uid)
|
||||
data['production']['placements'] = [{
|
||||
'source_index': 0, 'copy_index': 0, 'x_cm': 0, 'y_cm': 0,
|
||||
'width_cm': 10, 'length_cm': 10, 'rotation_degrees': 0, 'mirrored': False}]
|
||||
entries.append(data)
|
||||
payload = {'request_key': str(uuid4()),
|
||||
'customer': {'cnpj': '11222333000181', 'zap': '11999999999',
|
||||
'mail': 'arte@example.test'},
|
||||
'items': entries, 'freight': {'service': 'pickup'}}
|
||||
if treatment is not None:
|
||||
payload['treatment'] = treatment
|
||||
if redesign is not None:
|
||||
payload['redesign'] = redesign
|
||||
return payload
|
||||
QuoteRequest.model_validate(quote(treatment=[[0, 0]], redesign=[[1, 0]], items=2))
|
||||
with self.assertRaises(ValidationError):
|
||||
QuoteRequest.model_validate(quote(treatment=[[0, 0]], redesign=[[0, 0]]))
|
||||
with self.assertRaises(ValidationError):
|
||||
QuoteRequest.model_validate(quote(treatment=True, redesign=[[0, 0]]))
|
||||
with self.assertRaises(ValidationError):
|
||||
QuoteRequest.model_validate(quote(redesign=[[0, 0], [0, 0]]))
|
||||
with self.assertRaises(ValidationError):
|
||||
QuoteRequest.model_validate(quote(redesign=[[1, 0]]))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user