Skip to content

Conversation

@fw-bot
Copy link
Contributor

@fw-bot fw-bot commented Dec 27, 2024

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 32543ce The landed_cost account lines related to a given stock move are also considered in the _get_price_unit call of stock moves:

for invoice_line in line._get_po_line_invoice_lines_su():

def _get_po_line_invoice_lines_su(self):
po_line_invoices_lines = super()._get_po_line_invoice_lines_su()
move = self.sudo().invoice_lines.move_id
if move.landed_costs_ids.filtered(lambda lc: lc.state == 'done'):
return po_line_invoices_lines | move.line_ids.filtered('is_landed_costs_line')
return po_line_invoices_lines

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:
invoiced_qty += invoice_line.product_uom_id._compute_quantity(invoice_line.quantity, line.product_id.uom_id)

if self != to_unit and self.category_id.id != to_unit.category_id.id:
if raise_if_failure:
raise UserError(_('The unit of measure %s defined on the order line doesn\'t belong to the same category as the unit of measure %s defined on the product. Please correct the unit of measure defined on the order line or on the product, they should belong to the same category.') % (self.name, to_unit.name))
else:
return qty

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:

remaining_value = total_invoiced_value - receipt_value

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:

remaining_value = total_invoiced_value - receipt_value

if the landed cost has it's own invoice line.

Revert Commit 32543ce
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: #191943
Forward-Port-Of: #191225

… 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 32543ce
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 that 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 32543ce
Authored-by: Whenrow <whe@odoo.com>

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

X-original-commit: af8a314
@robodoo
Copy link
Contributor

robodoo commented Dec 27, 2024

Pull request status dashboard

@fw-bot
Copy link
Contributor Author

fw-bot commented Dec 27, 2024

This PR targets saas-18.1 and is part of the forward-port chain. Further PRs will be created up to master.

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

@robodoo robodoo added the forwardport This PR was created by @fw-bot label Dec 27, 2024
@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Dec 27, 2024
@lase-odoo
Copy link
Contributor

robodoo r+

@fw-bot
Copy link
Contributor Author

fw-bot commented Dec 30, 2024

@lase-odoo @adwid child PR #191952 was modified / updated and has become a normal PR. This PR (and any of its parents) will need to be merged independently as approvals won't cross.

robodoo pushed a commit that referenced this pull request Dec 30, 2024
… 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 32543ce
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 that 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 32543ce
Authored-by: Whenrow <whe@odoo.com>

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

closes #191951

X-original-commit: af8a314
Signed-off-by: Adrien Widart (awt) <awt@odoo.com>
Signed-off-by: Lancelot Semal (lase) <lase@odoo.com>
@robodoo robodoo closed this Dec 30, 2024
@fw-bot fw-bot deleted the saas-18.1-16.0-opw-4389366-uom_landed_cost_issue-lase-uuv8-fw branch January 13, 2025 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

forwardport This PR was created by @fw-bot OE the report is linked to a support ticket (opw-...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants