Files
tryton/party.py
T

42 lines
1.4 KiB
Python
Raw Normal View History

2016-10-02 15:21:28 +02:00
# 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.i18n import gettext
from trytond.modules.party.exceptions import EraseError
2021-12-11 17:58:44 +01:00
from trytond.pool import Pool, PoolMeta
2016-10-02 15:21:28 +02:00
2020-03-01 12:33:54 +01:00
class Replace(metaclass=PoolMeta):
2016-10-02 15:21:28 +02:00
__name__ = 'party.replace'
@classmethod
def fields_to_replace(cls):
2020-03-01 12:33:54 +01:00
return super().fields_to_replace() + [
2016-10-02 15:21:28 +02:00
('purchase.request', 'customer'),
('purchase.purchase', 'customer'),
('stock.shipment.drop', 'supplier'),
('stock.shipment.drop', 'customer'),
]
2018-03-24 00:09:55 +01:00
2020-03-01 12:33:54 +01:00
class Erase(metaclass=PoolMeta):
2018-03-24 00:09:55 +01:00
__name__ = 'party.erase'
def check_erase_company(self, party, company):
pool = Pool()
ShipmentDrop = pool.get('stock.shipment.drop')
2020-03-01 12:33:54 +01:00
super().check_erase_company(party, company)
2018-03-24 00:09:55 +01:00
shipments = ShipmentDrop.search([
['OR',
('supplier', '=', party.id),
('customer', '=', party.id),
],
2019-12-14 10:47:54 +01:00
('company', '=', company.id),
('state', 'not in', ['done', 'cancelled']),
2018-03-24 00:09:55 +01:00
])
if shipments:
raise EraseError(
gettext('stock.msg_erase_party_shipment',
party=party.rec_name,
company=company.rec_name))