From 1c015283753df0bdc201b2e010a27be398960b03 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Thu, 1 Mar 2018 11:49:10 +0100 Subject: [PATCH] [FIX] hr_expense: ensure message_new has only one record (singleton) Before this commit: Expense emails title are parsed to find a product that match the given [CODE]. For example, an email title like '[CARD] Graphic Card $900' will create an expense for the product having 'CARD' as internal reference. Since the search is done with an 'ilike' and with no 'limit', it could return multiple product: all the one containing the CODE in their internal reference. This would throw a singleton error when trying afterward to read product.id. Then, the mail would not go through the mail.thread flow and it would return a Mail System Delivery fail saying the address does not exist. Users would get stuck with this, having no way to understand where the error comes from. Now, we ensure to find only 1 product. To avoid breaking the ilike behavior that could be used by users only typing the first caracters of a long CODE, we still use ilike but force exact match if there is multiple results. Closes #23419 opw-1816340 --- addons/hr_expense/models/hr_expense.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index e83b9ca66a8..53c64c4a5ac 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -348,7 +348,8 @@ class HrExpense(models.Model): product = default_product else: expense_description = expense_description.replace(product_code.group(), '') - product = self.env['product.product'].search([('default_code', 'ilike', product_code.group(1))]) or default_product + products = self.env['product.product'].search([('default_code', 'ilike', product_code.group(1))]) or default_product + product = products.filtered(lambda p: p.default_code == product_code.group(1)) or products[0] pattern = '[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?' # Match the last occurence of a float in the string