first commit

This commit is contained in:
root
2026-03-14 09:42:12 +00:00
commit 0adbd20c2c
10991 changed files with 1646955 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

View File

@@ -0,0 +1,107 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from io import BytesIO
import ofxparse
from trytond.i18n import gettext
from trytond.modules.account_statement.exceptions import ImportStatementError
from trytond.pool import Pool, PoolMeta
class StatementImportStart(metaclass=PoolMeta):
__name__ = 'account.statement.import.start'
@classmethod
def __setup__(cls):
super().__setup__()
cls.file_format.selection.append(('ofx', "OFX"))
class StatementImport(metaclass=PoolMeta):
__name__ = 'account.statement.import'
def parse_ofx(self):
file_ = BytesIO(self.start.file_)
ofx = ofxparse.OfxParser.parse(file_)
for account in ofx.accounts:
statement = self.ofx_statement(ofx, account)
origins = []
for transaction in account.statement.transactions:
origins.extend(self.ofx_origin(account, transaction))
statement.origins = origins
yield statement
def ofx_statement(self, ofx, ofx_account):
pool = Pool()
Statement = pool.get('account.statement')
Journal = pool.get('account.statement.journal')
statement = Statement()
statement.name = ofx.trnuid
statement.company = self.start.company
statement.journal = Journal.get_by_bank_account(
statement.company, ofx_account.number, currency=ofx_account.curdef)
if not statement.journal:
raise ImportStatementError(
gettext('account_statement.msg_import_no_journal',
account=ofx_account.number))
if not isinstance(ofx_account.statement, ofxparse.Statement):
raise ImportStatementError(
gettext('account_statement_ofx.msg_import_no_statement'))
try:
statement.date = ofx_account.statement.end_date.date()
except AttributeError:
pass
total_amount = sum(
t.amount for t in ofx_account.statement.transactions)
statement.total_amount = total_amount
if (ofx_account.statement.end_date
== ofx_account.statement.balance_date):
statement.start_balance = (
ofx_account.statement.balance - total_amount)
statement.end_balance = ofx_account.statement.balance
statement.number_of_lines = len(ofx_account.statement.transactions)
return statement
def ofx_origin(self, ofx_account, transaction):
pool = Pool()
Origin = pool.get('account.statement.origin')
origin = Origin()
origin.number = transaction.id
origin.date = transaction.date.date()
origin.amount = transaction.amount
origin.party = self.ofx_party(ofx_account, transaction)
if origin.party:
origin.description = transaction.memo
else:
origin.description = '|'.join(
filter(None, [transaction.payee, transaction.memo]))
origin.information = self.ofx_information(ofx_account, transaction)
return [origin]
def ofx_party(self, ofx_account, transaction):
pool = Pool()
Party = pool.get('party.party')
if not transaction.payee:
return
parties = Party.search([('rec_name', 'ilike', transaction.payee)])
if len(parties) == 1:
party, = parties
return party
def ofx_information(self, ofx_account, transaction):
information = {}
for name in [
'checknum',
'mcc',
'sic',
'type',
]:
value = getattr(transaction, name)
if value:
information['ofx_' + name] = value
return information

View File

