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

[FIX] account_invoice_margin: avoid traceback in invoice #221

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

edy1192
Copy link
Contributor

@edy1192 edy1192 commented Nov 6, 2024

When creating an invoice, associating a product (the uom is associated), deleting the product from the line and saving, an error is obtained:

File
"/home/odoo/src/user/margin-analysis/account_invoice_margin/models/account_invoice.py", line 108, in _compute_purchase_price
    purchase_price = line.product_id.uom_id._compute_price(
  File "/home/odoo/src/odoo/addons/uom/models/uom_uom.py", line 247, in
_compute_price
    self.ensure_one()
  File "/home/odoo/src/odoo/odoo/models.py", line 5243, in ensure_one
    raise ValueError("Expected singleton: %s" % self)

This is because it attempts to use the product's uom to calculate the purchase price, and the product is empty.

The product is validated before performing the calculation, to avoid the error.

Functional test before the fix

https://youtu.be/ZbEGpCJR-xI

Functional test after the fix

https://youtu.be/W2pW2myxQU8

When creating an invoice, associating a product
(the uom is associated), deleting the product from the
line and saving, an error is obtained:

  File
"/home/odoo/src/user/margin-analysis/account_invoice_margin/models/account_invoice.py",
line 108, in _compute_purchase_price
    purchase_price = line.product_id.uom_id._compute_price(
  File "/home/odoo/src/odoo/addons/uom/models/uom_uom.py", line 247, in
_compute_price
    self.ensure_one()
  File "/home/odoo/src/odoo/odoo/models.py", line 5243, in ensure_one
    raise ValueError("Expected singleton: %s" % self)

This is because it attempts to take the uom of the
product to calculate the purchase price and the
product is empty.

The product is validated before performing the
calculation, to avoid the error.
@OCA-git-bot
Copy link
Contributor

Hi @sergio-teruel,
some modules you are maintaining are being modified, check this out!

@edy1192
Copy link
Contributor Author

edy1192 commented Nov 6, 2024

Hi @moylop260 could you check this, please?

Copy link
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

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

Thanks !

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 15.0-ocabot-merge-pr-221-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 5a07c53 into OCA:15.0 Nov 6, 2024
7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 76042f8. Thanks a lot for contributing to OCA. ❤️

@luisg123v luisg123v deleted the 15.0-fix-compute-edy1192 branch November 6, 2024 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants