Upgrade to 5.1

This commit is contained in:
Raimon Esteve 2019-03-26 12:23:35 +01:00
parent 821b95f07b
commit de538106fb
9 changed files with 61 additions and 52 deletions

16
aeat.py
View File

@ -15,6 +15,8 @@ from trytond.pyson import Eval, Bool, PYSONEncoder
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.config import config
from trytond.i18n import gettext
from trytond.exceptions import UserError
from . import tools
__all__ = [
@ -349,10 +351,6 @@ class SIIReport(Workflow, ModelSQL, ModelView):
Eval('operation_type').in_(['A0', 'A1'])),
}
})
cls._error_messages.update({
'delete_cancel': ('Report "%s" must be cancelled before '
'deletion.'),
})
cls._transitions |= set((
('draft', 'confirmed'),
('draft', 'cancelled'),
@ -419,7 +417,8 @@ class SIIReport(Workflow, ModelSQL, ModelView):
# Cancel before delete
for report in reports:
if report.state != 'cancelled':
cls.raise_user_error('delete_cancel', (report.rec_name,))
raise UserError(gettext('aeat_sii.msg_delete_cancel',
report=report.rec_name))
super(SIIReport, cls).delete(reports)
@classmethod
@ -542,8 +541,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
headers, (line.invoice for line in self.lines),
mapper=mapper)
except Exception as e:
self.raise_user_error(tools.unaccent(str(e)))
raise UserError(tools.unaccent(str(e)))
self._save_response(res)
def delete_issued_invoices(self):
@ -564,7 +562,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
headers, (line.sii_header for line in self.lines),
mapper=mapper)
except Exception as e:
self.raise_user_error(tools.unaccent(str(e)))
raise UserError(tools.unaccent(str(e)))
self._save_response(res)
@ -703,7 +701,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
headers, (line.invoice for line in self.lines),
mapper=mapper)
except Exception as e:
self.raise_user_error(tools.unaccent(str(e)))
raise UserError(tools.unaccent(str(e)))
self._save_response(res)

View File

@ -143,6 +143,7 @@
</record>
<record model="ir.rule.group" id="rule_group_sii_report">
<field name="name">User in company</field>
<field name="model" search="[('model', '=', 'aeat.sii.report')]"/>
<field name="global_p" eval="True"/>
</record>
@ -152,6 +153,7 @@
</record>
<record model="ir.rule.group" id="rule_group_sii_report_line">
<field name="name">User in company</field>
<field name="model" search="[('model', '=', 'aeat.sii.report.lines')]"/>
<field name="global_p" eval="True"/>
</record>

View File

@ -10,6 +10,8 @@ from trytond.config import config
from trytond.model import fields
from trytond.pool import PoolMeta
from trytond.transaction import Transaction
from trytond.i18n import gettext
from trytond.exceptions import UserError
__all__ = ['Company']
_logger = getLogger(__name__)
@ -23,15 +25,6 @@ class Company(metaclass=PoolMeta):
private_key = fields.Function(fields.Binary('Private Key'),
'get_private_key', 'set_private_key')
@classmethod
def __setup__(cls):
super(Company, cls).__setup__()
cls._error_messages.update({
'missing_fernet_key': "Missing Fernet key configuration",
'missing_pem_cert': "Missing PEM certificate"
})
@classmethod
def get_private_key(cls, companies, name=None):
converter = bytes
@ -71,14 +64,14 @@ class Company(metaclass=PoolMeta):
fernet_key = config.get('cryptography', 'fernet_key')
if not fernet_key:
_logger.error('Missing Fernet key configuration')
cls.raise_user_error('missing_fernet_key')
raise UserError(gettext('aeat_sii.msg_missing_fernet_key'))
else:
return Fernet(fernet_key)
@contextmanager
def tmp_ssl_credentials(self):
if not self.pem_certificate:
self.raise_user_error('missing_pem_cert')
raise UserError(gettext('aeat_sii.msg_missing_pem_cert'))
with NamedTemporaryFile(suffix='.crt') as crt:
with NamedTemporaryFile(suffix='.pem') as key:
crt.write(self.pem_certificate)

View File

