trytond-patches/issue10053.diff

452 lines
20 KiB
Diff

--- a/trytond/trytond/modules/party/configuration.py
+++ b/trytond/trytond/modules/party/configuration.py
@@ -1,11 +1,15 @@
# 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.i18n import gettext
from trytond.model import ModelView, ModelSQL, ModelSingleton, fields
from trytond.model import MultiValueMixin, ValueMixin
+from trytond.model.exceptions import AccessError
from trytond.pool import Pool
from trytond.tools.multivalue import migrate_property
+from .party import IDENTIFIER_TYPES
+
__all__ = ['Configuration', 'ConfigurationSequence', 'ConfigurationLang']
party_sequence = fields.Many2One('ir.sequence', 'Party Sequence',
@@ -23,6 +27,10 @@ class Configuration(ModelSingleton, ModelSQL, ModelView, MultiValueMixin):
party_sequence = fields.MultiValue(party_sequence)
party_lang = fields.MultiValue(party_lang)
+ identifier_types = fields.MultiSelection(
+ IDENTIFIER_TYPES, "Identifier Types",
+ help="Defines which identifier types are available.\n"
+ "Leave empty for all of them.")
@classmethod
def default_party_sequence(cls, **pattern):
@@ -33,6 +41,53 @@ class Configuration(ModelSingleton, ModelSQL, ModelView, MultiValueMixin):
except KeyError:
return None
+ def get_identifier_types(self):
+ selection = self.fields_get(
+ ['identifier_types'])['identifier_types']['selection']
+ if self.identifier_types:
+ selection = [
+ (k, v) for k, v in selection if k in self.identifier_types]
+ return selection
+
+ @classmethod
+ def create(cls, vlist):
+ records = super().create(vlist)
+ ModelView._fields_view_get_cache.clear()
+ return records
+
+ @classmethod
+ def write(cls, *args):
+ super().write(*args)
+ ModelView._fields_view_get_cache.clear()
+
+ @classmethod
+ def delete(cls, records):
+ super().delete(records)
+ ModelView._fields_view_get_cache.clear()
+
+ @classmethod
+ def validate(cls, records):
+ super().validate(records)
+ cls(1).check_identifier_types()
+
+ def check_identifier_types(self):
+ pool = Pool()
+ Identifier = pool.get('party.identifier')
+ if self.identifier_types:
+ identifiers = Identifier.search([
+ ('type', 'not in', [None, ''] + self.identifier_types),
+ ], limit=1, order=[])
+ if identifiers:
+ identifier, = identifiers
+ selection = self.fields_get(
+ ['identifier_types'])['identifier_types']['selection']
+ selection = dict(selection)
+ raise AccessError(gettext(
+ 'party.msg_identifier_type_remove',
+ type=selection.get(identifier.type, identifier.type),
+ identifier=identifier.rec_name,
+ ))
+
class _ConfigurationValue(ModelSQL):
--- a/trytond/trytond/modules/party/message.xml
+++ b/trytond/trytond/modules/party/message.xml
@@ -39,5 +39,8 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_address_subdivision_country_code_unique">
<field name="text">The country code on subdivision type must be unique.</field>
</record>
+ <record model="ir.message" id="msg_identifier_type_remove">
+ <field name="text">To remove the identifier type "%(type)s" from the configuration, you must change it on "%(identifier)s".</field>
+ </record>
</data>
</tryton>
--- a/trytond/trytond/modules/party/party.py
+++ b/trytond/trytond/modules/party/party.py
@@ -316,6 +316,147 @@ class PartyCategory(ModelSQL):
ondelete='CASCADE', required=True, select=True)
+IDENTIFIER_TYPES = [
+ ('ad_nrt', "Andorra Tax Number"),
+ ('al_nipt', "Albanian VAT Number"),
+ ('ar_cuit', "Argentinian Tax Number"),
+ ('ar_dni', "Argentinian National Identity Number"),
+ ('at_businessid', "Austrian Company Register"),
+ ('at_tin', "Austrian Tax Identification"),
+ ('at_vnr', "Austrian Social Security Number"),
+ ('au_abn', "Australian Business Number"),
+ ('au_acn', "Australian Company Number"),
+ ('au_tfn', "Australian Tax File Number"),
+ ('be_vat', "Belgian Enterprise Number"),
+ ('bg_egn', "Bulgarian Personal Identity Codes"),
+ ('bg_pnf', "Bulgarian Number of a Foreigner"),
+ ('bg_vat', "Bulgarian VAT Number"),
+ ('br_cnpj', "Brazillian Company Identifier"),
+ ('br_cpf', "Brazillian National Identifier"),
+ ('by_unp', "Belarus VAT Number"),
+ ('ca_bn', "Canadian Business Number"),
+ ('ca_sin', "Canadian Social Insurance Number"),
+ ('ch_ssn', "Swiss Social Security Number"),
+ ('ch_uid', "Swiss Business Identifier"),
+ ('ch_vat', "Swiss VAT Number"),
+ ('cl_rut', "Chilean National Tax Number"),
+ ('cn_ric', "Chinese Resident Identity Card Number"),
+ ('cn_uscc', "Chinese Unified Social Credit Code"),
+ ('co_nit', "Colombian Identity Code"),
+ ('co_rut', "Colombian Business Tax Number"),
+ ('cr_cpf', "Costa Rica Physical Person ID Number"),
+ ('cr_cpj', "Costa Rica Tax Number"),
+ ('cr_cr', "Costa Rica Foreigners ID Number"),
+ ('cu_ni', "Cuban Identity Card Number"),
+ ('cy_vat', "Cypriot VAT Number"),
+ ('cz_dic', "Czech VAT Number"),
+ ('cz_rc', "Czech National Identifier"),
+ ('de_handelsregisternummer', "German Company Register Number"),
+ ('de_idnr', "German Personal Tax Number"),
+ ('de_stnr', "German Tax Number"),
+ ('de_vat', "German VAT Number"),
+ ('dk_cpr', "Danish Citizen Number"),
+ ('dk_cvr', "Danish VAT Number"),
+ ('do_cedula', "Dominican Republic National Identification Number"),
+ ('do_rnc', "Dominican Republic Tax"),
+ ('ec_ci', "Ecuadorian Personal Identity Code"),
+ ('ec_ruc', "Ecuadorian Tax Identification"),
+ ('ee_ik', "Estonian Personal ID Number"),
+ ('ee_kmkr', "Estonian VAT Number"),
+ ('ee_registrikood', "Estonian Organisation Registration Code"),
+ ('es_cif', "Spanish Company Tax"),
+ ('es_dni', "Spanish Personal Identity Codes"),
+ ('es_nie', "Spanish Foreigner Number"),
+ ('es_nif', "Spanish VAT Number"),
+ ('eu_at_02', "SEPA Identifier of the Creditor (AT-02)"),
+ ('eu_vat', "European VAT Number"),
+ ('fi_alv', "Finnish VAT Number"),
+ ('fi_associationid', "Finnish Association Identifier"),
+ ('fi_hetu', "Finnish Personal Identity Code"),
+ ('fi_veronumero', "Finnish Individual Tax Number"),
+ ('fi_ytunnus', "Finnish Business Identifier"),
+ ('fr_nif', "French Tax Identification Number"),
+ ('fr_nir', "French Personal Identification Number"),
+ # TODO: remove from party_siren
+ # ('fr_siren', "French Company Identification Number"),
+ ('fr_tva', "French VAT Number"),
+ ('gb_nhs',
+ "United Kingdom National Health Service Patient Identifier"),
+ ('gb_upn', "English Unique Pupil Number"),
+ ('gb_vat', "United Kingdom (and Isle of Man) VAT Number"),
+ ('gr_amka', "Greek Social Security Number"),
+ ('gr_vat', "Greek VAT Number"),
+ ('gt_nit', "Guatemala Tax Number"),
+ ('hr_oib', "Croatian Identification Number"),
+ ('hu_anum', "Hungarian VAT Number"),
+ ('id_npwp', "Indonesian VAT Number"),
+ ('ie_pps', "Irish Personal Number"),
+ ('ie_vat', "Irish VAT Number"),
+ ('il_hp', "Israeli Company Number"),
+ ('il_idnr', "Israeli Identity Number"),
+ ('in_aadhaar', "Indian Digital Resident Personal Identity Number"),
+ ('in_pan', "Indian Income Tax Identifier"),
+ ('is_kennitala',
+ "Icelandic Personal and Organisation Identity Code"),
+ ('is_vsk', "Icelandic VAT Number"),
+ ('it_codicefiscale', "Italian Tax Code for Individuals"),
+ ('it_iva', "Italian VAT Number"),
+ ('jp_cn', "Japanese Corporate Number"),
+ ('kr_brn', "South Korea Business Registration Number"),
+ ('kr_krn', "South Korean Resident Registration Number"),
+ ('lt_asmens', "Lithuanian Personal Number"),
+ ('lt_pvm', "Lithuanian VAT Number"),
+ ('lu_tva', "Luxembourgian VAT Number"),
+ ('lv_pvn', "Latvian VAT Number"),
+ ('mc_tva', "Monacan VAT Number"),
+ ('md_idno', "Moldavian Company Identification Number"),
+ ('mt_vat', "Maltese VAT Number"),
+ ('mu_nid', "Mauritian National Identifier"),
+ ('mx_rfc', "Mexican Tax Number"),
+ ('my_nric',
+ "Malaysian National Registration Identity Card Number"),
+ ('nl_brin', "Dutch School Identification Number"),
+ ('nl_bsn', "Dutch Citizen Identification Number"),
+ ('nl_btw', "Dutch VAT Number"),
+ ('nl_onderwijsnummer', "Dutch Student Identification Number"),
+ ('no_fodselsnummer',
+ "Norwegian Birth Number, the National Identity Number"),
+ ('no_mva', "Norwegian VAT Number"),
+ ('no_orgnr', "Norwegian Organisation Number"),
+ ('nz_ird', "New Zealand Inland Revenue Department Number"),
+ ('pe_cui', "Peruvian Identity Number"),
+ ('pe_ruc', "Peruvian Company Tax Number"),
+ ('pl_nip', "Polish VAT Number"),
+ ('pl_pesel', "Polish National Identification Number"),
+ ('pl_regon', "Polish Register of Economic Units"),
+ ('pt_nif', "Portuguese VAT Number"),
+ ('py_ruc', "Paraguay Tax Number"),
+ ('ro_cf', "Romanian VAT Number"),
+ ('ro_cnp', "Romanian Numerical Personal Code"),
+ ('ro_onrc', "Romanian ONRC Number"),
+ ('rs_pib', "Serbian Tax Identification"),
+ ('ru_inn', "Russian Tax identifier"),
+ ('se_orgnr', "Swedish Company Number"),
+ ('se_personnummer', "Swedish Personal Number"),
+ ('se_vat', "Swedish VAT Number"),
+ ('si_ddv', "Slovenian VAT Number"),
+ ('sk_dph', "Slovak VAT Number"),
+ ('sk_rc', "Slovak Birth Number"),
+ ('sm_coe', "San Marino National Tax Number"),
+ ('tr_tckimlik', "Turkish Personal Identification Number"),
+ ('us_atin', "U.S. Adoption Taxpayer Identification Number"),
+ ('us_ein', "U.S. Employer Identification Number"),
+ ('us_itin', "U.S. Individual Taxpayer Identification Number"),
+ ('us_ptin', "U.S. Preparer Tax Identification Number"),
+ ('us_ssn', "U.S. Social Security Number"),
+ ('us_tin', "U.S. Taxpayer Identification Number"),
+ ('uy_ruc', "Uruguay Tax Number"),
+ ('ve_rif', "Venezuelan VAT Number"),
+ ('za_idnr', "South African Identity Document Number"),
+ ('za_tin', "South African Tax Identification Number"),
+ ]
+
+
class PartyIdentifier(sequence_ordered(), ModelSQL, ModelView):
'Party Identifier'
__name__ = 'party.identifier'
@@ -323,115 +464,7 @@ class PartyIdentifier(sequence_ordered(), ModelSQL, ModelView):
party = fields.Many2One('party.party', 'Party', ondelete='CASCADE',
required=True, select=True,
help="The party identified by this record.")
- type = fields.Selection([
- (None, ''),
- ('al_nipt', "Albanian VAT Number"),
- ('ar_cuit', "Argentinian Tax Number"),
- ('at_businessid', "Austrian Company Register"),
- ('at_tin', "Austrian Tax Identification"),
- ('au_abn', "Australian Business Number"),
- ('au_acn', "Australian Company Number"),
- ('au_tfn', "Australian Tax File Number"),
- ('be_vat', "Belgian Enterprise Number"),
- ('bg_egn', "Bulgarian Personal Identity Codes"),
- ('bg_pnf', "Bulgarian Number of a Foreigner"),
- ('bg_vat', "Bulgarian VAT Number"),
- ('br_cnpj', "Brazillian Company Identifier"),
- ('br_cpf', "Brazillian National Identifier"),
- ('ca_bn', "Canadian Business Number"),
- ('ca_sin', "Canadian Social Insurance Number"),
- ('ch_ssn', "Swiss Social Security Number"),
- ('ch_uid', "Swiss Business Identifier"),
- ('ch_vat', "Swiss VAT Number"),
- ('cl_rut', "Chilean National Tax Number"),
- ('cn_rit', "Chinese Resident Identity Card Number"),
- ('co_nit', "Colombian Identity Code"),
- ('co_rut', "Colombian Business Tax Number"),
- ('cy_vat', "Cypriot VAT Number"),
- ('cz_dic', "Czech VAT Number"),
- ('cz_rc', "Czech National Identifier"),
- ('de_handelsregisternummer', "German Company Register Number"),
- ('de_idnr', "German Personal Tax Number"),
- ('de_stnr', "German Tax Number"),
- ('de_vat', "German VAT Number"),
- ('dk_cpr', "Danish Citizen Number"),
- ('dk_cvr', "Danish VAT Number"),
- ('do_cedula', "Dominican Republic National Identification Number"),
- ('do_rnc', "Dominican Republic Tax"),
- ('ec_ci', "Ecuadorian Personal Identity Code"),
- ('ec_ruc', "Ecuadorian Tax Identification"),
- ('ee_ik', "Estonian Personcal ID number"),
- ('ee_kmkr', "Estonian VAT Number"),
- ('ee_registrikood', "Estonian Organisation Registration Code"),
- ('es_cif', "Spanish Company Tax"),
- ('es_dni', "Spanish Personal Identity Codes"),
- ('es_nie', "Spanish Foreigner Number"),
- ('es_nif', "Spanish VAT Number"),
- ('eu_at_02', "SEPA Identifier of the Creditor (AT-02)"),
- ('eu_vat', "European VAT Number"),
- ('fi_alv', "Finnish VAT Number"),
- ('fi_associationid', "Finnish Association Identifier"),
- ('fi_hetu', "Finnish Personal Identity Code"),
- ('fi_veronumero', "Finnish individual tax number"),
- ('fi_ytunnus', "Finnish Business Identifier"),
- ('fr_nif', "French Tax Identification Number"),
- ('fr_nir', "French Personal Identification Number"),
- # TODO: remove from party_siren
- # ('fr_siren', "French Company Identification Number"),
- ('fr_tva', "French VAT Number"),
- ('gb_nhs',
- "United Kingdom National Health Service Patient Identifier"),
- ('gb_upn', "English Unique Pupil Number"),
- ('gb_vat', "United Kingdom (and Isle of Man) VAT Number"),
- ('gr_vat', "Greek VAT Number"),
- ('hr_oib', "Croatian Identification Number"),
- ('hu_anum', "Hungarian VAT Number"),
- ('ie_pps', "Irish Personal Number"),
- ('ie_vat', "Irish VAT Number"),
- ('in_aadhaar', "Indian Digital Resident Personal Identity Number"),
- ('in_pan', "Indian Income Tax Identifier"),
- ('is_kennitala',
- "Icelandic Personal and Organisation Identity Code"),
- ('is_vsk', "Icelandic VAT Number"),
- ('it_codicefiscale', "Italian Tax Code for Individuals"),
- ('it_iva', "Italian VAT Number"),
- ('lt_pvm', "Lithuanian VAT Number"),
- ('lu_tva', "Luxembourgian VAT Number"),
- ('lv_pvn', "Latvian VAT Number"),
- ('mc_tva', "Monacan VAT Number"),
- ('mt_vat', "Maltese VAT Number"),
- ('mu_nid', "Mauritian National Identifier"),
- ('mx_rfc', "Mexican Tax Number"),
- ('my_nric',
- "Malaysian National Registration Identity Card Number"),
- ('nl_brin', "Dutch School Identification Number"),
- ('nl_bsn', "Dutch Citizen Identification Number"),
- ('nl_btw', "Dutch VAT Number"),
- ('nl_onderwijsnummer', "Dutch student identification number"),
- ('no_mva', "Norwegian VAT Number"),
- ('no_orgnr', "Norwegian Organisation Number"),
- ('pl_nip', "Polish VAT Number"),
- ('pl_pesel', "Polish National Identification Number"),
- ('pl_regon', "Polish Register of Economic Units"),
- ('pt_nif', "Portuguese VAT Number"),
- ('ro_cf', "Romanian VAT Number"),
- ('ro_cnp', "Romanian Numerical Personal Code"),
- ('rs_pib', "Serbian Tax Identification"),
- ('ru_inn', "Russian Tax identifier"),
- ('se_orgnr', "Swedish Company Number"),
- ('se_vat', "Swedish VAT Number"),
- ('si_ddv', "Slovenian VAT Number"),
- ('sk_dph', "Slovak VAT Number"),
- ('sk_rc', "Slovak Birth Number"),
- ('sm_coe', "San Marino National Tax Number"),
- ('tr_tckimlik', "Turkish Personal Identification Number"),
- ('us_atin', "U.S. Adoption Taxpayer Identification Number"),
- ('us_ein', "U.S. Employer Identification Number"),
- ('us_itin', "U.S. Individual Taxpayer Identification Number"),
- ('us_ptin', "U.S. Preparer Tax Identification Number"),
- ('us_ssn', "U.S. Social Security Number"),
- ('us_tin', "U.S. Taxpayer Identification Number"),
- ], 'Type')
+ type = fields.Selection('get_types', 'Type')
type_string = type.translated('type')
code = fields.Char('Code', required=True)
@@ -468,6 +501,13 @@ class PartyIdentifier(sequence_ordered(), ModelSQL, ModelView):
party_h.drop_column('vat_number')
party_h.drop_column('vat_country')
+ @classmethod
+ def get_types(cls):
+ pool = Pool()
+ Configuration = pool.get('party.configuration')
+ configuration = Configuration(1)
+ return [(None, '')] + configuration.get_identifier_types()
+
@fields.depends('type', 'code')
def on_change_with_code(self):
if self.type and '_' in self.type:
--- a/trytond/trytond/modules/party/view/configuration_form.xml
+++ b/trytond/trytond/modules/party/view/configuration_form.xml
@@ -6,4 +6,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="party_sequence"/>
<label name="party_lang"/>
<field name="party_lang" widget="selection"/>
+
+ <label name="identifier_types"/>
+ <field name="identifier_types"/>
</form>
diff --git a/trytond/trytond/modules/account_payment_sepa/__init__.py b/trytond/trytond/modules/account_payment_sepa/__init__.py
index 17457a9..feee60a 100644
--- a/trytond/trytond/modules/account_payment_sepa/__init__.py
+++ b/trytond/trytond/modules/account_payment_sepa/__init__.py
@@ -13,6 +13,7 @@ def register():
payment.Mandate,
payment.Payment,
payment.Message,
+ party.Configuration,
party.Party,
party.PartyIdentifier,
account.Configuration,
diff --git a/trytond/trytond/modules/account_payment_sepa/party.py b/trytond/trytond/modules/account_payment_sepa/party.py
index 2b7c16c..54de8d7 100644
--- a/trytond/trytond/modules/account_payment_sepa/party.py
+++ b/trytond/trytond/modules/account_payment_sepa/party.py
@@ -16,6 +16,15 @@ from trytond.modules.party.exceptions import InvalidIdentifierCode
from .exceptions import PartyIdentificationdError
+class Configuration(metaclass=PoolMeta):
+ __name__ = 'party.configuration'
+
+ @classmethod
+ def __setup__(cls):
+ super().__setup__()
+ cls.identifier_types.selection += [('sepa', 'SEPA Creditor Identifier')]
+
+
class Party(metaclass=PoolMeta):
__name__ = 'party.party'
sepa_creditor_identifier_used = fields.Function(fields.Char(
@@ -85,11 +94,6 @@ class PartyIdentifier(metaclass=PoolMeta):
},
depends=['type'])
- @classmethod
- def __setup__(cls):
- super(PartyIdentifier, cls).__setup__()
- cls.type.selection.append(('sepa', 'SEPA Creditor Identifier'))
-
@fields.depends('party', '_parent_party.identifiers')
def check_code(self):
super(PartyIdentifier, self).check_code()
diff --git a/trytond/trytond/modules/account_payment_sepa/tests/test_account_payment_sepa.py b/trytond/trytond/modules/account_payment_sepa/tests/test_account_payment_sepa.py
index 35ddddc..10e1337 100644
--- a/trytond/trytond/modules/account_payment_sepa/tests/test_account_payment_sepa.py
+++ b/trytond/trytond/modules/account_payment_sepa/tests/test_account_payment_sepa.py
@@ -150,6 +150,17 @@ class AccountPaymentSepaTestCase(ModuleTestCase):
'Test Account Payment SEPA module'
module = 'account_payment_sepa'
+ @with_transaction()
+ def test_party_identifiers(self):
+ 'Party Identifiers'
+ pool = Pool()
+ Configuration = pool.get('party.configuration')
+ PartyIdentifier = pool.get('party.identifier')
+
+ _TYPE = ('sepa', 'SEPA Creditor Identifier')
+ self.assertTrue(_TYPE in Configuration.identifier_types.selection)
+ self.assertTrue(_TYPE in PartyIdentifier.get_types())
+
@with_transaction()
def test_pain001_001_03(self):
'Test pain001.001.03 xsd validation'