You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
# Copyright 2019 Tecnativa - Vicent Cubells
|
|
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
import csv
|
|
import base64
|
|
from odoo import api, fields, models
|
|
from io import StringIO
|
|
|
|
|
|
class WizardTxtMapCreate(models.TransientModel):
|
|
_name = 'wizard.txt.map.create'
|
|
_description = 'Wizard Txt Map Create'
|
|
|
|
data_file = fields.Binary(
|
|
string='Bank Statement File',
|
|
required=True,
|
|
)
|
|
filename = fields.Char()
|
|
|
|
@api.multi
|
|
def create_map_lines(self):
|
|
statement_obj = self.env['account.bank.statement.import.map']
|
|
data_file = base64.b64decode(self.data_file)
|
|
if not isinstance(data_file, str):
|
|
data_file = data_file.decode('utf-8-sig').strip()
|
|
file = StringIO(data_file)
|
|
file.seek(0)
|
|
reader = csv.reader(file)
|
|
headers = []
|
|
for row in reader:
|
|
headers = row
|
|
break
|
|
lines = []
|
|
for idx, title in enumerate(headers):
|
|
lines.append((0, 0, {'sequence': idx, 'name': title}))
|
|
if lines:
|
|
for statement in statement_obj.browse(
|
|
self.env.context.get('active_ids')):
|
|
statement.map_line_ids = lines
|