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, + })