diff --git a/CHANGELOG b/CHANGELOG index 93c4a93f54..eefa8b2a11 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Check pending drop shipment to erase party * Create drop shipment depending on the shipment method Version 4.6.0 - 2017-10-30 diff --git a/__init__.py b/__init__.py index a1f197c460..83574542c2 100644 --- a/__init__.py +++ b/__init__.py @@ -5,7 +5,7 @@ from trytond.pool import Pool from stock import * from sale import * from purchase import * -from .party import PartyReplace +from . import party def register(): @@ -28,5 +28,6 @@ def register(): Pool.register( CreatePurchase, PurchaseHandleShipmentException, - PartyReplace, + party.PartyReplace, + party.PartyErase, module='sale_supply_drop_shipment', type_='wizard') diff --git a/party.py b/party.py index 80fb9c3adc..50d669ecf5 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: @@ -17,3 +17,26 @@ class PartyReplace: ('stock.shipment.drop', 'supplier'), ('stock.shipment.drop', 'customer'), ] + + +class PartyErase: + __metaclass__ = PoolMeta + __name__ = 'party.erase' + + def check_erase_company(self, party, company): + pool = Pool() + ShipmentDrop = pool.get('stock.shipment.drop') + super(PartyErase, self).check_erase_company(party, company) + + shipments = ShipmentDrop.search([ + ['OR', + ('supplier', '=', party.id), + ('customer', '=', party.id), + ], + ('state', 'not in', ['done', 'cancel']), + ]) + if shipments: + self.raise_user_error('pending_shipment', { + 'party': party.rec_name, + 'company': company.rec_name, + })