2016-10-11 18:16:47 +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.
|
2018-12-29 14:20:29 +01:00
|
|
|
from trytond.i18n import gettext
|
|
|
|
|
from trytond.modules.party.exceptions import EraseError
|
2021-12-11 17:58:43 +01:00
|
|
|
from trytond.pool import Pool, PoolMeta
|
2018-12-29 14:20:29 +01:00
|
|
|
|
2016-10-11 18:16:47 +02:00
|
|
|
|
2020-03-01 12:33:53 +01:00
|
|
|
class Replace(metaclass=PoolMeta):
|
2016-10-11 18:16:47 +02:00
|
|
|
__name__ = 'party.replace'
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def fields_to_replace(cls):
|
2020-03-01 12:33:53 +01:00
|
|
|
return super().fields_to_replace() + [
|
2016-10-11 18:16:47 +02:00
|
|
|
('project.work', 'party'),
|
|
|
|
|
]
|
2018-03-24 00:07:13 +01:00
|
|
|
|
|
|
|
|
|
2020-03-01 12:33:53 +01:00
|
|
|
class Erase(metaclass=PoolMeta):
|
2018-03-24 00:07:13 +01:00
|
|
|
__name__ = 'party.erase'
|
|
|
|
|
|
|
|
|
|
def check_erase_company(self, party, company):
|
|
|
|
|
pool = Pool()
|
|
|
|
|
Work = pool.get('project.work')
|
2020-03-01 12:33:53 +01:00
|
|
|
super().check_erase_company(party, company)
|
2018-03-24 00:07:13 +01:00
|
|
|
|
|
|
|
|
works = Work.search([
|
|
|
|
|
('party', '=', party.id),
|
2019-12-14 10:47:54 +01:00
|
|
|
('company', '=', company.id),
|
2020-12-05 11:47:21 +01:00
|
|
|
('progress', '!=', 1),
|
2018-03-24 00:07:13 +01:00
|
|
|
])
|
|
|
|
|
if works:
|
2018-12-29 14:20:29 +01:00
|
|
|
raise EraseError(
|
|
|
|
|
gettext('project.msg_erase_party_opened_project',
|
|
|
|
|
party=party.rec_name,
|
|
|
|
|
company=company.rec_name))
|