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):