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.
|
2021-12-11 17:58:42 +01:00
|
|
|
from trytond.pool import Pool, PoolMeta
|
2021-03-05 15:49:19 +01:00
|
|
|
from trytond.pyson import Eval
|
2021-12-11 17:58:42 +01:00
|
|
|
from trytond.report import Report
|
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
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2020-03-01 12:33:52 +01:00
|
|
|
class ConfigurationLang(CompanyValueMixin, metaclass=PoolMeta):
|
2017-04-01 00:30:53 +02:00
|
|
|
__name__ = 'party.configuration.party_lang'
|
|
|
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
2021-03-05 15:49:19 +01:00
|
|
|
@classmethod
|
|
|
|
|
def __setup__(cls):
|
|
|
|
|
super().__setup__()
|
|
|
|
|
cls.party.context['company'] = Eval('company', -1)
|
2022-04-08 19:07:13 +02:00
|
|
|
cls.party.depends.add('company')
|
2021-03-05 15:49:19 +01:00
|
|
|
|
2016-10-02 15:20:37 +02:00
|
|
|
|
2020-03-01 12:33:52 +01:00
|
|
|
class Replace(metaclass=PoolMeta):
|
2016-10-02 15:20:37 +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-02 15:20:37 +02:00
|
|
|
('company.company', 'party'),
|
|
|
|
|
('company.employee', 'party'),
|
|
|
|
|
]
|
2018-03-24 00:03:18 +01:00
|
|
|
|
|
|
|
|
|
2020-03-01 12:33:52 +01:00
|
|
|
class Erase(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')
|
|
|
|
|
|
2020-03-01 12:33:52 +01:00
|
|
|
super().check_erase(party)
|
2018-03-24 00:03:18 +01:00
|
|
|
|
|
|
|
|
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
|
2018-12-13 18:47:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
2019-11-02 17:32:56 +01:00
|
|
|
if context.get('company'):
|
2018-12-13 18:47:37 +01:00
|
|
|
company = Company(context['company'])
|
|
|
|
|
for address in company.party.addresses:
|
|
|
|
|
if address.country:
|
|
|
|
|
yield address.country.code
|
2019-12-05 22:37:16 +01:00
|
|
|
|
|
|
|
|
|
2021-04-11 18:37:41 +02:00
|
|
|
class ContactMechanismLanguage(CompanyValueMixin, metaclass=PoolMeta):
|
|
|
|
|
__name__ = 'party.contact_mechanism.language'
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def __setup__(cls):
|
|
|
|
|
super().__setup__()
|
|
|
|
|
cls.contact_mechanism.context['company'] = Eval('company', -1)
|
2022-04-08 19:07:13 +02:00
|
|
|
cls.contact_mechanism.depends.add('company')
|
2021-04-11 18:37:41 +02:00
|
|
|
|
|
|
|
|
|
2021-07-05 23:51:52 +02:00
|
|
|
class LetterReport(Report):
|
2019-12-05 22:37:16 +01:00
|
|
|
__name__ = 'party.letter'
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def execute(cls, ids, data):
|
|
|
|
|
with Transaction().set_context(address_with_party=True):
|
|
|
|
|
return super(LetterReport, cls).execute(ids, data)
|