from odoo import api, fields, models, _ from odoo.tools import float_round class HrExpense(models.Model): _inherit = 'hr.expense' @api.depends('product_id', 'company_id', 'payment_mode') def _compute_account_id(self): super()._compute_account_id() for expense in self: if not expense.product_id: continue # Use specific accounts based on payment mode if configured product = expense.product_id.with_company(expense.company_id) if expense.payment_mode == 'own_account': if product.property_account_expense_employee_id: expense.account_id = product.property_account_expense_employee_id elif expense.payment_mode == 'company_account': if product.property_account_expense_company_id: expense.account_id = product.property_account_expense_company_id receipt_due_date = fields.Date( string="Receipt Due Date", readonly=True, help="Date the employee must submit the receipt." ) receipt_received = fields.Boolean( string="Receipt Received", default=False, tracking=True, help="Mark if original receipt has been received." ) receipt_overdue = fields.Boolean( string="Receipt Overdue", compute='_compute_receipt_overdue', store=True, help="True if receipt is not received and past due date." ) @api.depends('receipt_due_date', 'receipt_received') def _compute_receipt_overdue(self): today = fields.Date.today() for expense in self: if expense.receipt_due_date and not expense.receipt_received and expense.receipt_due_date < today: expense.receipt_overdue = True else: expense.receipt_overdue = False def _prepare_move_lines_vals(self): res = super()._prepare_move_lines_vals() if res.get('price_unit'): # Round the price to the currency's decimal places to avoid floating point artifacts (e.g. ...0001) # We use precision_digits=2 which is the standard for IDR/USD etc. res['price_unit'] = float_round(res['price_unit'], precision_digits=self.currency_id.decimal_places or 2) return res