[FIX] hr_expense: compute total amount if there is a unit price

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) <wan@odoo.com>
This commit is contained in:
Thomas Lefebvre (thle)
2023-03-16 22:53:59 +01:00
parent 09383bd8b3
commit 3a982de28e
2 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -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']
@@ -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):