Browse Source

[12.0][IMP] account_bank_statement_import_txt_xlsx:

* strip header names, same as Odoo does in fields if you enter
  names with initial or final spaces.
* Allow to select a default mapping per journal.
12.0
Lois Rilo 5 years ago
committed by Alexey Pelykh
parent
commit
1404575dac
  1. 1
      account_bank_statement_import_txt_xlsx/__manifest__.py
  2. 5
      account_bank_statement_import_txt_xlsx/models/account_bank_statement_import.py
  3. 2
      account_bank_statement_import_txt_xlsx/models/account_bank_statement_import_sheet_parser.py
  4. 6
      account_bank_statement_import_txt_xlsx/models/account_journal.py
  5. 16
      account_bank_statement_import_txt_xlsx/views/account_journal_views.xml

1
account_bank_statement_import_txt_xlsx/__manifest__.py

@ -30,6 +30,7 @@
"data/map_data.xml", "data/map_data.xml",
"views/account_bank_statement_import_sheet_mapping.xml", "views/account_bank_statement_import_sheet_mapping.xml",
"views/account_bank_statement_import.xml", "views/account_bank_statement_import.xml",
"views/account_journal_views.xml",
"wizards/account_bank_statement_import_sheet_mapping_wizard.xml", "wizards/account_bank_statement_import_sheet_mapping_wizard.xml",
] ]
} }

5
account_bank_statement_import_txt_xlsx/models/account_bank_statement_import.py

@ -10,9 +10,14 @@ _logger = logging.getLogger(__name__)
class AccountBankStatementImport(models.TransientModel): class AccountBankStatementImport(models.TransientModel):
_inherit = 'account.bank.statement.import' _inherit = 'account.bank.statement.import'
def _get_default_mapping_id(self):
return self.env["account.journal"].browse(
self.env.context.get('journal_id')).default_sheet_mapping_id
sheet_mapping_id = fields.Many2one( sheet_mapping_id = fields.Many2one(
string='Sheet mapping', string='Sheet mapping',
comodel_name='account.bank.statement.import.sheet.mapping', comodel_name='account.bank.statement.import.sheet.mapping',
default=_get_default_mapping_id,
) )
@api.multi @api.multi

2
account_bank_statement_import_txt_xlsx/models/account_bank_statement_import_sheet_parser.py

@ -117,7 +117,7 @@ class AccountBankStatementImportSheetParser(models.TransientModel):
if isinstance(csv_or_xlsx, tuple): if isinstance(csv_or_xlsx, tuple):
header = [str(value) for value in csv_or_xlsx[1].row_values(0)] header = [str(value) for value in csv_or_xlsx[1].row_values(0)]
else: else:
header = list(next(csv_or_xlsx))
header = [value.strip() for value in next(csv_or_xlsx)]
timestamp_column = header.index(mapping.timestamp_column) timestamp_column = header.index(mapping.timestamp_column)
currency_column = header.index(mapping.currency_column) \ currency_column = header.index(mapping.currency_column) \
if mapping.currency_column else None if mapping.currency_column else None

6
account_bank_statement_import_txt_xlsx/models/account_journal.py

@ -2,12 +2,16 @@
# Copyright 2020 Brainbean Apps (https://brainbeanapps.com) # Copyright 2020 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
from odoo import fields, models
class AccountJournal(models.Model): class AccountJournal(models.Model):
_inherit = 'account.journal' _inherit = 'account.journal'
default_sheet_mapping_id = fields.Many2one(
comodel_name='account.bank.statement.import.sheet.mapping',
)
def _get_bank_statements_available_import_formats(self): def _get_bank_statements_available_import_formats(self):
res = super()._get_bank_statements_available_import_formats() res = super()._get_bank_statements_available_import_formats()
res.append('TXT/CSV/XSLX') res.append('TXT/CSV/XSLX')

16
account_bank_statement_import_txt_xlsx/views/account_journal_views.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_account_journal_form_n43" model="ir.ui.view">
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='advanced_settings']/group" position="inside">
<group string="Statement Import Map" attrs="{'invisible': [('type','!=','bank')]}">
<field name="default_sheet_mapping_id"/>
</group>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save