[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
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
maintenance.request.company_idis optional — the module's own_compute_currency_idacknowledges this and falls back toself.env.companywhen the request has no company._compute_total_purchase_amount, however, passesrecord.company_idstraight intocurrency._convert(...):res.currency._convertasserts the company is set: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_amountisstore=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_idpattern, so_convertalways receives a valid 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.