2016-10-11 18:17:34 +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
|
2020-02-24 18:38:48 +01:00
|
|
|
from trytond.model import fields
|
2018-12-29 14:20:29 +01:00
|
|
|
from trytond.modules.party.exceptions import EraseError
|
2021-12-11 17:58:42 +01:00
|
|
|
from trytond.pool import Pool, PoolMeta
|
2018-12-29 14:20:29 +01:00
|
|
|
|
2020-02-24 18:38:48 +01:00
|
|
|
|
|
|
|
|
class Party(metaclass=PoolMeta):
|
|
|
|
|
__name__ = 'party.party'
|
|
|
|
|
agents = fields.One2Many('commission.agent.selection', 'party', "Agents")
|
2016-10-11 18:17:34 +02:00
|
|
|
|
|
|
|
|
|
2020-03-01 12:33:52 +01:00
|
|
|
class Replace(metaclass=PoolMeta):
|
2016-10-11 18:17:34 +02:00
|
|
|
__name__ = 'party.replace'
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def fields_to_replace(cls):
|
2020-03-01 12:33:52 +01:00
|
|
|
return super().fields_to_replace() + [
|
2016-10-11 18:17:34 +02:00
|
|
|
('commission.agent', 'party'),
|
|
|
|
|
]
|
2018-03-24 00:06:36 +01:00
|
|
|
|
|
|
|
|
|
2020-03-01 12:33:52 +01:00
|
|
|
class Erase(metaclass=PoolMeta):
|
2018-03-24 00:06:36 +01:00
|
|
|
__name__ = 'party.erase'
|
|
|
|
|
|
|
|
|
|
def check_erase_company(self, party, company):
|
|
|
|
|
pool = Pool()
|
|
|
|
|
Commission = pool.get('commission')
|
2020-03-01 12:33:52 +01:00
|
|
|
super().check_erase_company(party, company)
|
2018-03-24 00:06:36 +01:00
|
|
|
|
|
|
|
|
commissions = Commission.search([
|
|
|
|
|
('agent.party', '=', party.id),
|
2020-11-24 12:16:09 +01:00
|
|
|
('agent.company', '=', company.id),
|
2018-03-24 00:06:36 +01:00
|
|
|
('invoice_line', '=', None),
|
|
|
|
|
])
|
|
|
|
|
if commissions:
|
2018-12-29 14:20:29 +01:00
|
|
|
raise EraseError(
|
|
|
|
|
gettext('commission.msg_erase_party_pending_commission',
|
|
|
|
|
party=party.rec_name,
|
|
|
|
|
company=company.rec_name))
|