changeset 4f03ed6915e0 in modules/account_statement_ofx:default
details:
https://hg.tryton.org/modules/account_statement_ofx?cmd=changeset;node=4f03ed6915e0
description:
Add ir.message and use custom exceptions
issue3672
diffstat:
account.py | 36 +++++++++++++-----------------------
message.xml | 10 ++++++++++
tryton.cfg | 1 +
3 files changed, 24 insertions(+), 23 deletions(-)
diffs (86 lines):
diff -r 33b65a9375ba -r 4f03ed6915e0 account.py
--- a/account.py Mon Oct 01 13:22:33 2018 +0200
+++ b/account.py Sat Dec 29 14:20:29 2018 +0100
@@ -4,8 +4,11 @@
import ofxparse
+from trytond.i18n import gettext
from trytond.pool import PoolMeta, Pool
+from trytond.modules.account_statement.exceptions import ImportStatementError
+
class StatementImportStart(metaclass=PoolMeta):
__name__ = 'account.statement.import.start'
@@ -19,20 +22,6 @@
class StatementImport(metaclass=PoolMeta):
__name__ = 'account.statement.import'
- @classmethod
- def __setup__(cls):
- super(StatementImport, cls).__setup__()
- cls._error_messages.update({
- 'ofx_no_journal': (
- 'No journal found for the bank account "%(account)s".'),
- 'ofx_wrong_currency': (
- 'The journal "%(journal)s" must have '
- 'the currency "%(ofx_currency)s" instead of '
- '"%(currency)s".'),
- 'ofx_not_statement': (
- "The OFX file is not a statement."),
- })
-
def parse_ofx(self):
file_ = BytesIO(self.start.file_)
ofx = ofxparse.OfxParser.parse(file_)
@@ -56,17 +45,18 @@
statement.journal = Journal.get_by_bank_account(
statement.company, ofx_account.number)
if not statement.journal:
- self.raise_user_error('ofx_no_journal', {
- 'account': ofx_account.number,
- })
+ raise ImportStatementError(
+ gettext('account_statement.msg_import_no_journal',
+ account=ofx_account.number))
if statement.journal.currency.code != ofx_account.curdef:
- self.raise_user_error('ofx_wrong_currency', {
- 'journal': statement.journal.rec_name,
- 'currency': statement.journal.currency.rec_name,
- 'ofx_currency': ofx_account.curdef,
- })
+ raise ImportStatementError(
+ gettext('account_statement.msg_import_wrong_currency',
+ journal=statement.journal.rec_name,
+ currency=statement.journal.currency.rec_name,
+ journal_currency=ofx_account.curdef))
if not isinstance(ofx_account.statement, ofxparse.Statement):
- self.raise_user_error('ofx_not_statement')
+ raise ImportStatementError(
+ gettext('account_statement_ofx.msg_import_no_statement'))
statement.date = ofx_account.statement.balance_date.date()
statement.total_amount = ofx_account.statement.balance
statement.number_of_lines = len(ofx_account.statement.transactions)
diff -r 33b65a9375ba -r 4f03ed6915e0 message.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml Sat Dec 29 14:20:29 2018 +0100
@@ -0,0 +1,10 @@
+<?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_import_no_statement">
+ <field name="text">The OFX file is not a statement.</field>
+ </record>
+ </data>
+</tryton>
diff -r 33b65a9375ba -r 4f03ed6915e0 tryton.cfg
--- a/tryton.cfg Mon Oct 01 13:22:33 2018 +0200
+++ b/tryton.cfg Sat Dec 29 14:20:29 2018 +0100
@@ -7,3 +7,4 @@
party
xml:
account.xml
+ message.xml