Commit e711280
[FIX] stock_currency_valuation: resolve the valuation currency per record company
Contract of the seam ``account-multicompany-ux`` <-> ``stock-currency-valuation``:
the valuation currency lives on the product CATEGORY and is company-dependent, so
reading it off the ambient company answers for the wrong one as soon as the record
belongs to another — routine with multi-company UX, where a user can have company A
selected and operate on a record of company B.
``stock.quant._compute_secondary_value`` read the guard off the ambient company and
the price with ``with_company(quant.company_id)``. When the active company has no
valuation currency and the quant's does, the guard answers "none" —true for the
active one— and the quant is skipped: its secondary value is not wrong, it is
missing. The product is now resolved once with the quant's company and reused for
both. ``stock.move._set_value`` had the same read on its conversion branch.
The three violations this was expected to fix in ``product.product`` do not exist,
and were checked one by one before touching anything: that model has no company of
its own, so for its company-dependent fields the CONTEXT company is the semantic
one. ``_get_last_product_value`` filters by ``self.env.company`` exactly as the core
does, and ``write`` / ``_change_standard_price`` read in the very company they are
writing to. ``stock.picking`` and ``stock.landed.cost`` already comply.
Left out on purpose: ``valuation_currency_id`` is a ``related`` on ``stock.move``,
``stock.quant`` and the AVCO report, and a ``related`` always resolves in the ambient
company with no way to apply ``with_company``, so two companies valuing the same
category in different currencies can see a right amount under the wrong symbol. The
fix is a compute with the record's company, which has consequences for views and
searches.
Verified in both directions: with the fix the suite is green, and without it the
test fails 0.0 != 3500.0. The test uses a category whose valuation currency exists
ONLY in company B and re-browses the quant from an env with company A — reading it
on the ``with_company(company_b)`` recordset that created it proves nothing, since a
company-dependent field resolves off the RECORDSET's context.
Part-of: #1004
Related: ingadhoc/account-financial-tools#984
Related: ingadhoc/product#937
Related: ingadhoc/miscellaneous#436
Signed-off-by: Camila Vives <cav@adhoc.inc>1 parent f67a368 commit e711280
4 files changed
Lines changed: 128 additions & 5 deletions
File tree
- stock_currency_valuation
- models
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
106 | 111 | | |
107 | | - | |
| 112 | + | |
108 | 113 | | |
109 | 114 | | |
110 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
36 | | - | |
37 | | - | |
| 44 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
Lines changed: 110 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
0 commit comments