From 98a6ee13374e7f4708a53acf62557460529eb0af Mon Sep 17 00:00:00 2001 From: Hansa Rathod Date: Mon, 9 Jul 2018 11:18:45 +0530 Subject: [PATCH] [IMP]: Added Upstream patch for HR Expense --- addons/hr_expense/models/hr_expense.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index f694cde8..eeba0dbd 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -370,7 +370,9 @@ class HrExpense(models.Model): product = default_product else: expense_description = expense_description.replace(product_code.group(), '') - product = self.env['product.product'].search([('default_code', 'ilike', product_code.group(1))]) or default_product + products = self.env['product.product'].search([('default_code', 'ilike', product_code.group(1))]) or default_product + product = products.filtered(lambda p: p.default_code == product_code.group(1)) or products[0] + account = product.product_tmpl_id._get_product_accounts()['expense'] pattern = '[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?' # Match the last occurence of a float in the string @@ -397,6 +399,8 @@ class HrExpense(models.Model): 'unit_amount': price, 'company_id': employee.company_id.id, }) + if account: + custom_values['account_id'] = account.id return super(HrExpense, self).message_new(msg_dict, custom_values) class HrExpenseSheet(models.Model): @@ -512,7 +516,7 @@ class HrExpenseSheet(models.Model): @api.onchange('employee_id') def _onchange_employee_id(self): - self.address_id = self.employee_id.address_home_id + self.address_id = self.employee_id.sudo().address_home_id self.department_id = self.employee_id.department_id @api.one @@ -599,4 +603,4 @@ class HrExpenseSheet(models.Model): def _check_payment_mode(self): payment_mode = set(self.expense_line_ids.mapped('payment_mode')) if len(payment_mode) > 1: - raise ValidationError(_('You cannot report expenses with different payment modes.')) \ No newline at end of file + raise ValidationError(_('You cannot report expenses with different payment modes.'))