fix(configurator): lot pricing robust in totals + SO-create (not reliant on onchange)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -54,3 +54,14 @@ class TestChargeTaxLot(TransactionCase):
|
|||||||
})
|
})
|
||||||
line._onchange_lot_pricing()
|
line._onchange_lot_pricing()
|
||||||
self.assertEqual(line.unit_price, 2.0)
|
self.assertEqual(line.unit_price, 2.0)
|
||||||
|
|
||||||
|
def test_lot_line_subtotal_uses_lot_total(self):
|
||||||
|
# Even if unit_price wasn't derived (onchange didn't fire), the
|
||||||
|
# summary subtotal uses the flat lot_total for lot-priced lines.
|
||||||
|
wiz = self._make_wizard(tax_id=self.tax13.id)
|
||||||
|
self.env['fp.direct.order.line'].create({
|
||||||
|
'wizard_id': wiz.id, 'quantity': 500, 'lot_total': 1000.0,
|
||||||
|
'is_lot_priced': True, 'unit_price': 0.0,
|
||||||
|
})
|
||||||
|
wiz.invalidate_recordset()
|
||||||
|
self.assertEqual(wiz.total_subtotal, 1000.0)
|
||||||
|
|||||||
@@ -403,6 +403,8 @@ class FpDirectOrderWizard(models.Model):
|
|||||||
@api.depends(
|
@api.depends(
|
||||||
'line_ids.quantity',
|
'line_ids.quantity',
|
||||||
'line_ids.unit_price',
|
'line_ids.unit_price',
|
||||||
|
'line_ids.is_lot_priced',
|
||||||
|
'line_ids.lot_total',
|
||||||
'charge_amount',
|
'charge_amount',
|
||||||
'tooling_charge',
|
'tooling_charge',
|
||||||
'tax_id',
|
'tax_id',
|
||||||
@@ -419,7 +421,8 @@ class FpDirectOrderWizard(models.Model):
|
|||||||
"""
|
"""
|
||||||
for rec in self:
|
for rec in self:
|
||||||
subtotal = sum(
|
subtotal = sum(
|
||||||
(l.quantity or 0) * (l.unit_price or 0.0)
|
(l.lot_total or 0.0) if l.is_lot_priced
|
||||||
|
else (l.quantity or 0) * (l.unit_price or 0.0)
|
||||||
for l in rec.line_ids
|
for l in rec.line_ids
|
||||||
)
|
)
|
||||||
charge = rec.charge_amount or rec.tooling_charge or 0.0
|
charge = rec.charge_amount or rec.tooling_charge or 0.0
|
||||||
@@ -853,7 +856,11 @@ class FpDirectOrderWizard(models.Model):
|
|||||||
'product_id': product.id,
|
'product_id': product.id,
|
||||||
'name': line_desc,
|
'name': line_desc,
|
||||||
'product_uom_qty': line.quantity,
|
'product_uom_qty': line.quantity,
|
||||||
'price_unit': line.unit_price or 0.0,
|
'price_unit': (
|
||||||
|
(line.lot_total / line.quantity)
|
||||||
|
if line.is_lot_priced and line.quantity
|
||||||
|
else (line.unit_price or 0.0)
|
||||||
|
),
|
||||||
'x_fc_part_catalog_id': part.id,
|
'x_fc_part_catalog_id': part.id,
|
||||||
'x_fc_description_template_id': line.description_template_id.id or False,
|
'x_fc_description_template_id': line.description_template_id.id or False,
|
||||||
'x_fc_internal_description': line.internal_description or False,
|
'x_fc_internal_description': line.internal_description or False,
|
||||||
|
|||||||
Reference in New Issue
Block a user