feat(configurator): per-line lot pricing (derive unit price, keep qty)

This commit is contained in:
gsinghpal
2026-05-29 21:38:49 -04:00
parent f8929eb686
commit a2ac804238
2 changed files with 25 additions and 0 deletions

View File

@@ -44,3 +44,13 @@ class TestChargeTaxLot(TransactionCase):
self.assertEqual(wiz.total_subtotal, 50.0)
self.assertAlmostEqual(wiz.total_tax, 19.5, places=2)
self.assertAlmostEqual(wiz.total_amount, 169.5, places=2)
# ----- Task 4: lot pricing -----
def test_lot_onchange_derives_unit_price(self):
wiz = self._make_wizard()
line = self.env['fp.direct.order.line'].new({
'wizard_id': wiz.id, 'quantity': 500, 'lot_total': 1000.0,
'is_lot_priced': True,
})
line._onchange_lot_pricing()
self.assertEqual(line.unit_price, 2.0)

View File

@@ -238,6 +238,21 @@ class FpDirectOrderLine(models.Model):
string='Unit Price',
currency_field='currency_id',
)
is_lot_priced = fields.Boolean(
string='Lot Price',
help='Price the whole quantity as a flat lot total instead of '
'per unit. Unit price is derived = lot total / quantity; '
'the quantity is preserved for production.',
)
lot_total = fields.Monetary(
string='Lot Total', currency_field='currency_id',
)
@api.onchange('is_lot_priced', 'lot_total', 'quantity')
def _onchange_lot_pricing(self):
for line in self:
if line.is_lot_priced and line.quantity:
line.unit_price = (line.lot_total or 0.0) / line.quantity
line_subtotal = fields.Monetary(
string='Subtotal',
currency_field='currency_id',