[FIX] hr_expense: fix the default product
- before this commit the product was set to EXP_GEN but nothing if EXP_GEN is not in db anymore - now it will pick the first "expensable" product if EXP_GEN doesn't exist. closes odoo/odoo#47678 X-original-commit: ee35c662768c6f27dff88e9c4597695c17b3b67b Signed-off-by: Florian Daloze (fda) <fda@odoo.com> Signed-off-by: Thomas Carlier <Explicitapps@users.noreply.github.com>
This commit is contained in:
@@ -180,8 +180,12 @@ class HrExpense(models.Model):
|
||||
|
||||
if any(attachment.res_id or attachment.res_model != 'hr.expense' for attachment in attachments):
|
||||
raise UserError(_("Invalid attachments!"))
|
||||
|
||||
product = self.env['product.product'].search([('default_code', '=', 'EXP_GEN')])
|
||||
|
||||
product = self.env['product.product'].search([('can_be_expensed', '=', True)])
|
||||
if product:
|
||||
product = product.filtered(lambda p: p.default_code == "EXP_GEN") or product[0]
|
||||
else:
|
||||
raise UserError(_("You need to have at least one product that can be expensed in your database to proceed!"))
|
||||
|
||||
for attachment in attachments:
|
||||
expense = self.env['hr.expense'].create({
|
||||
|
||||
Reference in New Issue
Block a user