Skip to content

[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
OCA:18.0from
Tecnativa:18.0-IMP-purchase_stock_price_unit_sync-bill-price-diff
Open

[18.0][IMP] purchase_stock_price_unit_sync: Sync the price corrected on the vendor bill#3139
carlosdauden wants to merge 1 commit into
OCA:18.0from
Tecnativa:18.0-IMP-purchase_stock_price_unit_sync-bill-price-diff

Conversation

@carlosdauden

Copy link
Copy Markdown
Contributor

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.

@Tecnativa TT63558

ping @sergio-teruel @carlos-lopez-tecnativa @CarlosRoca13

… 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.
@OCA-git-bot OCA-git-bot added series:18.0 mod:purchase_stock_price_unit_sync Module purchase_stock_price_unit_sync labels Jul 30, 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on your docstring, should this module have an explicit dependency on product_cost_price_avco_sync in order to work correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:purchase_stock_price_unit_sync Module purchase_stock_price_unit_sync series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants