Browse Source
Merge pull request #21 from hbrunn/8.0-migrate_from_7.0_therp
Merge pull request #21 from hbrunn/8.0-migrate_from_7.0_therp
[ADD] migration scriptpull/35/head
Pedro M. Baeza
9 years ago
12 changed files with 457 additions and 0 deletions
-
33account_bank_statement_import/migrations/8.0.1.0/post-migrate.py
-
35account_bank_statement_import_save_file/README.rst
-
22account_bank_statement_import_save_file/__init__.py
-
45account_bank_statement_import_save_file/__openerp__.py
-
92account_bank_statement_import_save_file/hooks.py
-
22account_bank_statement_import_save_file/models/__init__.py
-
34account_bank_statement_import_save_file/models/account_bank_statement.py
-
50account_bank_statement_import_save_file/models/account_bank_statement_import.py
-
BINaccount_bank_statement_import_save_file/static/description/icon.png
-
21account_bank_statement_import_save_file/tests/__init__.py
-
78account_bank_statement_import_save_file/tests/test_save_file.py
-
25account_bank_statement_import_save_file/views/account_bank_statement.xml
@ -0,0 +1,33 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
|
|||
def migrate(cr, version): |
|||
# if we end up here, we migrate from 7.0's account_banking |
|||
# set transaction ids, taking care to enforce uniqueness |
|||
cr.execute( |
|||
"""update account_bank_statement_line l set unique_import_id=l1.trans |
|||
from ( |
|||
select distinct |
|||
first_value(id) over (partition by trans) id, trans |
|||
from account_bank_statement_line |
|||
) l1 |
|||
where l.id=l1.id""") |
@ -0,0 +1,35 @@ |
|||
Save imported statement file |
|||
============================ |
|||
|
|||
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. |
|||
|
|||
Usage |
|||
===== |
|||
|
|||
On a successful import, the generated statement(s) link to an attachment containing the original file. |
|||
|
|||
Credits |
|||
======= |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* Holger Brunn <hbrunn@therp.nl> |
|||
|
|||
Icon |
|||
---- |
|||
|
|||
* https://commons.wikimedia.org/wiki/File:Paper_clip_font_awesome.svg |
|||
|
|||
Maintainer |
|||
---------- |
|||
|
|||
.. image:: http://odoo-community.org/logo.png |
|||
:alt: Odoo Community Association |
|||
:target: http://odoo-community.org |
|||
|
|||
This module is maintained by the OCA. |
|||
|
|||
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. |
|||
|
|||
To contribute to this module, please visit http://odoo-community.org. |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from . import models |
|||
from .hooks import _post_init_hook |
@ -0,0 +1,45 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
{ |
|||
"name": "Save imported bank statements", |
|||
"version": "1.0", |
|||
"author": "Therp BV", |
|||
"license": "AGPL-3", |
|||
"category": "Accounting & Finance", |
|||
"summary": "Keep imported bank statements as raw data", |
|||
"depends": [ |
|||
'account_bank_statement_import', |
|||
], |
|||
"data": [ |
|||
"views/account_bank_statement.xml", |
|||
], |
|||
"qweb": [ |
|||
], |
|||
"test": [ |
|||
], |
|||
"post_init_hook": '_post_init_hook', |
|||
"auto_install": False, |
|||
"installable": True, |
|||
"application": False, |
|||
"external_dependencies": { |
|||
'python': [], |
|||
}, |
|||
} |
@ -0,0 +1,92 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from openerp import SUPERUSER_ID |
|||
|
|||
|
|||
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()] |
|||
|
|||
# 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'].write( |
|||
cr, SUPERUSER_ID, |
|||
[attachment_id], |
|||
{'datas': str(content)}) |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from . import account_bank_statement |
|||
from . import account_bank_statement_import |
@ -0,0 +1,34 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2015 Therp BV (<http://therp.nl>). |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from openerp import models, fields |
|||
|
|||
|
|||
class AccountBankStatement(models.Model): |
|||
_inherit = 'account.bank.statement' |
|||
|
|||
import_file = fields.Many2one( |
|||
'ir.attachment', 'Import file', readonly=True) |
|||
import_date = fields.Datetime( |
|||
related=['import_file', 'create_date'], readonly=True) |
|||
import_user = fields.Many2one( |
|||
related=['import_file', 'create_uid'], readonly=True) |
|||
import_log = fields.Text( |
|||
related=['import_file', 'description'], readonly=True) |
@ -0,0 +1,50 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2015 Therp BV (<http://therp.nl>). |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
import base64 |
|||
from openerp import models, api |
|||
|
|||
|
|||
class AccountBankStatementImport(models.TransientModel): |
|||
_inherit = 'account.bank.statement.import' |
|||
|
|||
@api.model |
|||
def _import_file(self, data_file): |
|||
(statement_ids, notifications) = \ |
|||
super(AccountBankStatementImport, self)._import_file(data_file) |
|||
if statement_ids: |
|||
self.env['account.bank.statement'].browse(statement_ids).write({ |
|||
'import_file': self.env['ir.attachment'].create( |
|||
self._create_import_file_attachment_data( |
|||
data_file, statement_ids[0], notifications)).id, |
|||
}) |
|||
return (statement_ids, notifications) |
|||
|
|||
@api.model |
|||
def _create_import_file_attachment_data(self, data_file, statement_id, |
|||
notifications): |
|||
return { |
|||
'name': '<unknown>', |
|||
'res_model': 'account.bank.statement', |
|||
'res_id': statement_id, |
|||
'type': 'binary', |
|||
'datas': base64.b64encode(data_file), |
|||
'description': notifications, |
|||
} |
After Width: 128 | Height: 128 | Size: 7.1 KiB |
@ -0,0 +1,21 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from . import test_save_file |
@ -0,0 +1,78 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
import base64 |
|||
from openerp import api, models |
|||
from openerp.tests.common import TransactionCase |
|||
|
|||
|
|||
acc_number = 'BE1234567890' |
|||
|
|||
|
|||
class HelloWorldParser(models.TransientModel): |
|||
_inherit = 'account.bank.statement.import' |
|||
|
|||
@api.model |
|||
def _parse_file(self, data_file): |
|||
return ( |
|||
'EUR', |
|||
acc_number, |
|||
[{ |
|||
'name': '000000123', |
|||
'date': '2013-06-26', |
|||
'transactions': [{ |
|||
'name': 'KBC-INVESTERINGSKREDIET 787-5562831-01', |
|||
'date': '2013-06-26', |
|||
'amount': 42, |
|||
'unique_import_id': 'hello', |
|||
}], |
|||
}], |
|||
) |
|||
|
|||
|
|||
class TestSaveFile(TransactionCase): |
|||
def test_SaveFile(self): |
|||
HelloWorldParser._build_model(self.registry, self.cr) |
|||
import_wizard = self.env['account.bank.statement.import'] |
|||
import_wizard._prepare_setup() |
|||
import_wizard._setup_base(False) |
|||
import_wizard._setup_fields() |
|||
import_wizard._setup_complete() |
|||
import_wizard._auto_init() |
|||
journal_id = self.env['res.partner.bank'].search([ |
|||
('acc_number', '=', acc_number), |
|||
]).journal_id.id |
|||
if not journal_id: |
|||
account = import_wizard._create_bank_account(acc_number) |
|||
journal_id = self.env['account.journal']\ |
|||
.search([ |
|||
'|', |
|||
('currency.name', '=', 'EUR'), |
|||
('currency', '=', False) |
|||
]).ids[0] |
|||
account.journal_id = journal_id |
|||
action = import_wizard.with_context(journal_id=journal_id)\ |
|||
.create({'data_file': base64.b64encode('hello world')})\ |
|||
.import_file() |
|||
for statement in self.env['account.bank.statement'].browse( |
|||
action['context']['statement_ids']): |
|||
self.assertEqual( |
|||
base64.b64decode(statement.import_file.datas), |
|||
'hello world') |
@ -0,0 +1,25 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<openerp> |
|||
<data> |
|||
<record id="view_bank_statement_form" model="ir.ui.view"> |
|||
<field name="model">account.bank.statement</field> |
|||
<field name="inherit_id" ref="account.view_bank_statement_form" /> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//page[@string='Transactions']" position="after"> |
|||
<page string="Imported file" attrs="{'invisible': [('import_file', '=', False)]}"> |
|||
<group> |
|||
<group> |
|||
<field name="import_file" /> |
|||
</group> |
|||
<group> |
|||
<field name="import_date" /> |
|||
<field name="import_user" /> |
|||
</group> |
|||
</group> |
|||
<field name="import_log" /> |
|||
</page> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue