Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

account_move_line_purchase_info breaks automatic revaluation in Odoo >= V16 #2017

Open
JordiMForgeFlow opened this issue Jan 21, 2025 · 1 comment
Labels

Comments

@JordiMForgeFlow
Copy link
Contributor

Problem

Since Odoo V16, automatic revaluation is handled whenever the vendor bill price and the purchase price is different for a product with FIFO costing method. This is done when the invoice is posted: https://github.com/odoo/odoo/blob/05ce1a521d9702ce490100354d2b19007c35bb62/addons/purchase_stock/models/account_invoice.py#L159

The method _generate_price_difference_vals (https://github.com/odoo/odoo/blob/05ce1a521d9702ce490100354d2b19007c35bb62/addons/purchase_stock/models/account_move_line.py#L157) is used to prepare the values for the new layer adjusting the stock value, and Odoo will afterwards automatically reconcile the difference with the other stock interim account journal items.

The problem comes when Odoo loops through the invoice lines related to the purchase order line of the layer: https://github.com/odoo/odoo/blob/05ce1a521d9702ce490100354d2b19007c35bb62/addons/purchase_stock/models/account_move_line.py#L171. Due to the module account_move_line_purchase_info, the stock journal items created when products from a purchase order are received are being related to the purchase order line. As a result, the invoice lines related to a purchase order line are also including the stock journal items.

Without going into much detail, the logic that Odoo is doing only works when the invoice lines related to the purchase order line are not including the stock journal items. Otherwise, the revaluation does not happen and the feature is lost.

You can test in a V16 odoo standard with a FIFO Automated product. The expected result would be like the following:

Image

1- Warehouse receipt
2- Vendor Bill
3- Automatically generated entry for the difference

Solution

Two solutions come to mind:

  1. Use a new field in account_move_line_purchase_info to relate all journal items for a purchase.
  2. Propose a hook to Odoo in order to filter out the stock journal items in the affected method.

Looking forward to your feedback

CC @OCA/accounting-maintainers @ForgeFlow

@AaronHForgeFlow
Copy link
Contributor

I think it is best to add a new field in the account_move_line_purchase_info to relate all journal items for a purchase.

At first it may be a pain (there are a couple of modules that depends on this one) but in the long term this is the less time consuming solution. Maintaining a hook module would be more time consuming and I don't think Odoo is willing to merge such hooks in v16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants