Files
tryton/party.py
T

112 lines
3.5 KiB
Python
Raw Normal View History

2014-12-02 12:55:12 +01: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.
2017-04-01 00:30:53 +02:00
from trytond import backend
2018-03-24 00:03:18 +01:00
from trytond.pool import PoolMeta, Pool
2017-04-01 00:30:53 +02:00
from trytond.tools.multivalue import migrate_property
2018-03-24 00:03:18 +01:00
from trytond.transaction import Transaction
2012-09-24 22:17:50 +02:00
2017-04-01 00:30:53 +02:00
from .model import CompanyMultiValueMixin, CompanyValueMixin
__all__ = ['Configuration', 'PartyConfigurationLang', 'Party', 'PartyLang',
'PartyReplace', 'PartyErase', 'ContactMechanism']
2011-09-08 15:33:10 +02:00
2018-06-26 19:11:46 +02:00
class Configuration(CompanyMultiValueMixin, metaclass=PoolMeta):
2012-09-24 22:17:50 +02:00
__name__ = 'party.configuration'
2011-09-08 15:33:10 +02:00
2018-06-26 19:11:46 +02:00
class PartyConfigurationLang(CompanyValueMixin, metaclass=PoolMeta):
2017-04-01 00:30:53 +02:00
__name__ = 'party.configuration.party_lang'
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
exist = TableHandler.table_exist(cls._table)
if exist:
2018-07-24 22:01:07 +02:00
table = cls.__table_handler__(module_name)
2017-04-01 00:30:53 +02:00
exist &= table.column_exist('company')
super(PartyConfigurationLang, cls).__register__(module_name)
if not exist:
# Re-migrate with company
migrate_property(
'party.configuration', cls._configuration_value_field,
cls, cls._configuration_value_field, fields=['company'])
2018-06-26 19:11:46 +02:00
class Party(CompanyMultiValueMixin, metaclass=PoolMeta):
2017-04-01 00:30:53 +02:00
__name__ = 'party.party'
2018-06-26 19:11:46 +02:00
class PartyLang(CompanyValueMixin, metaclass=PoolMeta):
2017-04-01 00:30:53 +02:00
__name__ = 'party.party.lang'
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
exist = TableHandler.table_exist(cls._table)
if exist:
2018-07-24 22:01:07 +02:00
table = cls.__table_handler__(module_name)
2017-04-01 00:30:53 +02:00
exist &= table.column_exist('company')
super(PartyLang, cls).__register__(module_name)
if not exist:
# Re-migrate with company
cls._migrate_property([], [], [])
@classmethod
def _migrate_property(cls, field_names, value_names, fields):
fields.append('company')
super(PartyLang, cls)._migrate_property(
field_names, value_names, fields)
2016-10-02 15:20:37 +02:00
2018-06-26 19:11:46 +02:00
class PartyReplace(metaclass=PoolMeta):
2016-10-02 15:20:37 +02:00
__name__ = 'party.replace'
@classmethod
def fields_to_replace(cls):
return super(PartyReplace, cls).fields_to_replace() + [
('company.company', 'party'),
('company.employee', 'party'),
]
2018-03-24 00:03:18 +01:00
2018-06-26 19:11:46 +02:00
class PartyErase(metaclass=PoolMeta):
2018-03-24 00:03:18 +01:00
__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
class ContactMechanism(CompanyMultiValueMixin, metaclass=PoolMeta):
__name__ = 'party.contact_mechanism'
def _phone_country_codes(self):
pool = Pool()
Company = pool.get('company.company')
context = Transaction().context
yield from super()._phone_country_codes()
if 'company' in context:
company = Company(context['company'])
for address in company.party.addresses:
if address.country:
yield address.country.code