odoo/odoo#191942

Created by fw-bot
Merged at 619e0e164b33f60e6a38384404faedef9e6c3d9d

Statuses:

label
odoo-dev:saas-17.4-16.0-opw-4389366-uom_landed_cost_issue-lase-hxJE-fw
head
aef3f35230f317194bcba4d5370edb0a827b01b6
merged
1 year ago by Bugfix, Adrien Widart (awt)
odoo/odoo
16.0 #191225
17.0 #191892
saas-17.2 #191941
saas-17.4 #191942
18.0 #191943
saas-18.1 #191951
saas-18.2
saas-18.3
saas-18.4
19.0
master #191952

[FW][FIX] stock_landed_costs: avoid uom user error from valid landed cost lines

Issue 1

Trying to validate a receipt related to a landed cost account line for
a product using a uom from a different uom category will raise a
userError that do not allow you to validate the receipt.

Steps to reproduce:

  • Create a product:
    • real time property valuation
    • average cost method
    • on ordered quantities control policy
    • UOM from an other category han "Unit" e.g. kg
  • Create and confirm a PO for 100 k units at 1.35 each
  • Create an invoice for 23 k, receive 23k units and backorder
  • Create a landed cost on the invoice for 23k units in the company currency units
  • Post the invoice
  • Create a second invoice for 27k units and post it
  • Try to validate the receipt of the 27k units more units
    > UserError: The unit of measure Units defined on the order line doesn't belong to the same category as the unit of measure kg > defined on the product.

Cause of the issue:

Since Commit 32543ce9356f228d087d17a0ead1e0a80449e5de The landed_cost account lines related to a given stock move are also considered in the _get_price_unit call of stock moves:
https://github.com/odoo/odoo/blob/1b999e4b358eabe80cb3d636cd7bc348c5b85a1b/addons/purchase_stock/models/stock_move.py#L60
https://github.com/odoo/odoo/blob/1b999e4b358eabe80cb3d636cd7bc348c5b85a1b/addons/stock_landed_costs/models/purchase.py#L11-L16
However, the uom related to the landed cost account line might not match the uom category of the product related to the move. As such, this line will raise a UserError:
https://github.com/odoo/odoo/blob/da1f44c2296486c0267a7bdbbe3a314ada3aa679/addons/purchase_stock/models/stock_move.py#L70
https://github.com/odoo/odoo/blob/da1f44c2296486c0267a7bdbbe3a314ada3aa679/addons/uom/models/uom_uom.py#L223-L227

Issue 2

Steps to reproduce

  • Create a product invoiced on ordered quantities
  • Create a PO and a bill for it, post the bill
  • Receipt half the quantity
  • Add a landed cost product on the PO, create a second bill for this landed cost product. Create and validate the landed cost.
  • Receipt the second half quantity.

Issue:

The valuation of the second transfer is too low

Cause of the Issue 2:

To get the price unit for "on ordered qty" policy, We compute the ratio of already receipt value on already invoiced value:
https://github.com/odoo/odoo/blob/4f6353ec8a7306fbf63e95e8e02248d72f413aa3/addons/purchase_stock/models/stock_move.py#L84
The issue is the receipt value is increase by the landed costs value because the receipt valuation layer is linked to the landed cost valuation layer. But the product invoice line is not linked to the landed costs invoice line. Resulting in a invoice value under valuated.

This commit will ingnore the receipt values coming from landed costs so that the landed costs value will be added to the total invoiced value and not removed from the value here:
https://github.com/odoo/odoo/blob/cfb7a3593c5a4b313bdfd8628fe1b0dfe7e73823/addons/purchase_stock/models/stock_move.py#L72
if the landed cost has it's own invoice line.

Revert Commit 32543ce9356f228d087d17a0ead1e0a80449e5de
Authored-by: Whenrow <whe@odoo.com>

Issue 1: opw-4389366
Issue 2: opw-4354498


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

Forward-Port-Of: #191892
Forward-Port-Of: #191225