@@ -0,0 +1,27 @@
<?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>
<record model="account.statement.origin.information" id="information_checknum">
<field name="name">ofx_checknum</field>
<field name="string">Check Number</field>
<field name="type_">char</field>
</record>
<record model="account.statement.origin.information" id="information_mcc">
<field name="name">ofx_mcc</field>
<field name="string">Merchant Category Code (MCC)</field>
<field name="type_">char</field>
</record>
<record model="account.statement.origin.information" id="information_sic">
<field name="name">ofx_sic</field>
<field name="string">Standard Industry Code (SIC)</field>
<field name="type_">char</field>
</record>
<record model="account.statement.origin.information" id="information_type">
<field name="name">ofx_type</field>
<field name="string">Type</field>
<field name="type_">char</field>
</record>
</data>
</tryton>

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Número verificació"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Códi Categoria Comerciant (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Codi estàndard industria (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Tipus"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr "El fitxer OFX no és un extracte."

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Scheck-Nummer"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Code der Händler-Kategorie (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Branchen-Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Typ"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr "Die OFX-Datei ist kein Auszug."

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Numero verificación"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Código categoría comerciante (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Código estándar Industria (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Tipo"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr "El fichero OFX no es un extracto."

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr ""
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr ""
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr ""
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr ""
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Tšeki number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Kaupmehe kategooria kood (MC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Tööstusharu standardkood (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Tüüp"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr "OFX fail ei ole kinnitus."

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "بررسی شماره"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "کد دسته بندی تاجر (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "کد استاندارد صنعت (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "نوع"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr "پرونده OFX یک اظهارنامه نیست."

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Numéro de chèque"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr "Le fichier OFX n'est pas un extrait."

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr ""
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr ""
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr ""
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr ""
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Cheque nummer"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr "Het OFX-bestand is geen uittreksel."

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Număr Verificare"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Categorie de Comerciant (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Cod Industrie Independenta (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Tip"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr "Fișierul OFX nu este un extras de cont."

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr ""
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr ""
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr ""
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr ""
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt ""
"model:account.statement.origin.information,string:information_checknum"
msgid "Check Number"
msgstr "Check Number"
msgctxt "model:account.statement.origin.information,string:information_mcc"
msgid "Merchant Category Code (MCC)"
msgstr "Merchant Category Code (MCC)"
msgctxt "model:account.statement.origin.information,string:information_sic"
msgid "Standard Industry Code (SIC)"
msgstr "Standard Industry Code (SIC)"
msgctxt "model:account.statement.origin.information,string:information_type"
msgid "Type"
msgstr "Type"
msgctxt "model:ir.message,text:msg_import_no_statement"
msgid "The OFX file is not a statement."
msgstr ""

View File

@@ -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 grouped="1">
<record model="ir.message" id="msg_import_no_statement">
<field name="text">The OFX file is not a statement.</field>
</record>
</data>
</tryton>

View File

@@ -0,0 +1,61 @@
OFXHEADER:100
DATA:OFXSGML
VERSION:102
SECURITY:NONE
ENCODING:USASCII
CHARSET:1252
COMPRESSION:NONE
OLDFILEUID:NONE
NEWFILEUID:NONE
<OFX>
<SIGNONMSGSRSV1>
<SONRS>
<STATUS>
<CODE>0
<SEVERITY>INFO
</STATUS>
<DTSERVER>20180222052809
<LANGUAGE>FRA
<DTPROFUP>20180222052809
<DTACCTUP>20180222052809
</SONRS>
</SIGNONMSGSRSV1>
<BANKMSGSRSV1>
<STMTTRNRS>
<TRNUID>01234567890
<STATUS>
<CODE>0
<SEVERITY>INFO
</STATUS>
<STMTRS>
<CURDEF>EUR
<BANKACCTFROM>
<BANKID>12345</BANKID>
<BRANCHID>00000</BRANCHID>
<ACCTID>01234567890</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
<DTSTART>20180212
<DTEND>20180222
<STMTTRN>
<TRNTYPE>CREDIT
<DTPOSTED>20180221
<TRNAMT>+100.00
<FITID>0001
<NAME>MICHAEL SCOTT PAPER COMPANY
<MEMO>COMMUNICATION
</STMTTRN>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>500.00
<DTASOF>20180222
</LEDGERBAL>
<AVAILBAL>
<BALAMT>500.00
<DTASOF>20180222
</AVAILBAL>
</STMTRS>
</STMTTRNRS>
</BANKMSGSRSV1>
</OFX>

View File

@@ -0,0 +1,2 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

View File

@@ -0,0 +1,107 @@
==============================
Account Statement OFX Scenario
==============================
Imports::
>>> from functools import partial
>>> from proteus import Model, Wizard
>>> from trytond.modules.account.tests.tools import create_chart, get_accounts
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules, assertEqual
>>> from trytond.tools import file_open
Activate modules::
>>> config = activate_modules(
... 'account_statement_ofx',
... partial(create_company, currency='EUR'), create_chart)
Get company::
>>> company = get_company()
Get accounts::
>>> accounts = get_accounts()
>>> cash = accounts['cash']
Create parties::
>>> Party = Model.get('party.party')
>>> michael_scott_paper = Party(name="Michael Scott Paper Company")
>>> michael_scott_paper.save()
>>> bank_party = Party(name="Bank")
>>> bank_party.save()
Create Bank Account::
>>> Bank = Model.get('bank')
>>> BankAccount = Model.get('bank.account')
>>> bank = Bank()
>>> bank.party = bank_party
>>> bank.save()
>>> bank_account = BankAccount()
>>> bank_account.bank = bank
>>> bank_account.owners.append(Party(company.party.id))
>>> bank_account.currency = company.currency
>>> bank_account_number = bank_account.numbers.new()
>>> bank_account_number.type = 'other'
>>> bank_account_number.number = '01234567890'
>>> bank_account.save()
Create Statement Journal::
>>> AccountJournal = Model.get('account.journal')
>>> StatementJournal = Model.get('account.statement.journal')
>>> account_journal, = AccountJournal.find([('code', '=', 'STA')], limit=1)
>>> journal = StatementJournal(name="Bank",
... journal=account_journal,
... account=cash,
... bank_account=bank_account,
... validation='amount',
... )
>>> journal.save()
Import OFX file::
>>> statement_import = Wizard('account.statement.import')
>>> with file_open('account_statement_ofx/tests/OFX.txt', mode='rb') as fp:
... ofx = fp.read()
>>> statement_import.form.file_ = ofx
>>> statement_import.form.file_format = 'ofx'
>>> statement_import.execute('import_')
Check Statement::
>>> Statement = Model.get('account.statement')
>>> statement, = Statement.find([])
>>> statement.name
'01234567890'
>>> statement.date
datetime.date(2018, 2, 22)
>>> statement.total_amount
Decimal('100.00')
>>> statement.number_of_lines
1
>>> statement.start_balance
Decimal('400.00')
>>> statement.end_balance
Decimal('500.00')
>>> len(statement.origins)
1
>>> origin, = statement.origins
>>> origin.number
'0001'
>>> origin.date
datetime.date(2018, 2, 21)
>>> origin.amount
Decimal('100.00')
>>> assertEqual(origin.party, michael_scott_paper)
>>> origin.description
'COMMUNICATION'
>>> origin.information['ofx_type']
'credit'

View File

@@ -0,0 +1,12 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.tests.test_tryton import ModuleTestCase
class AccountStatementOFXTestCase(ModuleTestCase):
'Test Account Statement OFX module'
module = 'account_statement_ofx'
del ModuleTestCase

View File

@@ -0,0 +1,8 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.tests.test_tryton import load_doc_tests
def load_tests(*args, **kwargs):
return load_doc_tests(__name__, __file__, *args, **kwargs)

View File

@@ -0,0 +1,16 @@
[tryton]
version=7.8.0
depends:
account_statement
bank
ir
party
xml:
account.xml
message.xml
[register]
model:
account.StatementImportStart
wizard:
account.StatementImport