2017-06-02 18:32:43 +02:00
|
|
|
# The COPYRIGHT file at the top level of this repository contains
|
|
|
|
# the full copyright notices and license terms.
|
2017-04-28 09:26:42 +02:00
|
|
|
from trytond.model import fields
|
|
|
|
from trytond.pool import PoolMeta
|
|
|
|
from . import aeat
|
|
|
|
|
|
|
|
__all__ = ['Party']
|
|
|
|
|
2017-06-02 18:32:43 +02:00
|
|
|
|
2017-04-28 09:26:42 +02:00
|
|
|
class Party:
|
|
|
|
__name__ = 'party.party'
|
|
|
|
__metaclass__ = PoolMeta
|
|
|
|
|
2017-07-07 11:29:00 +02:00
|
|
|
sii_identifier_type = fields.Selection(aeat.PARTY_IDENTIFIER_TYPE,
|
|
|
|
'SII Identifier Type')
|
|
|
|
sii_vat_code = fields.Function(fields.Char('SII VAT Code', size=9),
|
2017-06-07 19:08:58 +02:00
|
|
|
'get_sii_vat_data')
|
2017-07-07 11:29:00 +02:00
|
|
|
sii_vat_country = fields.Function(fields.Char('SII VAT Country', size=2),
|
2017-06-07 19:08:58 +02:00
|
|
|
'get_sii_vat_data')
|
|
|
|
|
|
|
|
def get_sii_vat_data(self, name=None):
|
2017-08-28 14:17:12 +02:00
|
|
|
vat_code = self.vat_code
|
|
|
|
if vat_code:
|
|
|
|
type = None
|
|
|
|
for identifier in self.identifiers:
|
|
|
|
if identifier.code == vat_code:
|
|
|
|
type = identifier.type
|
|
|
|
break
|
2017-06-07 19:08:58 +02:00
|
|
|
if name == 'sii_vat_code':
|
2017-08-28 14:17:12 +02:00
|
|
|
return vat_code[2:] if type == 'eu_vat' else vat_code
|
2017-06-07 19:08:58 +02:00
|
|
|
elif name == 'sii_vat_country':
|
2017-08-28 14:17:12 +02:00
|
|
|
return vat_code[:2] if type == 'eu_vat' else None
|