party: qif import
This commit is contained in:
parent
0287452fe8
commit
50cbb2cc37
5 changed files with 66 additions and 0 deletions
|
@ -14,6 +14,10 @@ msgctxt "model:ir.message,text:msg_wiz_transactions_found"
|
||||||
msgid "The following transactionen are now imported:\nBalance: %(balance)s\nNumber of transactions: %(quantity)s"
|
msgid "The following transactionen are now imported:\nBalance: %(balance)s\nNumber of transactions: %(quantity)s"
|
||||||
msgstr "Die folgenden Transaktionen werden nun importiert:\nSaldo: %(balance)s\nAnzahl Transactionen: %(quantity)s"
|
msgstr "Die folgenden Transaktionen werden nun importiert:\nSaldo: %(balance)s\nAnzahl Transactionen: %(quantity)s"
|
||||||
|
|
||||||
|
msgctxt "model:ir.message,text:msg_wiz_parties_found"
|
||||||
|
msgid "The following %(numparties)s parties are now imported:"
|
||||||
|
msgstr "Die folgenden %(numparties)s Parteien werden nun importiert:"
|
||||||
|
|
||||||
msgctxt "model:ir.message,name:msg_wiz_no_categories"
|
msgctxt "model:ir.message,name:msg_wiz_no_categories"
|
||||||
msgid "No categories were found in the file."
|
msgid "No categories were found in the file."
|
||||||
msgstr "In der Datei wurden keine Kategorien gefunden."
|
msgstr "In der Datei wurden keine Kategorien gefunden."
|
||||||
|
|
|
@ -14,6 +14,9 @@ full copyright notices and license terms. -->
|
||||||
<record model="ir.message" id="msg_wiz_no_bank">
|
<record model="ir.message" id="msg_wiz_no_bank">
|
||||||
<field name="text">No transactions were found in the file.</field>
|
<field name="text">No transactions were found in the file.</field>
|
||||||
</record>
|
</record>
|
||||||
|
<record model="ir.message" id="msg_wiz_parties_found">
|
||||||
|
<field name="text">The following %(numparties)s parties are now imported:</field>
|
||||||
|
</record>
|
||||||
<record model="ir.message" id="msg_wiz_transactions_found">
|
<record model="ir.message" id="msg_wiz_transactions_found">
|
||||||
<field name="text">The following transactionen are now imported:\nBalance: %(balance)s\nNumber of transactions: %(quantity)s</field>
|
<field name="text">The following transactionen are now imported:\nBalance: %(balance)s\nNumber of transactions: %(quantity)s</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
|
@ -148,6 +148,21 @@ class ImportQifWizard(Wizard):
|
||||||
self.showinfo.allowimport = True
|
self.showinfo.allowimport = True
|
||||||
else :
|
else :
|
||||||
self.showinfo.info = gettext('cashbook_dataexchange.msg_wiz_no_categories')
|
self.showinfo.info = gettext('cashbook_dataexchange.msg_wiz_no_categories')
|
||||||
|
elif model == 'party.party':
|
||||||
|
# read file content, extract parties
|
||||||
|
qif_content = QifTool.split_by_type(file_content)
|
||||||
|
if 'Bank' in qif_content.keys():
|
||||||
|
to_create = QifTool.convert_parties_to_create(
|
||||||
|
QifTool.qif_read_transactions(qif_content['Bank'])
|
||||||
|
)
|
||||||
|
self.showinfo.info = gettext(
|
||||||
|
'cashbook_dataexchange.msg_wiz_parties_found',
|
||||||
|
numparties = len(to_create),
|
||||||
|
) + '\n\n' + '\n'.join([x['name'] for x in to_create])
|
||||||
|
if len(to_create) > 0:
|
||||||
|
self.showinfo.allowimport = True
|
||||||
|
else :
|
||||||
|
self.showinfo.info = gettext('cashbook_dataexchange.msg_wiz_no_bank')
|
||||||
elif model == 'cashbook.book':
|
elif model == 'cashbook.book':
|
||||||
# read file content, extract categories
|
# read file content, extract categories
|
||||||
qif_content = QifTool.split_by_type(file_content)
|
qif_content = QifTool.split_by_type(file_content)
|
||||||
|
@ -188,6 +203,8 @@ class ImportQifWizard(Wizard):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Category = pool.get('cashbook.category')
|
Category = pool.get('cashbook.category')
|
||||||
Book = pool.get('cashbook.book')
|
Book = pool.get('cashbook.book')
|
||||||
|
Party = pool.get('party.party')
|
||||||
|
QifTool = pool.get('cashbook_dataexchange.qiftool')
|
||||||
|
|
||||||
model = Transaction().context.get('active_model', '')
|
model = Transaction().context.get('active_model', '')
|
||||||
file_content = None
|
file_content = None
|
||||||
|
@ -200,6 +217,13 @@ class ImportQifWizard(Wizard):
|
||||||
elif model == 'cashbook.book':
|
elif model == 'cashbook.book':
|
||||||
if file_content:
|
if file_content:
|
||||||
Book.create_from_qif(self.showinfo.book, file_content)
|
Book.create_from_qif(self.showinfo.book, file_content)
|
||||||
|
elif model == 'party.party':
|
||||||
|
qif_content = QifTool.split_by_type(file_content)
|
||||||
|
if 'Bank' in qif_content.keys():
|
||||||
|
to_create = QifTool.convert_parties_to_create(
|
||||||
|
QifTool.qif_read_transactions(qif_content['Bank'])
|
||||||
|
)
|
||||||
|
Party.create(to_create)
|
||||||
return 'end'
|
return 'end'
|
||||||
|
|
||||||
# end ImportQifWizard
|
# end ImportQifWizard
|
||||||
|
|
|
@ -36,5 +36,12 @@ full copyright notices and license terms. -->
|
||||||
<field name="action" ref="act_import_qif_wizard"/>
|
<field name="action" ref="act_import_qif_wizard"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<!-- import parties -->
|
||||||
|
<record model="ir.action.keyword" id="act_import_qif_wizard-party-keyword">
|
||||||
|
<field name="keyword">form_action</field>
|
||||||
|
<field name="model">party.party,-1</field>
|
||||||
|
<field name="action" ref="act_import_qif_wizard"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</tryton>
|
</tryton>
|
||||||
|
|
28
qiftool.py
28
qiftool.py
|
@ -149,6 +149,34 @@ class QifTool(Model):
|
||||||
cat_id = categories[0].id
|
cat_id = categories[0].id
|
||||||
return (cat_id, msg_txt)
|
return (cat_id, msg_txt)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def convert_parties_to_create(cls, transactions):
|
||||||
|
""" extract party from transaction, check if exist,
|
||||||
|
create 'to_create'
|
||||||
|
"""
|
||||||
|
Party = Pool().get('party.party')
|
||||||
|
|
||||||
|
to_create = []
|
||||||
|
party_cache = []
|
||||||
|
for transaction in transactions:
|
||||||
|
if 'party' in transaction.keys():
|
||||||
|
if transaction['party'] in party_cache:
|
||||||
|
continue
|
||||||
|
|
||||||
|
party_cache.append(transaction['party'])
|
||||||
|
if Party.search_count([
|
||||||
|
('rec_name', 'ilike', '%%%(pname)s%%' % {
|
||||||
|
'pname': transaction['party'],
|
||||||
|
})
|
||||||
|
]) == 0:
|
||||||
|
to_create.append({
|
||||||
|
'name': transaction['party'],
|
||||||
|
'addresses': [('create', [{
|
||||||
|
'street': transaction.get('address', None),
|
||||||
|
}])],
|
||||||
|
})
|
||||||
|
return to_create
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def convert_transactions_to_create(cls, transactions, split2edit=True):
|
def convert_transactions_to_create(cls, transactions, split2edit=True):
|
||||||
""" convert read transactions to create-command
|
""" convert read transactions to create-command
|
||||||
|
|
Loading…
Reference in a new issue