@ -5,6 +5,8 @@ from trytond.model import ModelView, fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval, Bool
from trytond.transaction import Transaction
from trytond.i18n import gettext
from trytond.exceptions import UserError
from sql import Null
from sql.aggregate import Max
from .aeat import (
@ -61,14 +63,6 @@ class Invoice(metaclass=PoolMeta):
'sii_excemption_key', 'sii_intracomunity_key','sii_pending_sending',
'sii_communication_type', 'sii_state', 'sii_header']
cls._check_modify_exclude += sii_fields
cls._error_messages.update({
'invoices_sii': ('The next invoices are related with SII books:\n'
'%s.\n\nIf you edit them take care if you need to update '
'again to SII'),
'invoices_sii_pending': ('The next invoices are related with SII '
'books on draft state.'),
})
cls._buttons.update({
'reset_sii_keys': {
'invisible': Bool(Eval('sii_state', None)),
@ -394,7 +388,8 @@ class Invoice(metaclass=PoolMeta):
invoices_sii += '\n%s: %s' % (invoice.number, invoice.sii_state)
if invoices_sii:
warning_name = 'invoices_sii_report_%s' % ",".join([str(x.id) for x in invoices])
cls.raise_user_warning(warning_name, 'invoices_sii', invoices_sii)
raise UserError(gettext('aeat_sii.msg_invoices_sii',
invoices=invoices_sii))
@classmethod
def draft(cls, invoices):
@ -409,7 +404,7 @@ class Invoice(metaclass=PoolMeta):
invoices_sii += '\n%s: %s' % (invoice.number, invoice.sii_state)
for record in invoice.sii_records:
if record.report.state == 'draft':
cls.raise_user_error('invoices_sii_pending')
raise UserError(gettext('aeat_sii.invoices_sii_pending'))
if invoices_sii:
warning_name = 'invoices_sii_report'

View File

@ -17,6 +17,8 @@ from trytond.wizard import Wizard
from trytond.wizard import StateView
from trytond.wizard import StateTransition
from trytond.wizard import Button
from trytond.i18n import gettext
from trytond.exceptions import UserError
__all__ = [
'LoadPKCS12',
@ -36,14 +38,6 @@ class LoadPKCS12Start(ModelView):
class LoadPKCS12(Wizard):
"Load PKCS12"
__name__ = "aeat.sii.load_pkcs12"
@classmethod
def __setup__(cls):
super(LoadPKCS12, cls).__setup__()
cls._error_messages.update({
'error_loading_pkcs12': 'Unable to load PKCS12: %s',
})
start = StateView(
'aeat.sii.load_pkcs12.start',
'aeat_sii.load_pkcs12_start_view', [
@ -72,5 +66,6 @@ class LoadPKCS12(Wizard):
_logger.debug('Cryptographic error loading pkcs12 %s', e)
errors = e.args[0]
message = ', '.join(error[2] for error in errors)
self.raise_user_error('error_loading_pkcs12', (message,))
raise UserError(gettext('aeat_sii.error_loading_pkcs12',
message=message))
return 'end'

View File

@ -10,22 +10,22 @@ msgstr ""
msgctxt "error:account.invoice:"
msgid ""
"The next invoices are related with SII books:\n"
"%s.\n"
"(invoices)%s.\n"
"\n"
"If you edit them take care if you need to update again to SII"
msgstr ""
"Las facturas están relacionadas con los libros del SII:\n"
"%s.\n"
"%(invoices)s.\n"
"\n"
"Si les edites vigila que no les hagis de tornar a pujar al SII"
msgctxt "error:aeat.sii.load_pkcs12:"
msgid "Unable to load PKCS12: %s"
msgstr "No se ha podido cargar PKCS12: %s"
msgid "Unable to load PKCS12: %(message)s"
msgstr "No se ha podido cargar PKCS12: %(message)s"
msgctxt "error:aeat.sii.report:"
msgid "Report \"%s\" must be cancelled before deletion."
msgstr "Debe cancelar el informe \\\"%s\\\" antes de borrarla."
msgid "Report \"%(report)s\" must be cancelled before deletion."
msgstr "Debe cancelar el informe \"%(report)s\" antes de borrarla."
msgctxt "error:company.company:"
msgid "Missing Fernet key configuration"

View File

@ -10,22 +10,22 @@ msgstr ""
msgctxt "error:account.invoice:"
msgid ""
"The next invoices are related with SII books:\n"
"%s.\n"
"%(invoices)s.\n"
"\n"
"If you edit them take care if you need to update again to SII"
msgstr ""
"Las facturas están relacionadas con los libros del SII:\n"
"%s.\n"
"%(invoices)s.\n"
"\n"
"Si las editas vigila que no cesiten subirse nuevamente al SII"
msgctxt "error:aeat.sii.load_pkcs12:"
msgid "Unable to load PKCS12: %s"
msgstr "No se ha podido cargar PKCS12: %s"
msgid "Unable to load PKCS12: %(message)s"
msgstr "No se ha podido cargar PKCS12: %(message)s"
msgctxt "error:aeat.sii.report:"
msgid "Report \"%s\" must be cancelled before deletion."
msgstr "Debe cancelar el informe \\\"%s\\\" antes de borrarla."
msgid "Report \"%(report)s\" must be cancelled before deletion."
msgstr "Debe cancelar el informe \"%(report)s\" antes de borrarla."
msgctxt "error:company.company:"
msgid "Missing Fernet key configuration"

25
message.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data group="1">
<record model="ir.message" id="msg_missing_fernet_key">
<field name="text">Missing Fernet key configuration</field>
</record>
<record model="ir.message" id="msg_missing_pem_cert">
<field name="text">Missing PEM certificate</field>
</record>
<record model="ir.message" id="msg_delete_cancel">
<field name="text">Report "%(report)s" must be cancelled before deletion.</field>
</record>
<record model="ir.message" id="msg_invoices_sii">
<field name="text">The next invoices are related with SII books:\n%(invoices)s.\n\nIf you edit them take care if you need to update again to SII</field>
</record>
<record model="ir.message" id="msg_invoices_sii_pending">
<field name="text">The next invoices are related with SII books on draft state.</field>
</record>
<record model="ir.message" id="msg_error_loading_pkcs12">
<field name="text">Unable to load PKCS12: %(message)s</field>
</record>
</data>
</tryton>

View File

@ -1,5 +1,5 @@
[tryton]
version=4.9.0
version=5.1.0
depends:
account_invoice
account_invoice_company_currency
@ -17,3 +17,4 @@ xml:
company.xml
load_pkcs12.xml
sii.xml
message.xml