diff --git a/CHANGELOG b/CHANGELOG index 84730c1db0..5a9952313b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ +* Check pending subscription to erase party + Version 4.6.0 - 2017-10-30 * Bug fixes (see mercurial logs for details) Version 4.4.0 - 2017-05-01 -* Initial release \ No newline at end of file +* Initial release diff --git a/__init__.py b/__init__.py index 8418cfd3cb..b3d71d313a 100644 --- a/__init__.py +++ b/__init__.py @@ -28,6 +28,7 @@ def register(): subscription.CreateLineConsumption, subscription.CreateSubscriptionInvoice, party.PartyReplace, + party.PartyErase, module='sale_subscription', type_='wizard') Pool.register( module='sale_subscription', type_='report') diff --git a/party.py b/party.py index 4de3a1ef40..c0a0fb661c 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: @@ -14,3 +14,33 @@ class PartyReplace: return super(PartyReplace, cls).fields_to_replace() + [ ('sale.subscription', 'party'), ] + + +class PartyErase: + __metaclass__ = PoolMeta + __name__ = 'party.erase' + + @classmethod + def __setup__(cls): + super(PartyErase, cls).__setup__() + cls._error_messages.update({ + 'pending_subscription': ( + 'The party "%(party)s" can not be erased ' + 'because he has pending subscriptions ' + 'for the company "%(company)s".'), + }) + + def check_erase_company(self, party, company): + pool = Pool() + Subscription = pool.get('sale.subscription') + super(PartyErase, self).check_erase_company(party, company) + + subscriptions = Subscription.search([ + ('party', '=', party.id), + ('state', 'not in', ['closed', 'canceled']), + ]) + if subscriptions: + self.raise_user_error('pending_subscription', { + 'party': party.rec_name, + 'company': company.rec_name, + })