From f075b52a25c69f767a37760c9dfd739d00b267c6 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 21 Nov 2017 10:39:48 +0100 Subject: [PATCH] [FIX] hr_expense: multiple payment modes - Create an expense paid by employee - Create an expense paid by company - Select the two expenses and submit a report You are authorized to create this report but you cannot validate it and you cannot refuse it because of the mix of an expense paid by employee and paid by company. You're blocked. We should block the creation of an expense report mixing expenses paid by company and paid by employee opw-783395 --- addons/hr_expense/i18n/hr_expense.pot | 25 ++++++++++++++++++++++++- addons/hr_expense/models/hr_expense.py | 7 +++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/addons/hr_expense/i18n/hr_expense.pot b/addons/hr_expense/i18n/hr_expense.pot index b26c16e88da..c30ecaba78b 100644 --- a/addons/hr_expense/i18n/hr_expense.pot +++ b/addons/hr_expense/i18n/hr_expense.pot @@ -148,6 +148,11 @@ msgstr "" msgid "All Expenses" msgstr "" +#. module: hr_expense +#: model:ir.model.fields,help:hr_expense.field_hr_expense_account_id +msgid "An expense account is expected" +msgstr "" + #. module: hr_expense #: model:ir.model.fields,field_description:hr_expense.field_hr_expense_analytic_account_id #: model:ir.ui.view,arch_db:hr_expense.view_hr_expense_filter @@ -826,6 +831,18 @@ msgid "Once your email gateway is configured, come back to this screen\n" " to setup the next steps." msgstr "" +#. module: hr_expense +#: code:addons/hr_expense/models/hr_expense.py:537 +#, python-format +msgid "Only HR Officers can approve expenses" +msgstr "" + +#. module: hr_expense +#: code:addons/hr_expense/models/hr_expense.py:528 +#, python-format +msgid "Only HR Officers can refuse expenses" +msgstr "" + #. module: hr_expense #: selection:hr.expense.sheet,state:0 #: model:mail.message.subtype,name:hr_expense.mt_expense_paid @@ -1308,7 +1325,13 @@ msgid "You cannot report expenses for different employees in the same report!" msgstr "" #. module: hr_expense -#: code:addons/hr_expense/models/hr_expense.py:104 +#: code:addons/hr_expense/models/hr_expense.py:605 +#, python-format +msgid "You cannot report expenses with different payment modes." +msgstr "" + +#. module: hr_expense +#: code:addons/hr_expense/models/hr_expense.py:105 #, python-format msgid "You cannot report twice the same line!" msgstr "" diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 61a45a48154..4bbdb0b3dbc 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -596,3 +596,10 @@ class HrExpenseSheet(models.Model): employee_ids = self.expense_line_ids.mapped('employee_id') if len(employee_ids) > 1 or (len(employee_ids) == 1 and employee_ids != self.employee_id): raise ValidationError(_('You cannot add expense lines of another employee.')) + + @api.one + @api.constrains('expense_line_ids') + 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.'))