diff --git a/CHANGELOG b/CHANGELOG index e61bee9272..7fe91ee829 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Check pending purchase to erase party * Add wizard to modify purchase header after filling lines * Make description on purchase line optional * Add product supplier on purchase line diff --git a/__init__.py b/__init__.py index 888c18d7c1..4e327116a9 100644 --- a/__init__.py +++ b/__init__.py @@ -7,7 +7,7 @@ from .product import * from .stock import * from .configuration import * from .invoice import * -from .party import PartyReplace +from . import party def register(): @@ -42,6 +42,7 @@ def register(): OpenSupplier, HandleShipmentException, HandleInvoiceException, - PartyReplace, + party.PartyReplace, + party.PartyErase, ModifyHeader, module='purchase', type_='wizard') diff --git a/party.py b/party.py index 1f2402b0e9..8b91ea1c32 100644 --- a/party.py +++ b/party.py @@ -1,8 +1,8 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond.pool import PoolMeta +from trytond.pool import PoolMeta, Pool -__all__ = ['PartyReplace'] +__all__ = ['PartyReplace', 'PartyErase'] class PartyReplace: @@ -15,3 +15,33 @@ class PartyReplace: ('purchase.product_supplier', 'party'), ('purchase.purchase', 'party'), ] + + +class PartyErase: + __metaclass__ = PoolMeta + __name__ = 'party.erase' + + @classmethod + def __setup__(cls): + super(PartyErase, cls).__setup__() + cls._error_messages.update({ + 'pending_purchase': ( + 'The party "%(party)s" can not be erased ' + 'because he has pending purchases ' + 'for the company "%(company)s".'), + }) + + def check_erase_company(self, party, company): + pool = Pool() + Purchase = pool.get('purchase.purchase') + super(PartyErase, self).check_erase_company(party, company) + + purchases = Purchase.search([ + ('party', '=', party.id), + ('state', 'not in', ['done', 'cancel']), + ]) + if purchases: + self.raise_user_error('pending_purchase', { + 'party': party.rec_name, + 'company': company.rec_name, + })