mirror of
https://gitlab.com/datalifeit/trytond-aeat_sii
synced 2023-12-13 20:30:37 +01:00
Fix mapper instantiation, vat_code format, identifier_type party selection
This commit is contained in:
parent
336db8b9a8
commit
0cd3dd7a82
64
aeat.py
64
aeat.py
|
@ -247,7 +247,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
'readonly': Eval('state') != 'draft',
|
||||
}, depends=['state'])
|
||||
currency = fields.Function(fields.Many2One('currency.currency',
|
||||
'Currency'), 'get_currency')
|
||||
'Currency'), 'on_change_with_currency')
|
||||
fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
|
||||
required=True, states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
|
@ -261,7 +261,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
domain=[('fiscalyear', '=', Eval('fiscalyear'))],
|
||||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
}, depends=['state'])
|
||||
}, depends=['state', 'fiscalyear'])
|
||||
|
||||
operation_type = fields.Selection(COMMUNICATION_TYPE, 'Operation Type',
|
||||
required=True,
|
||||
|
@ -336,14 +336,14 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
('cancelled', 'draft'),
|
||||
))
|
||||
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
|
||||
return Transaction().context.get('company')
|
||||
|
||||
def get_currency(self, name):
|
||||
return self.company.currency.id
|
||||
@fields.depends('company')
|
||||
def on_change_with_currency(self, name):
|
||||
if self.company:
|
||||
return self.company.currency.id
|
||||
|
||||
@staticmethod
|
||||
def default_fiscalyear():
|
||||
|
@ -357,13 +357,22 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
|
||||
@staticmethod
|
||||
def default_version():
|
||||
return '0.6'
|
||||
return '0.7'
|
||||
|
||||
@fields.depends('company')
|
||||
def on_change_with_company_vat(self):
|
||||
if self.company:
|
||||
return self.company.party.vat_number
|
||||
|
||||
@classmethod
|
||||
def copy(cls, records, default=None):
|
||||
if default is None:
|
||||
default = {}
|
||||
else:
|
||||
default = default.copy()
|
||||
default['communication_state'] = None
|
||||
return super(SIIReport, cls).copy(records, default=default)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('draft')
|
||||
|
@ -441,10 +450,10 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
_logger.info('Sending report %s to AEAT SII', self.id)
|
||||
headers = mapping.get_headers(
|
||||
name=self.company.party.name,
|
||||
vat=self.company.party.vat_number,
|
||||
vat=self.company_vat,
|
||||
comm_kind=self.operation_type)
|
||||
pool = Pool()
|
||||
mapper = pool.get('aeat.sii.issued.invoice.mapper')(pool=pool)
|
||||
mapper = IssuedTrytonInvoiceMapper(pool=pool)
|
||||
res = None
|
||||
with self.company.tmp_ssl_credentials() as (crt, key):
|
||||
srv = service.bind_issued_invoices_service(crt, key, test=True)
|
||||
|
@ -468,10 +477,10 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
def delete_issued_invoices(self):
|
||||
headers = mapping.get_headers(
|
||||
name=self.company.party.name,
|
||||
vat=self.company.party.vat_number,
|
||||
vat=self.company_vat,
|
||||
comm_kind=self.operation_type)
|
||||
pool = Pool()
|
||||
mapper = pool.get('aeat.sii.issued.invoice.mapper')(pool=pool)
|
||||
mapper = IssuedTrytonInvoiceMapper(pool=pool)
|
||||
res = None
|
||||
with self.company.tmp_ssl_credentials() as (crt, key):
|
||||
srv = service.bind_issued_invoices_service(crt, key, test=True)
|
||||
|
@ -498,7 +507,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
Invoice = pool.get('account.invoice')
|
||||
headers = mapping.get_headers(
|
||||
name=self.company.party.name,
|
||||
vat=self.company.party.vat_number,
|
||||
vat=self.company_vat,
|
||||
comm_kind=self.operation_type)
|
||||
|
||||
with self.company.tmp_ssl_credentials() as (crt, key):
|
||||
|
@ -545,10 +554,10 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
_logger.info('Sending report %s to AEAT SII', self.id)
|
||||
headers = mapping.get_headers(
|
||||
name=self.company.party.name,
|
||||
vat=self.company.party.vat_code,
|
||||
vat=self.company_vat,
|
||||
comm_kind=self.operation_type)
|
||||
pool = Pool()
|
||||
mapper = pool.get('aeat.sii.recieved.invoice.mapper')(pool=pool)
|
||||
mapper = RecievedTrytonInvoiceMapper(pool=pool)
|
||||
res = None
|
||||
with self.company.tmp_ssl_credentials() as (crt, key):
|
||||
srv = service.bind_recieved_invoices_service(crt, key, test=True)
|
||||
|
@ -572,10 +581,10 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
def delete_recieved_invoices(self):
|
||||
headers = mapping.get_headers(
|
||||
name=self.company.party.name,
|
||||
vat=self.company.party.vat_code,
|
||||
vat=self.company_vat,
|
||||
comm_kind=self.operation_type)
|
||||
pool = Pool()
|
||||
mapper = pool.get('aeat.sii.recieved.invoice.mapper')(pool=pool)
|
||||
mapper = RecievedTrytonInvoiceMapper(pool=pool)
|
||||
res = None
|
||||
with self.company.tmp_ssl_credentials() as (crt, key):
|
||||
srv = service.bind_recieved_invoices_service(crt, key, test=True)
|
||||
|
@ -602,7 +611,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
Invoice = pool.get('account.invoice')
|
||||
headers = mapping.get_headers(
|
||||
name=self.company.party.name,
|
||||
vat=self.company.party.vat_code,
|
||||
vat=self.company_vat,
|
||||
comm_kind=self.operation_type)
|
||||
|
||||
with self.company.tmp_ssl_credentials() as (crt, key):
|
||||
|
@ -647,21 +656,21 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
})
|
||||
|
||||
|
||||
class BaseTrytonInvoiceMapper(Model):
|
||||
class BaseTrytonInvoiceMapper(object):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(BaseTrytonInvoiceMapper, self).__init__(*args, **kwargs)
|
||||
super(BaseTrytonInvoiceMapper, self).__init__()
|
||||
self.pool = Pool()
|
||||
|
||||
year = attrgetter('move.period.fiscalyear.name')
|
||||
period = attrgetter('move.period.start_date.month')
|
||||
nif = attrgetter('company.party.vat_code')
|
||||
nif = attrgetter('company.party.vat_number')
|
||||
issue_date = attrgetter('invoice_date')
|
||||
invoice_kind = attrgetter('sii_operation_key')
|
||||
rectified_invoice_kind = callback_utils.fixed_value('I')
|
||||
not_exempt_kind = attrgetter('sii_subjected')
|
||||
counterpart_name = attrgetter('party.name')
|
||||
counterpart_nif = attrgetter('party.vat_code')
|
||||
counterpart_nif = attrgetter('party.vat_number')
|
||||
counterpart_id_type = attrgetter('party.identifier_type')
|
||||
counterpart_country = attrgetter('party.vat_country')
|
||||
counterpart_id = counterpart_nif
|
||||
|
@ -698,7 +707,6 @@ class IssuedTrytonInvoiceMapper(
|
|||
"""
|
||||
Tryton Issued Invoice to AEAT mapper
|
||||
"""
|
||||
__name__ = 'aeat.sii.issued.invoice.mapper'
|
||||
serial_number = attrgetter('number')
|
||||
specialkey_or_trascendence = attrgetter('sii_issued_key')
|
||||
|
||||
|
@ -709,7 +717,6 @@ class RecievedTrytonInvoiceMapper(
|
|||
"""
|
||||
Tryton Recieved Invoice to AEAT mapper
|
||||
"""
|
||||
__name__ = 'aeat.sii.recieved.invoice.mapper'
|
||||
serial_number = attrgetter('reference')
|
||||
specialkey_or_trascendence = attrgetter('sii_received_key')
|
||||
move_date = attrgetter('move.date')
|
||||
|
@ -736,3 +743,14 @@ class SIIReportLine(ModelSQL, ModelView):
|
|||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
@classmethod
|
||||
def copy(cls, records, default=None):
|
||||
if default is None:
|
||||
default = {}
|
||||
else:
|
||||
default = default.copy()
|
||||
default['state'] = None
|
||||
default['communication_code'] = None
|
||||
default['communication_msg'] = None
|
||||
return super(SIIReportLine, cls).copy(records, default=default)
|
||||
|
|
2
aeat.xml
2
aeat.xml
|
@ -1,4 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#This file is part party_comment module for Tryton.
|
||||
#The COPYRIGHT file at the top level of this repository contains
|
||||
#the full copyright notices and license terms.
|
||||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
|
||||
from logging import getLogger
|
||||
from contextlib import contextmanager
|
||||
|
@ -27,6 +26,7 @@ class Company:
|
|||
|
||||
cls._error_messages.update({
|
||||
'missing_fernet_key': "Missing Fernet key configuration",
|
||||
'missing_pem_cert': "Missing PEM certificate"
|
||||
})
|
||||
|
||||
pem_certificate = fields.Binary(
|
||||
|
@ -90,6 +90,8 @@ class Company:
|
|||
|
||||
@contextmanager
|
||||
def tmp_ssl_credentials(self):
|
||||
if not self.pem_certificate:
|
||||
self.raise_user_error('missing_pem_cert')
|
||||
with NamedTemporaryFile(suffix='.crt') as crt:
|
||||
with NamedTemporaryFile(suffix='.pem') as key:
|
||||
crt.write(self.pem_certificate)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ class Invoice:
|
|||
SIILines = pool.get('aeat.sii.report.lines')
|
||||
result = {}
|
||||
for name in names:
|
||||
result[name] = dict((i.id, '') for i in invoices)
|
||||
result[name] = dict((i.id, None) for i in invoices)
|
||||
|
||||
table = SIILines.__table__()
|
||||
cursor = Transaction().cursor
|
||||
|
@ -102,7 +102,6 @@ class Invoice:
|
|||
|
||||
for state, inv in cursor.fetchall():
|
||||
result['sii_state'][inv] = state
|
||||
|
||||
return result
|
||||
|
||||
def _credit(self):
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="aeat_sii_invoice_form_view">
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<data>
|
||||
|
||||
<record model="ir.ui.view" id="load_pkcs12_start_view">
|
||||
<field name="model">aeat.sii.load_pkcs12.start</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">load_pkcs12_start</field>
|
||||
</record>
|
||||
<record model="ir.action.wizard" id="act_aeat_sii_load_pkcs12">
|
||||
<field name="name">Load PKCS12</field>
|
||||
<field name="wiz_name">aeat.sii.load_pkcs12</field>
|
||||
</record>
|
||||
<record model="ir.action.keyword" id="act_aeat_sii_load_pkcs12_keyword1">
|
||||
<field name="action" ref="act_aeat_sii_load_pkcs12"/>
|
||||
<field name="keyword">form_action</field>
|
||||
<field name="model">company.company,-1</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="load_pkcs12_start_view">
|
||||
<field name="model">aeat.sii.load_pkcs12.start</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">load_pkcs12_start</field>
|
||||
</record>
|
||||
<record model="ir.action.wizard" id="act_aeat_sii_load_pkcs12">
|
||||
<field name="name">Load PKCS12</field>
|
||||
<field name="wiz_name">aeat.sii.load_pkcs12</field>
|
||||
</record>
|
||||
<record model="ir.action.keyword" id="act_aeat_sii_load_pkcs12_keyword1">
|
||||
<field name="action" ref="act_aeat_sii_load_pkcs12"/>
|
||||
<field name="keyword">form_action</field>
|
||||
<field name="model">company.company,-1</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -8,7 +8,11 @@ msgstr "No se ha podido cargar PKCS12: %s"
|
|||
|
||||
msgctxt "error:company.company:"
|
||||
msgid "Missing Fernet key configuration"
|
||||
msgstr "Falta clave Fernet a la configuración"
|
||||
msgstr "Falta clave Fernet en la configuración"
|
||||
|
||||
msgctxt "error:company.company:"
|
||||
msgid "Missing PEM certificate"
|
||||
msgstr "Falta certificado PEM"
|
||||
|
||||
msgctxt "field:account.invoice,sii_book_key:"
|
||||
msgid "SII Book Key"
|
||||
|
@ -122,7 +126,6 @@ msgctxt "field:aeat.sii.report,rec_name:"
|
|||
msgid "Name"
|
||||
msgstr "Nombre"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:aeat.sii.report,state:"
|
||||
msgid "State"
|
||||
msgstr "Estado"
|
||||
|
@ -131,7 +134,6 @@ msgctxt "field:aeat.sii.report,version:"
|
|||
msgid "Version"
|
||||
msgstr "Versión"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:aeat.sii.report,write_date:"
|
||||
msgid "Write Date"
|
||||
msgstr "Fecha de modificación"
|
||||
|
@ -184,7 +186,6 @@ msgctxt "field:aeat.sii.report.lines,write_date:"
|
|||
msgid "Write Date"
|
||||
msgstr "Fecha de modificación"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:aeat.sii.report.lines,write_uid:"
|
||||
msgid "Write User"
|
||||
msgstr "Usuario modificación"
|
||||
|
@ -251,7 +252,7 @@ msgstr "Informe SII"
|
|||
|
||||
msgctxt "model:ir.action,name:act_aeat_sii_report_line"
|
||||
msgid "AEAT SII Report Lines"
|
||||
msgstr "Línias informe SII"
|
||||
msgstr "Líneas informe SII"
|
||||
|
||||
msgctxt "model:ir.action,name:act_aeat_sii_report_lines"
|
||||
msgid "SII Report Lines"
|
||||
|
@ -802,14 +803,13 @@ msgctxt "view:aeat.sii.report:"
|
|||
msgid "Load Invoices"
|
||||
msgstr "Cargar facturas"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "view:aeat.sii.report:"
|
||||
msgid "Send"
|
||||
msgstr "Enviar"
|
||||
|
||||
msgctxt "view:company.company:"
|
||||
msgid "Certificate"
|
||||
msgstr ""
|
||||
msgstr "Certificado"
|
||||
|
||||
msgctxt "wizard_button:aeat.sii.load_pkcs12,start,end:"
|
||||
msgid "Cancel"
|
||||
|
|
9
party.py
9
party.py
|
@ -1,6 +1,5 @@
|
|||
#This file is part party_comment module for Tryton.
|
||||
#The COPYRIGHT file at the top level of this repository contains
|
||||
#the full copyright notices and license terms.
|
||||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
from . import aeat
|
||||
|
@ -13,5 +12,5 @@ class Party:
|
|||
__metaclass__ = PoolMeta
|
||||
|
||||
# TODO: v4 change to party.identifier module
|
||||
identifier_type = fields.Selection( [('','')] + aeat.PARTY_IDENTIFIER_TYPE,
|
||||
'Identifier Type', )
|
||||
identifier_type = fields.Selection(aeat.PARTY_IDENTIFIER_TYPE,
|
||||
'Identifier Type')
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part party_comment module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="party_view_form">
|
||||
|
|
|
@ -8,8 +8,8 @@ from trytond.tests.test_tryton import test_view, test_depends
|
|||
# from trytond.tests.test_tryton import doctest_setup, doctest_teardown
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
'Test module'
|
||||
class AeatSIITestCase(unittest.TestCase):
|
||||
'Test AEAT SII module'
|
||||
|
||||
def setUp(self):
|
||||
trytond.tests.test_tryton.install_module('aeat_sii')
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of party_comment module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license types. -->
|
||||
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page[@id='reports']" position="after">
|
||||
<page string="Certificate" col="2" id="certificate">
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of party_comment module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license types. -->
|
||||
|
||||
<form string="Load PKCS12" col="2">
|
||||
<label name="pfx"/>
|
||||
<field name="pfx"/>
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of party_comment module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license types. -->
|
||||
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page[@id='accounting']/field[@name='vat_number']"
|
||||
position="after">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
<!-- The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<form string="AEAT SII Data Reassigment Done" col="2">
|
||||
<image name="tryton-dialog-information" xexpand="0" xfill="0"/>
|
||||
|
|
Loading…
Reference in a new issue