Skip to content

Commit

Permalink
[FIX] hr_expense: add extra case for unit_amount compute with attachment
Browse files Browse the repository at this point in the history
Reproduction:
1. Install Expense, make sure in the product list of test data, we have
Expenses(without cost e.g. 0.00) and Daily Allowance(with cost e.g. 100)
2. Create a new expense with the product Daily Allowance, and attach a
file to the attachment, save expense
3. Edit the created expense, change the product to Expenses and save
4. The UI is not changed and can’t edit the total amount of the expense

Reason: the recomputation of product_has_cost is based on the
unit_amount. However, when there’s an attachment, the recomputation of
unit_amount doesn’t consider the case when the product is changed to one
without standard_price (unit_amount).

Fix: add a condition to make sure when the product is changed from one
with standard_price to one without standard_price, the unit_amount of
expense is recomputed correctly

opw-3051726

Related commit: odoo-dev@918a5f2

closes odoo#106660

Signed-off-by: Kevin Baptiste <kba@odoo.com>
  • Loading branch information
Jinjiu96 committed Nov 29, 2022
1 parent 3c21558 commit 2250b3d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion addons/hr_expense/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def _compute_from_product_id_company_id(self):
for expense in self.filtered('product_id'):
expense = expense.with_company(expense.company_id)
expense.name = expense.name or expense.product_id.display_name
if not expense.attachment_number or (expense.attachment_number and not expense.unit_amount):
if not expense.attachment_number or (expense.attachment_number and not expense.unit_amount) or (expense.attachment_number and expense.unit_amount and not expense.product_id.standard_price):
expense.unit_amount = expense.product_id.price_compute('standard_price')[expense.product_id.id]
expense.product_uom_id = expense.product_id.uom_id
expense.tax_ids = expense.product_id.supplier_taxes_id.filtered(lambda tax: tax.price_include and tax.company_id == expense.company_id) # taxes only from the same company
Expand Down

0 comments on commit 2250b3d

Please sign in to comment.