mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[MIG] account_bank_statement_import_save_file from v10 to v12
This commit is contained in:
@@ -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 . import models
|
||||||
from .hooks import _post_init_hook
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# Copyright 2015-2019 Therp BV (<http://therp.nl>).
|
||||||
# © 2015 Therp BV (<http://therp.nl>).
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Save imported bank statements',
|
'name': 'Save imported bank statements',
|
||||||
'version': '10.0.1.0.0',
|
'version': '12.0.1.0.0',
|
||||||
'author': 'Odoo Community Association (OCA), Therp BV',
|
'author': 'Odoo Community Association (OCA), Therp BV',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'category': 'Banking addons',
|
'category': 'Banking addons',
|
||||||
@@ -15,8 +14,6 @@
|
|||||||
'data': [
|
'data': [
|
||||||
'views/account_bank_statement.xml',
|
'views/account_bank_statement.xml',
|
||||||
],
|
],
|
||||||
'post_init_hook': '_post_init_hook',
|
|
||||||
'auto_install': False,
|
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'application': False,
|
'application': False,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
from . import account_bank_statement_import
|
from . import account_bank_statement_import
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# Copyright 2015-2019 Therp BV (<http://therp.nl>).
|
||||||
# © 2015 Therp BV (<http://therp.nl>).
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo import models, fields
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
class AccountBankStatement(models.Model):
|
class AccountBankStatement(models.Model):
|
||||||
@@ -10,9 +9,7 @@ class AccountBankStatement(models.Model):
|
|||||||
|
|
||||||
import_file = fields.Many2one(
|
import_file = fields.Many2one(
|
||||||
'ir.attachment', 'Import file', readonly=True)
|
'ir.attachment', 'Import file', readonly=True)
|
||||||
import_date = fields.Datetime(
|
import_date = fields.Datetime(related='import_file.create_date')
|
||||||
related=['import_file', 'create_date'], readonly=True)
|
import_user = fields.Many2one(related='import_file.create_uid')
|
||||||
import_user = fields.Many2one(
|
|
||||||
related=['import_file', 'create_uid'], readonly=True)
|
|
||||||
import_log = fields.Text(
|
import_log = fields.Text(
|
||||||
related=['import_file', 'description'], readonly=True)
|
related='import_file.description', string='Import Warnings')
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# Copyright 2015-2019 Therp BV (<http://therp.nl>).
|
||||||
# © 2015 Therp BV (<http://therp.nl>).
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
import base64
|
from odoo import api, models
|
||||||
from odoo import models, api
|
|
||||||
|
|
||||||
|
|
||||||
class AccountBankStatementImport(models.TransientModel):
|
class AccountBankStatementImport(models.TransientModel):
|
||||||
@@ -15,26 +13,24 @@ class AccountBankStatementImport(models.TransientModel):
|
|||||||
super(AccountBankStatementImport, self).import_file()
|
super(AccountBankStatementImport, self).import_file()
|
||||||
statement_ids = action.get('context', {}).get('statement_ids')
|
statement_ids = action.get('context', {}).get('statement_ids')
|
||||||
notifications = action.get('context', {}).get('notifications')
|
notifications = action.get('context', {}).get('notifications')
|
||||||
data_file = base64.b64decode(self.data_file)
|
|
||||||
if statement_ids:
|
if statement_ids:
|
||||||
|
attach_vals = self._prepare_import_file_attachment(
|
||||||
|
self.data_file, statement_ids[0], notifications, self.filename)
|
||||||
|
attach = self.env['ir.attachment'].create(attach_vals)
|
||||||
self.env['account.bank.statement'].browse(statement_ids).write({
|
self.env['account.bank.statement'].browse(statement_ids).write({
|
||||||
'import_file': self.env['ir.attachment'].create(
|
'import_file': attach.id})
|
||||||
self._create_import_file_attachment_data(
|
|
||||||
data_file, statement_ids[0], notifications,
|
|
||||||
self.filename)).id,
|
|
||||||
})
|
|
||||||
return action
|
return action
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _create_import_file_attachment_data(self, data_file, statement_id,
|
def _prepare_import_file_attachment(self, data_file, statement_id,
|
||||||
notifications, filename=None):
|
notifications, filename):
|
||||||
return {
|
return {
|
||||||
'name': filename or '<unknown>',
|
'name': filename,
|
||||||
'res_model': 'account.bank.statement',
|
'res_model': 'account.bank.statement',
|
||||||
'res_id': statement_id,
|
'res_id': statement_id,
|
||||||
'type': 'binary',
|
'type': 'binary',
|
||||||
'datas': base64.b64encode(data_file),
|
'datas': data_file,
|
||||||
'datas_fname': filename or '<unknown>',
|
'datas_fname': filename,
|
||||||
'description': '\n'.join(
|
'description': '\n'.join(
|
||||||
'%(type)s: %(message)s' % notification
|
'%(type)s: %(message)s' % notification
|
||||||
for notification in notifications) or False,
|
for notification in notifications) or False,
|
||||||
|
|||||||
@@ -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.
|
||||||
1
account_bank_statement_import_save_file/readme/USAGE.rst
Normal file
1
account_bank_statement_import_save_file/readme/USAGE.rst
Normal file
@@ -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.
|
||||||
@@ -4,20 +4,16 @@
|
|||||||
<field name="model">account.bank.statement</field>
|
<field name="model">account.bank.statement</field>
|
||||||
<field name="inherit_id" ref="account.view_bank_statement_form" />
|
<field name="inherit_id" ref="account.view_bank_statement_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//page[@name='statement_line_ids']" position="after">
|
<notebook position="inside">
|
||||||
<page string="Imported file" attrs="{'invisible': [('import_file', '=', False)]}">
|
<page string="Imported File" name="imported_file" attrs="{'invisible': [('import_file', '=', False)]}">
|
||||||
<group>
|
<group>
|
||||||
<group>
|
<field name="import_file"/>
|
||||||
<field name="import_file" />
|
<field name="import_date"/>
|
||||||
</group>
|
<field name="import_user"/>
|
||||||
<group>
|
<field name="import_log"/>
|
||||||
<field name="import_date" />
|
|
||||||
<field name="import_user" />
|
|
||||||
</group>
|
|
||||||
</group>
|
</group>
|
||||||
<field name="import_log" />
|
|
||||||
</page>
|
</page>
|
||||||
</xpath>
|
</notebook>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
Reference in New Issue
Block a user