Unaccent data and countepart country

- Unaccent data to submit AEAT
- Get counterpart country from invoice address when not has vat country
Merge from task-031671
This commit is contained in:
Raimon Esteve 2017-07-25 08:54:41 +02:00
parent 9b5795a64a
commit 353949f163
3 changed files with 52 additions and 19 deletions

13
aeat.py
View File

@ -14,6 +14,7 @@ from trytond.pyson import Eval, Bool
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.config import config
from . import tools
__all__ = [
'SIIReport',
@ -472,7 +473,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
_logger.info('Sending report %s to AEAT SII', self.id)
headers = mapping.get_headers(
name=self.company.party.name,
name=tools.unaccent(self.company.party.name),
vat=self.company_vat,
comm_kind=self.operation_type,
version=self.version)
@ -494,7 +495,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
mapper = pool.get('aeat.sii.issued.invoice.mapper')(pool=pool)
headers = mapping.get_headers(
name=self.company.party.name,
name=tools.unaccent(self.company.party.name),
vat=self.company_vat,
comm_kind=self.operation_type,
version=self.version)
@ -516,7 +517,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
Invoice = pool.get('account.invoice')
headers = mapping.get_headers(
name=self.company.party.name,
name=tools.unaccent(self.company.party.name),
vat=self.company_vat,
comm_kind=self.operation_type,
version=self.version)
@ -596,7 +597,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
_logger.info('Sending report %s to AEAT SII', self.id)
headers = mapping.get_headers(
name=self.company.party.name,
name=tools.unaccent(self.company.party.name),
vat=self.company_vat,
comm_kind=self.operation_type,
version=self.version)
@ -618,7 +619,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
mapper = pool.get('aeat.sii.recieved.invoice.mapper')(pool=pool)
headers = mapping.get_headers(
name=self.company.party.name,
name=tools.unaccent(self.company.party.name),
vat=self.company_vat,
comm_kind=self.operation_type,
version=self.version)
@ -654,7 +655,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
SIIReportLineTax = pool.get('aeat.sii.report.line.tax')
headers = mapping.get_headers(
name=self.company.party.name,
name=tools.unaccent(self.company.party.name),
vat=self.company_vat,
comm_kind=self.operation_type,
version=self.version)

View File

@ -9,6 +9,7 @@ from pyAEATsii import callback_utils
from trytond.model import Model
from trytond.pool import Pool
from . import tools
__all__ = [
'IssuedTrytonInvoiceMapper',
@ -32,7 +33,6 @@ class BaseTrytonInvoiceMapper(Model):
rectified_invoice_kind = callback_utils.fixed_value('I')
not_exempt_kind = attrgetter('sii_subjected_key')
exempt_kind = attrgetter('sii_excemption_key')
counterpart_name = attrgetter('party.name')
def counterpart_nif(self, invoice):
nif = invoice.party.identifiers[0].code
@ -41,7 +41,6 @@ class BaseTrytonInvoiceMapper(Model):
return nif
counterpart_id_type = attrgetter('party.sii_identifier_type')
counterpart_country = attrgetter('party.sii_vat_country')
counterpart_id = counterpart_nif
untaxed_amount = attrgetter('untaxed_amount')
@ -50,12 +49,21 @@ class BaseTrytonInvoiceMapper(Model):
tax_base = attrgetter('base')
tax_amount = attrgetter('amount')
def counterpart_name(self, invoice):
return tools.unaccent(invoice.party.name)
def description(self, invoice):
return (
invoice.description or
invoice.lines[0].description or
self.serial_number(invoice)
)
if invoice.description:
return tools.unaccent(invoice.description)
if invoice.lines and invoice.lines[0].description:
return tools.unaccent(invoice.lines[0].description)
return self.serial_number(invoice)
def counterpart_country(self, invoice):
if invoice.party.sii_vat_country:
return invoice.party.sii_vat_country
return (invoice.invoice_address.country.code
if invoice.invoice_address.country else '')
def final_serial_number(self, invoice):
try:
@ -105,9 +113,8 @@ class BaseTrytonInvoiceMapper(Model):
return self.tax_amount(surcharge_tax)
class IssuedTrytonInvoiceMapper(
mapping.IssuedInvoiceMapper, BaseTrytonInvoiceMapper
):
class IssuedTrytonInvoiceMapper(mapping.IssuedInvoiceMapper,
BaseTrytonInvoiceMapper):
"""
Tryton Issued Invoice to AEAT mapper
"""
@ -116,9 +123,8 @@ class IssuedTrytonInvoiceMapper(
specialkey_or_trascendence = attrgetter('sii_issued_key')
class RecievedTrytonInvoiceMapper(
mapping.RecievedInvoiceMapper, BaseTrytonInvoiceMapper
):
class RecievedTrytonInvoiceMapper(mapping.RecievedInvoiceMapper,
BaseTrytonInvoiceMapper):
"""
Tryton Recieved Invoice to AEAT mapper
"""

26
tools.py Normal file
View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
import unicodedata
src_chars = """"/*+?¿!$[]{}@#`^:;<>=~%\\"""
src_chars = unicode(src_chars, 'iso-8859-1')
dst_chars = """________________________"""
dst_chars = unicode(dst_chars, 'iso-8859-1')
def normalize(text):
if isinstance(text, unicode):
text = text.encode('utf-8')
return text
def unaccent(text):
if isinstance(text, str):
text = unicode(text, 'utf-8')
output = text
for c in xrange(len(src_chars)):
if c >= len(dst_chars):
break
output = output.replace(src_chars[c], dst_chars[c])
output = unicodedata.normalize('NFKD', output).encode('ASCII',
'ignore')
return output.strip('_').encode('utf-8')