[FIX] account: avoid computing uom price if no product
Before this commit: * Enable UOMs * Create a new invoice and invoice line * Set *only* the uom field of the invoice line * Singleton expected error This happens because the method _compute_price of `uom.uom` expects a singleton, however since no product has been defined yet, it gets an empty recordset which of course doesn't comply with self.ensure_one(), raising a Singleton Error. Functionally speaking, it makes sense to define a product before choosing an uom, however a Singleton Error is an unexpected error, so instead of doing that, we only calculate the price_unit if a product has been chosen. Fixes #28269 closes odoo/odoo#28278
This commit is contained in:
@@ -1756,14 +1756,14 @@ class AccountInvoiceLine(models.Model):
|
||||
result = {}
|
||||
if not self.uom_id:
|
||||
self.price_unit = 0.0
|
||||
else:
|
||||
|
||||
if self.product_id and self.uom_id:
|
||||
if self.invoice_id.type in ('in_invoice', 'in_refund'):
|
||||
price_unit = self.product_id.standard_price
|
||||
else:
|
||||
price_unit = self.product_id.lst_price
|
||||
self.price_unit = self.product_id.uom_id._compute_price(price_unit, self.uom_id)
|
||||
|
||||
if self.product_id and self.uom_id:
|
||||
if self.product_id.uom_id.category_id.id != self.uom_id.category_id.id:
|
||||
warning = {
|
||||
'title': _('Warning!'),
|
||||
|
||||
Reference in New Issue
Block a user