[18.0][IMP] purchase_stock_price_unit_sync: Sync the price corrected on the vendor bill - #3139
Open
carlosdauden wants to merge 1 commit into
Open
Conversation
… vendor bill This module already pushes a price corrected on the purchase order down to the moves that are already done and to their valuation layers. The vendor bill, which is the other place where the real price of a purchase shows up, was left to Odoo, and Odoo only corrects half of it. Odoo books a price difference as a child valuation layer worth the difference times the quantity that has not left stock yet, and sends the rest to the expense account. The stock ends up valued right, but the moves that already left keep the cost that turned out to be wrong, so the margin of what was sold, and any stock valuation asked for a date before the bill, stay wrong too. Correcting the same price on the purchase order did fix all of it, so the two ways of doing the very same thing gave different results. The invoiced price is now applied to the whole layer, which leaves the bill on the same footing as the purchase order. The hook is `_prepare_pdiff_vals`, where Odoo has already worked out, with its own matching of layers and bills, which layer each invoice line pays for and at what price, so none of that logic is duplicated here. It needs `product_cost_price_avco_sync` installed, checked at runtime rather than declared as a dependency: it is that module which replays the valuation chain once the layer changes, and restating a layer without it would leave the layer inconsistent while also throwing away the correction Odoo does make, which is worse than not doing anything. Refunds are left to Odoo, which compensates them against the original bill with a logic of its own, and so is automated valuation, where the journal entry of the layer is already posted and restating it would pull the two apart.
CarlosRoca13
approved these changes
Jul 31, 2026
| """Whether the price difference of this invoice line has to be applied | ||
| by restating the layer instead of by correcting only what is left of it. | ||
|
|
||
| It needs `product_cost_price_avco_sync`, which is what replays the chain |
Contributor
There was a problem hiding this comment.
Based on your docstring, should this module have an explicit dependency on product_cost_price_avco_sync in order to work correctly?
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.
This module already pushes a price corrected on the purchase order down to the moves that are already done and to their valuation layers. The vendor bill, which is the other place where the real price of a purchase shows up, was left to Odoo, and Odoo only corrects half of it.
Odoo books a price difference as a child valuation layer worth the difference times the quantity that has not left stock yet, and sends the rest to the expense account. The stock ends up valued right, but the moves that already left keep the cost that turned out to be wrong, so the margin of what was sold, and any stock valuation asked for a date before the bill, stay wrong too. Correcting the same price on the purchase order did fix all of it, so the two ways of doing the very same thing gave different results.
The invoiced price is now applied to the whole layer, which leaves the bill on the same footing as the purchase order. The hook is
_prepare_pdiff_vals, where Odoo has already worked out, with its own matching of layers and bills, which layer each invoice line pays for and at what price, so none of that logic is duplicated here.It needs
product_cost_price_avco_syncinstalled, checked at runtime rather than declared as a dependency: it is that module which replays the valuation chain once the layer changes, and restating a layer without it would leave the layer inconsistent while also throwing away the correction Odoo does make, which is worse than not doing anything. Refunds are left to Odoo, which compensates them against the original bill with a logic of its own, and so is automated valuation, where the journal entry of the layer is already posted and restating it would pull the two apart.@Tecnativa TT63558
ping @sergio-teruel @carlos-lopez-tecnativa @CarlosRoca13