From 4584aed5e549b7145aa36a8e537b15615fb0f2d2 Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Tue, 30 Oct 2018 10:07:35 +0000 Subject: [PATCH] [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 --- addons/account/models/account_invoice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index e897f96abd7..ab46cde5838 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -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!'),