diff --git a/__init__.py b/__init__.py index d78136bd1f..ce833fd61c 100644 --- a/__init__.py +++ b/__init__.py @@ -4,7 +4,7 @@ from trytond.pool import Pool from .company import * from .cron import * -from .party import * +from . import party def register(): @@ -19,15 +19,16 @@ def register(): CompanyConfigStart, Cron, CronCompany, - Configuration, - PartyConfigurationLang, - Party, - PartyLang, + party.Configuration, + party.PartyConfigurationLang, + party.Party, + party.PartyLang, Rule, module='company', type_='model') Pool.register( CompanyConfig, - PartyReplace, + party.PartyReplace, + party.PartyErase, module='company', type_='wizard') Pool.register( LetterReport, diff --git a/party.py b/party.py index 2af8083f68..474780a56c 100644 --- a/party.py +++ b/party.py @@ -1,13 +1,14 @@ # 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 import backend -from trytond.pool import PoolMeta +from trytond.pool import PoolMeta, Pool from trytond.tools.multivalue import migrate_property +from trytond.transaction import Transaction from .model import CompanyMultiValueMixin, CompanyValueMixin __all__ = ['Configuration', 'PartyConfigurationLang', 'Party', 'PartyLang', - 'PartyReplace'] + 'PartyReplace', 'PartyErase'] class Configuration(CompanyMultiValueMixin): @@ -76,3 +77,25 @@ class PartyReplace: ('company.company', 'party'), ('company.employee', 'party'), ] + + +class PartyErase: + __metaclass__ = PoolMeta + __name__ = 'party.erase' + + def check_erase(self, party): + pool = Pool() + Party = pool.get('party.party') + Company = pool.get('company.company') + + super(PartyErase, self).check_erase(party) + + with Transaction().set_user(0): + companies = Company.search([]) + for company in companies: + with Transaction().set_context(company=company.id): + party = Party(party.id) + self.check_erase_company(party, company) + + def check_erase_company(self, party, company): + pass