fix(configurator): money fields now show $ everywhere

Root cause: pricing.rule records had currency_id=NULL because the
default=lambda only applies on new records. Monetary fields without a
currency silently render as plain numbers — no $ symbol.

Fixes:

1. currency_id now required=True on fp.pricing.rule, fp.treatment,
   fp.customer.price.list, fp.quote.configurator, fusion.plating.quote.request
   — so it can never be missing going forward.

2. post_init_hook + matching backfill helper in
   fusion_plating_configurator/__init__.py pins the company currency
   on any existing records that were created before the required flag.
   Ran on upgrade → all 4 pricing.rule rows now have CAD/$.

3. Flipped two remaining Float money fields to Monetary:
   - fp.job.consumption.unit_cost and total_cost (were Float digits=4/2)
   - (mrp.workorder.x_fc_workcenter_cost_hour stays Float — it is a
     related field from core mrp.workcenter.costs_hour which is Float)

4. Every Monetary field reference in views now has explicit:
     widget="monetary" options="{'currency_field': 'currency_id'}"
   Previously Odoo's default rendering dropped the $ in some contexts.
   Touched: fp_pricing_rule_views (list + form), fp_treatment_views,
   fp_customer_price_list_views (already done), fp_quote_configurator_views
   (list + form shipping/delivery/calculated/override), fp_quote_request_views
   (list + form), fp_job_consumption_views, mrp_production_views job-costing
   group, direct-order wizard (already done earlier).

5. Unit / % suffix polish as we went: rush_surcharge_percent shows "%",
   default_duration_minutes shows "min" on treatment form, treatment list
   labels duration column.

Verified: all 4 pricing rules now render "$0.45", "$0.85" etc; 62 records
across 6 models all have currency_id populated; zero remaining Float $
fields in the codebase.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsinghpal
2026-04-17 18:54:14 -04:00
parent b85642816f
commit 70fe10c214
14 changed files with 116 additions and 43 deletions

View File

