Check pending invoice to erase party

issue7169
review38021002
This commit is contained in:
Cédric Krier
2018-03-24 00:05:23 +01:00
parent 0030150c57
commit 25f92048e4
3 changed files with 34 additions and 1 deletions
+1
View File
@@ -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
+1
View File
@@ -40,6 +40,7 @@ def register():
PayInvoice,
CreditInvoice,
party.PartyReplace,
party.PartyErase,
RenewFiscalYear,
module='account_invoice', type_='wizard')
Pool.register(
+32 -1
View File
@@ -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,
})