fix(configurator): margin % stored as fraction so widget='percentage' formats right
Phase D8 compute was returning x_fc_margin_percent already-multiplied by 100, but the 'percentage' widget in the SO form multiplies again for display. Result was 10000% instead of 100%. Store as 0.0-1.0 fraction; widget handles the multiplier. Caught during UAT on S00066. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -486,19 +486,23 @@ class SaleOrder(models.Model):
|
|||||||
|
|
||||||
@api.depends('order_line.price_subtotal', 'amount_untaxed')
|
@api.depends('order_line.price_subtotal', 'amount_untaxed')
|
||||||
def _compute_margin(self):
|
def _compute_margin(self):
|
||||||
"""Simple margin: untaxed total minus rolled-up cost from coating configs."""
|
"""Simple margin: untaxed total minus rolled-up cost from coating configs.
|
||||||
|
|
||||||
|
x_fc_margin_percent is stored as a fraction (0.0 - 1.0) so the
|
||||||
|
widget='percentage' formats it correctly (a 100% margin reads
|
||||||
|
as 100%, not 10000%).
|
||||||
|
"""
|
||||||
for rec in self:
|
for rec in self:
|
||||||
cost = 0.0
|
cost = 0.0
|
||||||
for line in rec.order_line:
|
for line in rec.order_line:
|
||||||
if line.x_fc_coating_config_id:
|
if line.x_fc_coating_config_id:
|
||||||
# If coating_config has a cost field, use it; otherwise 0.
|
|
||||||
cost_per_unit = getattr(
|
cost_per_unit = getattr(
|
||||||
line.x_fc_coating_config_id, 'unit_cost', 0.0,
|
line.x_fc_coating_config_id, 'unit_cost', 0.0,
|
||||||
) or 0.0
|
) or 0.0
|
||||||
cost += cost_per_unit * (line.product_uom_qty or 0)
|
cost += cost_per_unit * (line.product_uom_qty or 0)
|
||||||
rec.x_fc_margin_amount = (rec.amount_untaxed or 0) - cost
|
rec.x_fc_margin_amount = (rec.amount_untaxed or 0) - cost
|
||||||
rec.x_fc_margin_percent = (
|
rec.x_fc_margin_percent = (
|
||||||
(rec.x_fc_margin_amount / rec.amount_untaxed * 100.0)
|
(rec.x_fc_margin_amount / rec.amount_untaxed)
|
||||||
if rec.amount_untaxed else 0.0
|
if rec.amount_untaxed else 0.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user