@@ -40,15 +40,17 @@ class FpJobConsumption(models.Model):
uom_id = fields.Many2one(
'uom.uom', string='UoM',
)
unit_cost = fields.Float(
string='Unit Cost (snapshot)', digits=(12, 4),
currency_id = fields.Many2one(
'res.currency', required=True,
default=lambda self: self.env.company.currency_id,
)
unit_cost = fields.Monetary(
string='Unit Cost (snapshot)', currency_field='currency_id',
help='Taken from product.standard_price at log time.',
)
total_cost = fields.Float(
string='Total Cost', compute='_compute_total_cost', store=True, digits=(12, 2),
)
currency_id = fields.Many2one(
'res.currency', default=lambda self: self.env.company.currency_id,
total_cost = fields.Monetary(
string='Total Cost', currency_field='currency_id',
compute='_compute_total_cost', store=True,
)
logged_date = fields.Datetime(
string='Logged', default=fields.Datetime.now,

View File

@@ -12,10 +12,12 @@
<field name="product_id"/>
<field name="quantity"/>
<field name="uom_id"/>
<field name="unit_cost"/>
<field name="total_cost" sum="Total"/>
<field name="currency_id" column_invisible="1"/>
<field name="unit_cost" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="total_cost" widget="monetary"
options="{'currency_field': 'currency_id'}" sum="Total"/>
<field name="source"/>
<field name="currency_id" invisible="1"/>
<field name="logged_by_id" optional="hide"/>
</list>
</field>
@@ -38,9 +40,11 @@
<group>
<field name="quantity"/>
<field name="uom_id"/>
<field name="unit_cost"/>
<field name="total_cost" readonly="1"/>
<field name="currency_id" invisible="1"/>
<field name="currency_id"/>
<field name="unit_cost" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="total_cost" widget="monetary"
options="{'currency_field': 'currency_id'}" readonly="1"/>
<field name="logged_date"/>
<field name="logged_by_id"/>
</group>

View File

@@ -29,17 +29,22 @@
<field name="x_fc_currency_id" invisible="1"/>
<group>
<field name="x_fc_quoted_revenue" readonly="1"
widget="monetary"/>
widget="monetary"
options="{'currency_field': 'x_fc_currency_id'}"/>
<field name="x_fc_labour_cost" readonly="1"
widget="monetary"/>
widget="monetary"
options="{'currency_field': 'x_fc_currency_id'}"/>
<field name="x_fc_consumables_cost" readonly="1"
widget="monetary"/>
widget="monetary"
options="{'currency_field': 'x_fc_currency_id'}"/>
<field name="x_fc_actual_cost" readonly="1"
widget="monetary"/>
widget="monetary"
options="{'currency_field': 'x_fc_currency_id'}"/>
</group>
<group>
<field name="x_fc_margin_actual" readonly="1"
widget="monetary"
options="{'currency_field': 'x_fc_currency_id'}"
decoration-success="x_fc_margin_actual &gt; 0"
decoration-danger="x_fc_margin_actual &lt; 0"/>
<field name="x_fc_margin_pct" readonly="1"

View File

@@ -6,3 +6,36 @@
from . import controllers
from . import models
from . import wizard
def _backfill_currency(env):
"""Fill missing currency_id on existing money-holding records.
Older demo data and manually-created rows were persisted before the
`required=True` was added, so some records sit with currency_id=NULL
and Monetary fields render without a $ symbol. This runs on module
install/upgrade and pins them to the company's currency.
"""
company_currency = env.company.currency_id.id
if not company_currency:
return
for model_name in (
'fp.pricing.rule',
'fp.treatment',
'fp.customer.price.list',
'fp.quote.configurator',
):
Model = env.get(model_name)
if Model is None:
continue
Model.search([('currency_id', '=', False)]).write(
{'currency_id': company_currency}
)
def post_init_hook(env):
_backfill_currency(env)
def post_upgrade_hook(env):
_backfill_currency(env)

View File

@@ -67,4 +67,6 @@ Provides:
'installable': True,
'application': False,
'auto_install': False,
'post_init_hook': 'post_init_hook',
'post_load': None,
}

View File

@@ -44,7 +44,7 @@ class FpCustomerPriceList(models.Model):
)
currency_id = fields.Many2one(
'res.currency', string='Currency',
default=lambda self: self.env.company.currency_id,
required=True, default=lambda self: self.env.company.currency_id,
)
effective_from = fields.Date(
string='Effective From', default=fields.Date.today, required=True, tracking=True,

View File

@@ -36,7 +36,7 @@ class FpPricingRule(models.Model):
string='Pricing Method', required=True, default='per_sqin',
)
currency_id = fields.Many2one('res.currency', string='Currency',
default=lambda self: self.env.company.currency_id)
required=True, default=lambda self: self.env.company.currency_id)
base_rate = fields.Monetary(string='Base Rate', currency_field='currency_id',
help='Price per unit (sq in, sq ft, piece, or flat).')
thickness_factor = fields.Float(string='Thickness Factor', default=1.0,

View File

@@ -269,7 +269,7 @@ class FpQuoteConfigurator(models.Model):
# ----- Pricing ----------------------------------------------------------
currency_id = fields.Many2one(
'res.currency', string='Currency',
default=lambda self: self.env.company.currency_id,
required=True, default=lambda self: self.env.company.currency_id,
)
shipping_fee = fields.Monetary(string='Shipping Fee', currency_field='currency_id')
delivery_fee = fields.Monetary(string='Delivery Fee', currency_field='currency_id')

View File

@@ -35,6 +35,7 @@ class FpTreatment(models.Model):
currency_id = fields.Many2one(
'res.currency',
string='Currency',
required=True,
default=lambda self: self.env.company.currency_id,
)
default_cost = fields.Monetary(

View File

@@ -19,8 +19,10 @@
<field name="certification_level"/>
<field name="pricing_method"/>
<field name="currency_id" column_invisible="1"/>
<field name="base_rate"/>
<field name="minimum_charge"/>
<field name="base_rate" widget="monetary"
options="{'currency_field': 'currency_id'}" sum="Total"/>
<field name="minimum_charge" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="active" widget="boolean_toggle"/>
</list>
</field>
@@ -54,15 +56,23 @@
<group string="Pricing">
<group>
<field name="pricing_method"/>
<field name="currency_id" invisible="1"/>
<field name="base_rate"/>
<field name="currency_id"/>
<field name="base_rate" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="thickness_factor"/>
</group>
<group>
<field name="masking_rate_per_zone"/>
<field name="setup_fee"/>
<field name="minimum_charge"/>
<field name="rush_surcharge_percent"/>
<field name="masking_rate_per_zone" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="setup_fee" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="minimum_charge" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<label for="rush_surcharge_percent"/>
<div class="o_row">
<field name="rush_surcharge_percent" nolabel="1" class="oe_inline"/>
<span class="ms-1">%</span>
</div>
</group>
</group>
<notebook>
@@ -70,7 +80,7 @@
<field name="complexity_surcharge_ids">
<list editable="bottom">
<field name="complexity"/>
<field name="surcharge_percent"/>
<field name="surcharge_percent" string="Surcharge %"/>
</list>
</field>
</page>

View File

@@ -198,19 +198,23 @@
<group>
<group string="Delivery &amp; Fees">
<field name="delivery_method"/>
<field name="shipping_fee"/>
<field name="delivery_fee"/>
<field name="currency_id" invisible="1"/>
<field name="shipping_fee" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="delivery_fee" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
</group>
</group>
<separator string="Pricing"/>
<group>
<group>
<field name="calculated_price" widget="monetary" readonly="1"
options="{'currency_field': 'currency_id'}"
class="fw-bold fs-4"/>
</group>
<group>
<field name="estimator_override_price" widget="monetary"/>
<field name="estimator_override_price" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
</group>
</group>
<group>
@@ -298,8 +302,11 @@
<field name="surface_area"/>
<field name="quantity"/>
<field name="currency_id" column_invisible="1"/>
<field name="calculated_price"/>
<field name="estimator_override_price" string="Final Price"/>
<field name="calculated_price" widget="monetary"
options="{'currency_field': 'currency_id'}" sum="Total"/>
<field name="estimator_override_price" string="Final Price"
widget="monetary"
options="{'currency_field': 'currency_id'}" sum="Total"/>
<field name="state" widget="badge"
decoration-success="state == 'confirmed'"
decoration-info="state == 'draft'"

View File

@@ -15,9 +15,10 @@
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="treatment_type"/>
<field name="default_duration_minutes"/>
<field name="default_duration_minutes" string="Duration (min)"/>
<field name="currency_id" column_invisible="1"/>
<field name="default_cost"/>
<field name="default_cost" widget="monetary"
options="{'currency_field': 'currency_id'}" sum="Total"/>
<field name="active" widget="boolean_toggle"/>
</list>
</field>
@@ -41,9 +42,14 @@
<field name="sequence"/>
</group>
<group>
<field name="default_duration_minutes"/>
<field name="currency_id" invisible="1"/>
<field name="default_cost"/>
<label for="default_duration_minutes"/>
<div class="o_row">
<field name="default_duration_minutes" nolabel="1" class="oe_inline"/>
<span class="ms-1">min</span>
</div>
<field name="currency_id"/>
<field name="default_cost" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
</group>
</group>
<group>

View File

@@ -102,6 +102,7 @@ class FpQuoteRequest(models.Model):
currency_id = fields.Many2one(
'res.currency',
string='Currency',
required=True,
default=lambda self: self.env.company.currency_id,
)
quoted_by_id = fields.Many2one(

View File

@@ -23,8 +23,9 @@
<field name="contact_name" optional="show"/>
<field name="quantity"/>
<field name="target_delivery"/>
<field name="quoted_price" widget="monetary" optional="show"/>
<field name="currency_id" invisible="1"/>
<field name="currency_id" column_invisible="1"/>
<field name="quoted_price" widget="monetary"
options="{'currency_field': 'currency_id'}" optional="show" sum="Total"/>
<field name="state" widget="badge"
decoration-info="state == 'new'"
decoration-warning="state == 'under_review'"
@@ -80,9 +81,10 @@
<field name="quantity"/>
<field name="target_delivery"/>
<field name="process_type_ids" widget="many2many_tags"/>
<field name="quoted_price" widget="monetary"
readonly="state in ('new','under_review')"/>
<field name="currency_id" groups="base.group_multi_currency"/>
<field name="quoted_price" widget="monetary"
options="{'currency_field': 'currency_id'}"
readonly="state in ('new','under_review')"/>
<field name="quoted_by_id" readonly="1"/>
<field name="quote_sent_date" readonly="1"/>
<field name="customer_response_date" readonly="1"/>