From 76314f0a3bdb4deb05444443826106607fe35c5d Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 2 Nov 2016 13:55:55 +0100 Subject: [PATCH] [FIX] hr_expense: unlink posted expense Steps to reproduce: - Create one (or several) expense lines - Submit them to the manager (create the expense sheet) - Approve the sheet and post the entries - Delete the created and posted sheet Bug: - The expense is deleted but the accounting entries are still in the database - The expense lines are in "To submit" and you can submit to manager again and generate a new report and therefore new accounting entries... Fix: It is not allowed to delete posted expense. opw:692323 --- addons/hr_expense/i18n/hr_expense.pot | 6 ++++++ addons/hr_expense/models/hr_expense.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/addons/hr_expense/i18n/hr_expense.pot b/addons/hr_expense/i18n/hr_expense.pot index 5c754fc8f18..bec51b5b550 100644 --- a/addons/hr_expense/i18n/hr_expense.pot +++ b/addons/hr_expense/i18n/hr_expense.pot @@ -1249,6 +1249,12 @@ msgid "You can setup a generic email alias to create\n" " in the mail subject to set it on the expense too." msgstr "" +#. module: hr_expense +#: code:addons/hr_expense/models/hr_expense.py:421 +#, python-format +msgid "You cannot delete a posted expense." +msgstr "" + #. module: hr_expense #: code:addons/hr_expense/models/hr_expense.py:105 #, python-format diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 14df45c7e3f..cc573dc4e95 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -417,6 +417,13 @@ class HrExpenseSheet(models.Model): self._add_followers() return res + @api.multi + def unlink(self): + for expense in self: + if expense.state == "post": + raise UserError(_("You cannot delete a posted expense.")) + super(HrExpenseSheet, self).unlink() + @api.multi def set_to_paid(self): self.write({'state': 'done'})