Alexis de Lattre
6 years ago
10 changed files with 31 additions and 125 deletions
-
5account_bank_statement_import_save_file/__init__.py
-
7account_bank_statement_import_save_file/__manifest__.py
-
76account_bank_statement_import_save_file/hooks.py
-
4account_bank_statement_import_save_file/models/__init__.py
-
13account_bank_statement_import_save_file/models/account_bank_statement.py
-
26account_bank_statement_import_save_file/models/account_bank_statement_import.py
-
3account_bank_statement_import_save_file/readme/CONTRIBUTORS.rst
-
1account_bank_statement_import_save_file/readme/DESCRIPTION.rst
-
1account_bank_statement_import_save_file/readme/USAGE.rst
-
18account_bank_statement_import_save_file/views/account_bank_statement.xml
@ -1,6 +1 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2015 Therp BV (<http://therp.nl>). |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import models |
|||
from .hooks import _post_init_hook |
@ -1,76 +0,0 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2015 Therp BV (<http://therp.nl>). |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
|
|||
def _post_init_hook(cr, pool): |
|||
# if we install this module on a database with remains of account_banking, |
|||
# migrate account.banking.imported.file |
|||
cr.execute( |
|||
"select 1 from pg_catalog.pg_class c " |
|||
"join pg_catalog.pg_namespace n ON n.oid = c.relnamespace " |
|||
"where n.nspname = 'public' and " |
|||
"c.relname = 'account_banking_imported_file' and " |
|||
"c.relkind = 'r'") |
|||
if cr.fetchall(): |
|||
_post_init_hook_migrate_account_banking_imported_file(cr, pool) |
|||
|
|||
|
|||
def _post_init_hook_migrate_account_banking_imported_file(cr, pool): |
|||
# create attachments |
|||
cr.execute( |
|||
"""insert into ir_attachment |
|||
( |
|||
name, create_uid, create_date, datas_fname, description, |
|||
company_id, res_model, type, |
|||
res_id |
|||
) |
|||
select |
|||
coalesce(file_name, '<unknown>'), user_id, date, file_name, log, |
|||
company_id, 'account.bank.statement', 'binary', |
|||
( |
|||
select id from account_bank_statement |
|||
where banking_id=f.id |
|||
limit 1 |
|||
) |
|||
from account_banking_imported_file f |
|||
returning id""") |
|||
|
|||
attachment_ids = [attachment_id for attachment_id, in cr.fetchall()] |
|||
|
|||
if not attachment_ids: |
|||
return |
|||
|
|||
# assign respective attachment to all statements pointing to an imported |
|||
# banking file |
|||
cr.execute( |
|||
"""with banking_id2attachment as ( |
|||
select distinct b.id banking_id, a.id attachment_id |
|||
from account_banking_imported_file b |
|||
join account_bank_statement s |
|||
on s.banking_id=b.id |
|||
join ir_attachment a |
|||
on a.id in %s and s.id=a.res_id |
|||
) |
|||
update account_bank_statement s |
|||
set import_file=b2a.attachment_id |
|||
from banking_id2attachment b2a |
|||
where b2a.banking_id=s.banking_id""", |
|||
(tuple(attachment_ids),) |
|||
) |
|||
|
|||
# now we just have to write the file's content via the orm |
|||
# (to support non-db storage) |
|||
cr.execute( |
|||
"""select distinct a.id, b.file |
|||
from account_banking_imported_file b |
|||
join account_bank_statement s |
|||
on s.banking_id=b.id |
|||
join ir_attachment a |
|||
on a.id in %s and s.id=a.res_id""", |
|||
(tuple(attachment_ids),) |
|||
) |
|||
for attachment_id, content in cr.fetchall(): |
|||
pool['ir.attachment'].sudo().write( |
|||
[attachment_id], |
|||
{'datas': str(content)}) |
@ -1,6 +1,2 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2015 Therp BV (<http://therp.nl>). |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import account_bank_statement |
|||
from . import account_bank_statement_import |
@ -0,0 +1,3 @@ |
|||
* Holger Brunn <hbrunn@therp.nl> |
|||
* Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com> |
|||
* Alexis de Lattre <alexis.delattre@akretion.com> |
@ -0,0 +1 @@ |
|||
This module saves the original file of an imported bank statement for further reference/processing and maintains a link between bank statements and those imported files. |
@ -0,0 +1 @@ |
|||
On a successful import, the form view of the bank statement will have an additional tab *Imported File* which contains the original file. |
Write
Preview
Loading…
Cancel
Save
Reference in new issue