[MIG] account_bank_statement_import_save_file from v10 to v12

This commit is contained in:
Alexis de Lattre
2019-02-28 22:50:31 +01:00
parent c10c08de1f
commit 3ce503fd86
10 changed files with 31 additions and 125 deletions

View File

@@ -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

View File

@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# © 2015 Therp BV (<http://therp.nl>).
# Copyright 2015-2019 Therp BV (<http://therp.nl>).
# 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):
@@ -10,9 +9,7 @@ class AccountBankStatement(models.Model):
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_date = fields.Datetime(related='import_file.create_date')
import_user = fields.Many2one(related='import_file.create_uid')
import_log = fields.Text(
related=['import_file', 'description'], readonly=True)
related='import_file.description', string='Import Warnings')

View File

@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
# © 2015 Therp BV (<http://therp.nl>).
# Copyright 2015-2019 Therp BV (<http://therp.nl>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import base64
from odoo import models, api
from odoo import api, models
class AccountBankStatementImport(models.TransientModel):
@@ -15,26 +13,24 @@ class AccountBankStatementImport(models.TransientModel):
super(AccountBankStatementImport, self).import_file()
statement_ids = action.get('context', {}).get('statement_ids')
notifications = action.get('context', {}).get('notifications')
data_file = base64.b64decode(self.data_file)
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({
'import_file': self.env['ir.attachment'].create(
self._create_import_file_attachment_data(
data_file, statement_ids[0], notifications,
self.filename)).id,
})
'import_file': attach.id})
return action
@api.model
def _create_import_file_attachment_data(self, data_file, statement_id,
notifications, filename=None):
def _prepare_import_file_attachment(self, data_file, statement_id,
notifications, filename):
return {
'name': filename or '<unknown>',
'name': filename,
'res_model': 'account.bank.statement',
'res_id': statement_id,
'type': 'binary',
'datas': base64.b64encode(data_file),
'datas_fname': filename or '<unknown>',
'datas': data_file,
'datas_fname': filename,
'description': '\n'.join(
'%(type)s: %(message)s' % notification
for notification in notifications) or False,