From 3a982de28ea22e363284a179afba6b92e507def7 Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Thu, 2 Feb 2023 13:37:52 +0000 Subject: [PATCH] [FIX] hr_expense: compute total amount if there is a unit price MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: Create an expense by sending an email. Make sure the product has a zero cost. Issue: The expense has no total amount even if a unit price is detected in the subject of the mail. Solution: Compute a total amount if we have a unit price. opw-3128566 closes odoo/odoo#115620 X-original-commit: eb629fa82cbf592184ed60d0bf309a26a4465b70 Signed-off-by: William André (wan) --- addons/hr_expense/models/hr_expense.py | 2 +- .../tests/test_expenses_mail_import.py | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index f104e70bac0..7d5f44e208d 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -166,7 +166,7 @@ class HrExpense(models.Model): @api.depends('quantity', 'unit_amount', 'tax_ids', 'currency_id') def _compute_amount(self): for expense in self: - if expense.product_id and not expense.product_has_cost: + if expense.product_id and not expense.unit_amount: continue taxes = expense._get_taxes(price=expense.unit_amount, quantity=expense.quantity) expense.total_amount = taxes['total_included'] diff --git a/addons/hr_expense/tests/test_expenses_mail_import.py b/addons/hr_expense/tests/test_expenses_mail_import.py index 39bf9eb629a..e8acd640532 100644 --- a/addons/hr_expense/tests/test_expenses_mail_import.py +++ b/addons/hr_expense/tests/test_expenses_mail_import.py @@ -49,6 +49,32 @@ class TestExpensesMailImport(TestExpenseCommon): 'employee_id': self.expense_employee.id, }]) + def test_import_expense_from_email_product_no_cost(self): + """ + We have to compute a value for the total amount + even if the product has no cost. + """ + product_no_cost = self.env['product.product'].create({ + 'name': 'Product No Cost', + 'standard_price': 0.0, + 'can_be_expensed': True, + 'default_code': 'product_no_cost', + }) + message_parsed = { + 'message_id': "test", + 'subject': 'product_no_cost my description 100', + 'email_from': self.expense_user_employee.email, + 'to': 'catchall@yourcompany.com', + 'body': "test", + 'attachments': [], + } + expense = self.env['hr.expense'].message_new(message_parsed) + self.assertRecordValues(expense, [{ + 'product_id': product_no_cost.id, + 'total_amount': 100.0, + 'employee_id': self.expense_employee.id, + }]) + def test_import_expense_from_mail_parsing_subjects(self): def assertParsedValues(subject, currencies, exp_description, exp_amount, exp_product):