From 7f6fcc56257096aa226281ddccb2b84facc812ae Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Thu, 12 Sep 2013 16:39:17 +0200 Subject: [PATCH] [FIX] account_credit_control: Test if invoice have credit control line in non draft state before deleting it --- account_credit_control/__init__.py | 1 + account_credit_control/i18n/de.po | 8 +++++ account_credit_control/i18n/en.po | 8 +++++ account_credit_control/i18n/es.po | 6 ++++ account_credit_control/i18n/fr.po | 7 ++++ account_credit_control/invoice.py | 55 ++++++++++++++++++++++++++++++ 6 files changed, 85 insertions(+) create mode 100644 account_credit_control/invoice.py diff --git a/account_credit_control/__init__.py b/account_credit_control/__init__.py index 15a388665..27a4fabc2 100644 --- a/account_credit_control/__init__.py +++ b/account_credit_control/__init__.py @@ -27,3 +27,4 @@ from . import policy from . import company from . import wizard from . import report +from . import invoice diff --git a/account_credit_control/i18n/de.po b/account_credit_control/i18n/de.po index 6bde84721..761cfb60a 100644 --- a/account_credit_control/i18n/de.po +++ b/account_credit_control/i18n/de.po @@ -363,6 +363,14 @@ msgstr "" msgid "Lines marker" msgstr "Lines marker" + +#. module: account_credit_control +#: code:addons/account_credit_control/invoice.py:35 +#, python-format +msgid "You cannot cancel this invoice ! A payment reminder has already been sent to the customer.You must create a credit note and raise a new invoice." +msgstr "You cannot cancel this invoice ! A payment reminder has already been sent to the customer.You must create a credit note and raise a new invoice." + + #. module: account_credit_control #: field:credit.control.printer,state:0 msgid "state" diff --git a/account_credit_control/i18n/en.po b/account_credit_control/i18n/en.po index bd1d5081a..a485dd7c4 100644 --- a/account_credit_control/i18n/en.po +++ b/account_credit_control/i18n/en.po @@ -363,6 +363,14 @@ msgstr "" msgid "Lines marker" msgstr "Lines marker" + +#. module: account_credit_control +#: code:addons/account_credit_control/invoice.py:35 +#, python-format +msgid "You cannot cancel this invoice ! A payment reminder has already been sent to the customer.You must create a credit note and raise a new invoice." +msgstr "You cannot cancel this invoice ! A payment reminder has already been sent to the customer.You must create a credit note and raise a new invoice." + + #. module: account_credit_control #: field:credit.control.printer,state:0 msgid "state" diff --git a/account_credit_control/i18n/es.po b/account_credit_control/i18n/es.po index bd1d5081a..8c6ef96d9 100644 --- a/account_credit_control/i18n/es.po +++ b/account_credit_control/i18n/es.po @@ -368,6 +368,12 @@ msgstr "Lines marker" msgid "state" msgstr "state" +#. module: account_credit_control +#: code:addons/account_credit_control/invoice.py:35 +#, python-format +msgid "You cannot cancel this invoice ! A payment reminder has already been sent to the customer.You must create a credit note and raise a new invoice." +msgstr "You cannot cancel this invoice ! A payment reminder has already been sent to the customer.You must create a credit note and raise a new invoice." + #. module: account_credit_control #: field:credit.control.run,report:0 msgid "Report" diff --git a/account_credit_control/i18n/fr.po b/account_credit_control/i18n/fr.po index 247635b35..85867283b 100644 --- a/account_credit_control/i18n/fr.po +++ b/account_credit_control/i18n/fr.po @@ -345,6 +345,13 @@ msgstr "" msgid "Lines marker" msgstr "Traiter les lignes" +#. module: account_credit_control +#: code:addons/account_credit_control/invoice.py:35 +#, python-format +msgid "You cannot cancel this invoice ! A payment reminder has already been sent to the customer.You must create a credit note and raise a new invoice." +msgstr "Vous ne pouvez pas annuler cette facture ! Une lettre de relance a été envoyé au client. Vous devez créer un avoir et établir une nouvelle facture." + + #. module: account_credit_control #: field:credit.control.printer,state:0 msgid "state" diff --git a/account_credit_control/invoice.py b/account_credit_control/invoice.py new file mode 100644 index 000000000..4e1114fdd --- /dev/null +++ b/account_credit_control/invoice.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Vincent Renaville +# Copyright 2013 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp.osv import orm, fields +from openerp.tools.translate import _ + + +class AccountInvoice(orm.Model): + """Check on cancelling of an invoice""" + _inherit = 'account.invoice' + + def action_cancel(self, cr, uid, ids, context=None): + # We will search if this invoice is linked with credit + credit_control_line_obj = self.pool.get('credit.control.line') + for invoice_id in ids: + credit_control_line_ids_nondraft = credit_control_line_obj.search(cr, + uid, + [('invoice_id', '=', invoice_id), + ('state', '<>', 'draft')],context=context) + if credit_control_line_ids_nondraft: + raise orm.except_orm(_('Error!'), + _('You cannot cancel this invoice ! ' + 'A payment reminder has already been ' + 'sent to the customer.' + 'You must create a credit note and raise a new invoice.')) + credit_control_line_ids_draft = credit_control_line_obj.search(cr, + uid, + [('invoice_id', '=', invoice_id), + ('state', '=', 'draft')],context=context) + if credit_control_line_ids_draft: + credit_control_line_obj.unlink(cr, + uid, + credit_control_line_ids_draft, + context=context) + return super(AccountInvoice, self).action_cancel(cr, + uid, + ids, + context=context)