Fix bug when update SII keys in invoice.
Convert config fields to Multivalue/Multicompany. Add raise when certificate is not deffined in configuration account when try to communicate with AEAT.
This commit is contained in:
parent
60f0e548b9
commit
a6f124ca1d
|
@ -15,6 +15,7 @@ from . import contract
|
|||
def register():
|
||||
Pool.register(
|
||||
account.Configuration,
|
||||
account.ConfigurationDefaultSII,
|
||||
account.TemplateTax,
|
||||
account.Tax,
|
||||
cron.Cron,
|
||||
|
|
72
account.py
72
account.py
|
@ -1,18 +1,64 @@
|
|||
# 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 trytond.model import fields, ModelSQL
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.modules.company.model import CompanyValueMixin
|
||||
from .aeat import (BOOK_KEY, OPERATION_KEY, SEND_SPECIAL_REGIME_KEY,
|
||||
RECEIVE_SPECIAL_REGIME_KEY, IVA_SUBJECTED, EXEMPTION_CAUSE)
|
||||
|
||||
|
||||
__all__ = ['Configuration', 'TemplateTax', 'Tax']
|
||||
|
||||
|
||||
class Configuration(metaclass=PoolMeta):
|
||||
__name__ = 'account.configuration'
|
||||
|
||||
aeat_certificate_sii = fields.MultiValue(fields.Many2One('certificate',
|
||||
'AEAT Certificate SII'))
|
||||
aeat_pending_sii = fields.MultiValue(fields.Boolean('AEAT Pending SII',
|
||||
help='Automatically generate AEAT Pending SII reports by cron'))
|
||||
aeat_pending_sii_send = fields.MultiValue(fields.Boolean('AEAT Pending SII Send',
|
||||
states={
|
||||
'invisible': ~Eval('aeat_pending_sii', False),
|
||||
}, depends=['aeat_pending_sii'],
|
||||
help='Automatically send AEAT Pending SII reports by cron'))
|
||||
aeat_received_sii = fields.MultiValue(fields.Boolean('AEAT Received SII',
|
||||
help='Automatically generate AEAT Received SII reports by cron'))
|
||||
aeat_received_sii_send = fields.MultiValue(fields.Boolean('AEAT Received SII Send',
|
||||
states={
|
||||
'invisible': ~Eval('aeat_received_sii', False),
|
||||
}, depends=['aeat_received_sii'],
|
||||
help='Automatically send AEAT Received SII reports by cron'))
|
||||
|
||||
@classmethod
|
||||
def multivalue_model(cls, field):
|
||||
pool = Pool()
|
||||
if field in {'aeat_certificate_sii', 'aeat_pending_sii',
|
||||
'aeat_pending_sii_send', 'aeat_received_sii',
|
||||
'aeat_received_sii_send'}:
|
||||
return pool.get('account.configuration.default_sii')
|
||||
return super().multivalue_model(field)
|
||||
|
||||
@classmethod
|
||||
def default_aeat_pending_sii(cls, **pattern):
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def default_aeat_received_sii(cls, **pattern):
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def default_aeat_pending_sii_send(cls, **pattern):
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def default_aeat_received_sii_send(cls, **pattern):
|
||||
return False
|
||||
|
||||
|
||||
class ConfigurationDefaultSII(ModelSQL, CompanyValueMixin):
|
||||
"Account Configuration Default SII Values"
|
||||
__name__ = 'account.configuration.default_sii'
|
||||
|
||||
aeat_certificate_sii = fields.Many2One('certificate',
|
||||
'AEAT Certificate SII')
|
||||
aeat_pending_sii = fields.Boolean('AEAT Pending SII',
|
||||
|
@ -30,22 +76,6 @@ class Configuration(metaclass=PoolMeta):
|
|||
}, depends=['aeat_received_sii'],
|
||||
help='Automatically send AEAT Received SII reports by cron')
|
||||
|
||||
@staticmethod
|
||||
def default_aeat_pending_sii():
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def default_aeat_received_sii():
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def default_aeat_pending_sii_send():
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def default_aeat_received_sii_send():
|
||||
return False
|
||||
|
||||
|
||||
class TemplateTax(metaclass=PoolMeta):
|
||||
__name__ = 'account.tax.template'
|
||||
|
|
13
aeat.py
13
aeat.py
|
@ -566,13 +566,12 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
certificate = config.aeat_certificate_sii
|
||||
if not certificate:
|
||||
_logger.info('Missing AEAT Certificate SII configuration')
|
||||
raise UserError(gettext('aeat_sii.msg_missing_certificate'))
|
||||
return certificate
|
||||
|
||||
def submit_issued_invoices(self):
|
||||
# get certificate from company
|
||||
certificate = self._get_certificate()
|
||||
if not certificate:
|
||||
return
|
||||
|
||||
if self.state != 'confirmed':
|
||||
_logger.info('This report %s has already been sended', self.id)
|
||||
|
@ -617,8 +616,6 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
def delete_issued_invoices(self):
|
||||
# get certificate from company
|
||||
certificate = self._get_certificate()
|
||||
if not certificate:
|
||||
return
|
||||
|
||||
if self.state != 'confirmed':
|
||||
_logger.info('This report %s has already been sended', self.id)
|
||||
|
@ -655,8 +652,6 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
|
||||
# get certificate from company
|
||||
certificate = self._get_certificate()
|
||||
if not certificate:
|
||||
return
|
||||
|
||||
headers = tools.get_headers(
|
||||
name=tools.unaccent(self.company.party.name),
|
||||
|
@ -781,8 +776,6 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
def submit_recieved_invoices(self):
|
||||
# get certificate from company
|
||||
certificate = self._get_certificate()
|
||||
if not certificate:
|
||||
return
|
||||
|
||||
if self.state != 'confirmed':
|
||||
_logger.info('This report %s has already been sended', self.id)
|
||||
|
@ -826,8 +819,6 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
def delete_recieved_invoices(self):
|
||||
# get certificate from company
|
||||
certificate = self._get_certificate()
|
||||
if not certificate:
|
||||
return
|
||||
|
||||
if self.state != 'confirmed':
|
||||
_logger.info('This report %s has already been sended', self.id)
|
||||
|
@ -884,8 +875,6 @@ class SIIReport(Workflow, ModelSQL, ModelView):
|
|||
|
||||
# get certificate from company
|
||||
certificate = self._get_certificate()
|
||||
if not certificate:
|
||||
return
|
||||
|
||||
headers = tools.get_headers(
|
||||
name=tools.unaccent(self.company.party.name),
|
||||
|
|
|
@ -133,7 +133,7 @@ class Invoice(metaclass=PoolMeta):
|
|||
if not invoice.sii_operation_key:
|
||||
invoice.sii_operation_key = invoice._get_sii_operation_key()
|
||||
values = invoice._save_values
|
||||
if invoice == 'posted':
|
||||
if invoice.state in ('posted', 'paid'):
|
||||
values['sii_sending_pending'] = True
|
||||
to_write.extend(([invoice], values))
|
||||
|
||||
|
|
|
@ -564,6 +564,13 @@ msgctxt "model:ir.message,text:msg_report_wrong_invoice_state"
|
|||
msgid "Invoice \"%(invoice)s\" must be posted, paid or refunded."
|
||||
msgstr "La factura \"%(invoice)s\" ha d'estar comptabilitzada, pagada o abonada."
|
||||
|
||||
msgctxt "model:ir.message,text:msg_missing_certificate"
|
||||
msgid ""
|
||||
"There isn't a certificate deffined in the account configuration for the SII."
|
||||
msgstr ""
|
||||
"No exiteix cap certificat definit a la configuració comptable per "
|
||||
"l'enviament del SII."
|
||||
|
||||
msgctxt "model:ir.model.button,string:cancel_button"
|
||||
msgid "Cancel"
|
||||
msgstr "Cancel·la"
|
||||
|
|
|
@ -566,6 +566,13 @@ msgctxt "model:ir.message,text:msg_report_wrong_invoice_state"
|
|||
msgid "Invoice \"%(invoice)s\" must be posted, paid or refunded."
|
||||
msgstr "La factura \"%(invoice)s\" debe estar contabilizada, pagada o abonada."
|
||||
|
||||
msgctxt "model:ir.message,text:msg_missing_certificate"
|
||||
msgid ""
|
||||
"There isn't a certificate deffined in the account configuration for the SII."
|
||||
msgstr ""
|
||||
"No exite ningún certificado definido en la configuración contable para el "
|
||||
"envío del SII."
|
||||
|
||||
msgctxt "model:ir.model.button,string:cancel_button"
|
||||
msgid "Cancel"
|
||||
msgstr "Cancelar"
|
||||
|
|
|
@ -38,5 +38,8 @@ If you edit them take care if you need to update again to SII</field>
|
|||
<record model="ir.message" id="msg_set_simplified_invoice">
|
||||
<field name="text">The invoice "%(invoices)s" has not VAT and SII operation key is Simplified Invoice (ticket) and Invoices without destination identification.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_missing_certificate">
|
||||
<field name="text">There isn't a certificate deffined in the account configuration for the SII.</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -5,6 +5,7 @@ depends:
|
|||
account_invoice_company_currency
|
||||
account_es
|
||||
certificate_manager
|
||||
company
|
||||
extras_depend:
|
||||
account_invoice_intercompany
|
||||
contract
|
||||
|
|
Loading…
Reference in New Issue