From 25f92048e4f4904ea507eb2908669decde9bb6c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 24 Mar 2018 00:05:23 +0100 Subject: [PATCH] Check pending invoice to erase party issue7169 review38021002 --- CHANGELOG | 1 + __init__.py | 1 + party.py | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 6ed2c0b98a..be85262bf4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Check pending invoice to erase party * Add invoice usage to party's contact mechanisms * Show reconciled date on invoice * Make description on invoice line optional diff --git a/__init__.py b/__init__.py index 7d0fcc889a..a65bb71c95 100644 --- a/__init__.py +++ b/__init__.py @@ -40,6 +40,7 @@ def register(): PayInvoice, CreditInvoice, party.PartyReplace, + party.PartyErase, RenewFiscalYear, module='account_invoice', type_='wizard') Pool.register( diff --git a/party.py b/party.py index babff6af5e..d1cd29d056 100644 --- a/party.py +++ b/party.py @@ -5,7 +5,8 @@ from trytond.model import ModelView, ModelSQL, ValueMixin, fields from trytond.pool import Pool, PoolMeta from trytond.tools.multivalue import migrate_property -__all__ = ['Address', 'Party', 'PartyPaymentTerm', 'PartyReplace'] +__all__ = ['Address', 'Party', 'PartyPaymentTerm', + 'PartyReplace', 'PartyErase'] customer_payment_term = fields.Many2One( 'account.invoice.payment_term', "Customer Payment Term") supplier_payment_term = fields.Many2One( @@ -100,3 +101,33 @@ class PartyReplace: ('account.invoice', 'party'), ('account.invoice.line', 'party'), ] + + +class PartyErase: + __metaclass__ = PoolMeta + __name__ = 'party.erase' + + @classmethod + def __setup__(cls): + super(PartyErase, cls).__setup__() + cls._error_messages.update({ + 'pending_invoice': ( + 'The party "%(party)s" can not be erased ' + 'because he has pending invoices ' + 'for the company "%(company)s".'), + }) + + def check_erase_company(self, party, company): + pool = Pool() + Invoice = pool.get('account.invoice') + super(PartyErase, self).check_erase_company(party, company) + + invoices = Invoice.search([ + ('party', '=', party.id), + ('state', 'not in', ['paid', 'cancel']), + ]) + if invoices: + self.raise_user_error('pending_invoice', { + 'party': party.rec_name, + 'company': company.rec_name, + })