Skip to content

[16.0][FIX] maintenance_request_purchase: fall back to active company in _compute_total_purchase_amount#2

Open
eantones wants to merge 7 commits into
16.0from
16.0-fix-maintenance_request_purchase-company-fallback
Open

[16.0][FIX] maintenance_request_purchase: fall back to active company in _compute_total_purchase_amount#2
eantones wants to merge 7 commits into
16.0from
16.0-fix-maintenance_request_purchase-company-fallback

Conversation

@eantones

@eantones eantones commented Jul 8, 2026

Copy link
Copy Markdown
Member

Problem

maintenance.request.company_id is optional — the module's own _compute_currency_id acknowledges this and falls back to self.env.company when the request has no company.

_compute_total_purchase_amount, however, passes record.company_id straight into currency._convert(...):

po.currency_id._convert(po.amount_total, company_currency, record.company_id, date)

res.currency._convert asserts the company is set:

assert company, "convert amount from unknown company"

So on any database that holds company-less maintenance requests with a confirmed purchase order, the compute raises AssertionError: convert amount from unknown company.

Because total_purchase_amount is store=True, this fires on the stored-field recompute — e.g. during a module update / -u all (the field's column is populated for every record at once), which aborts the registry load. It would otherwise surface on-access in the UI for such a record.

Fix

Fall back to the active company, mirroring the existing _compute_currency_id pattern, so _convert always receives a valid company:

company = record.company_id or self.env.company

Behaviour is unchanged for requests that already have a company.

Context

Found during the Oxigen Salud 14→18 migration: the source database has 10,601 of 35,466 maintenance requests with no company, which aborted the 15→16 hop when this stored field was recomputed.

eantones added 7 commits July 8, 2026 22:54
…ompute_total_purchase_amount

maintenance.request.company_id is optional (the module's own
_compute_currency_id already falls back to self.env.company for the
currency). _compute_total_purchase_amount passed record.company_id
straight into currency._convert(), which asserts the company is set.

On databases that hold company-less maintenance requests this crashes
the stored-field recompute (total_purchase_amount is store=True), for
example during a module update / -u all.

Fall back to self.env.company so _convert always receives a valid
company.
Version bump and readme/HISTORY.rst entry for the company fallback fix in
_compute_total_purchase_amount.
…l amount

maintenance.request.company_id is optional, but _compute_total_purchase_amount
passed it to res.currency._convert(), which asserts a company is set, so the
stored total_purchase_amount recompute crashed on company-less requests.

Convert each purchase order using its own company_id, which is always set and
is the correct rate context for that order's amount.
…not env

maintenance.request.company_id is optional, so _compute_total_purchase_amount
passed an empty company to res.currency._convert() (which asserts a company is
set), crashing the stored total_purchase_amount recompute on company-less
requests.

Derive the company deterministically from the request's own data -- its
equipment, then its team, then its creator (always set) -- so the stored total
and currency never depend on the acting user's company. Use the same source for
_compute_currency_id.
The module keeps no changelog; per OCA/NuoBiT convention a HISTORY.rst is not
created when the module doesn't already have one.
maintenance.request.company_id is optional, so _compute_total_purchase_amount
passed an empty company to res.currency._convert() (which asserts a company is
set), crashing the stored total_purchase_amount recompute on company-less
requests that have a confirmed purchase order.

Convert each purchase order using its own company_id -- always set on
purchase.order, deterministic (fixed on the order, independent of who triggers
the recompute), and the company actually involved in the amount being summed.
Credit the company-fallback fix. README.rst/index.html regeneration is left to
pre-commit/oca-gen-addon-readme.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant