diff --git a/account_bank_statement_import_move_line/__manifest__.py b/account_bank_statement_import_move_line/__manifest__.py
index e7795292..39c65c12 100644
--- a/account_bank_statement_import_move_line/__manifest__.py
+++ b/account_bank_statement_import_move_line/__manifest__.py
@@ -2,23 +2,20 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{
- 'name': 'Bank statement import move lines',
- 'version': '12.0.1.0.0',
- 'category': 'Accounting',
- 'summary': 'Import journal items into bank statement',
- 'author': 'Tecnativa, '
- 'Odoo Community Association (OCA)',
- 'maintainers': ['pedrobaeza'],
- 'website': 'https://github.com/OCA/bank-statement-import',
- 'depends': [
- 'account',
+ "name": "Bank statement import move lines",
+ "version": "12.0.1.0.0",
+ "category": "Accounting",
+ "summary": "Import journal items into bank statement",
+ "author": "Tecnativa, " "Odoo Community Association (OCA)",
+ "maintainers": ["pedrobaeza"],
+ "website": "https://github.com/OCA/bank-statement-import",
+ "depends": ["account",],
+ "data": [
+ "wizards/account_statement_line_create_view.xml",
+ "views/account_bank_statement_view.xml",
],
- 'data': [
- 'wizards/account_statement_line_create_view.xml',
- 'views/account_bank_statement_view.xml',
- ],
- 'license': 'AGPL-3',
- 'development_status': 'Production/Stable',
- 'installable': True,
- 'auto_install': False,
+ "license": "AGPL-3",
+ "development_status": "Production/Stable",
+ "installable": True,
+ "auto_install": False,
}
diff --git a/account_bank_statement_import_move_line/models/account_move_line.py b/account_bank_statement_import_move_line/models/account_move_line.py
index 1655f6d1..042c1644 100644
--- a/account_bank_statement_import_move_line/models/account_move_line.py
+++ b/account_bank_statement_import_move_line/models/account_move_line.py
@@ -5,7 +5,7 @@ from odoo import api, models
class AccountMoveLine(models.Model):
- _inherit = 'account.move.line'
+ _inherit = "account.move.line"
@api.multi
def _prepare_statement_line_vals(self, statement):
@@ -16,20 +16,20 @@ class AccountMoveLine(models.Model):
elif self.credit > 0:
amount = -self.credit
vals = {
- 'name': self.name or '?',
- 'amount': amount,
- 'partner_id': self.partner_id.id,
- 'statement_id': statement.id,
- 'ref': self.ref,
- 'date': self.date_maturity,
- 'amount_currency': self.amount_currency,
- 'currency_id': self.currency_id.id,
+ "name": self.name or "?",
+ "amount": amount,
+ "partner_id": self.partner_id.id,
+ "statement_id": statement.id,
+ "ref": self.ref,
+ "date": self.date_maturity,
+ "amount_currency": self.amount_currency,
+ "currency_id": self.currency_id.id,
}
return vals
@api.multi
def create_statement_line_from_move_line(self, statement):
- abslo = self.env['account.bank.statement.line']
+ abslo = self.env["account.bank.statement.line"]
for mline in self:
abslo.create(mline._prepare_statement_line_vals(statement))
return
diff --git a/account_bank_statement_import_move_line/tests/test_account_bank_statement_import_move_line.py b/account_bank_statement_import_move_line/tests/test_account_bank_statement_import_move_line.py
index f2eb42f2..ef9cff86 100644
--- a/account_bank_statement_import_move_line/tests/test_account_bank_statement_import_move_line.py
+++ b/account_bank_statement_import_move_line/tests/test_account_bank_statement_import_move_line.py
@@ -1,64 +1,75 @@
# Copyright 2017 Tecnativa - Luis M. Ontalba
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0
-from odoo.tests import common
from odoo import fields
+from odoo.tests import common
class TestAccountBankStatementImportMoveLine(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestAccountBankStatementImportMoveLine, cls).setUpClass()
- cls.account_type = cls.env['account.account.type'].create({
- 'name': 'Test Account Type'})
- cls.a_receivable = cls.env['account.account'].create({
- 'code': 'TAA',
- 'name': 'Test Receivable Account',
- 'internal_type': 'receivable',
- 'user_type_id': cls.account_type.id,
- })
- cls.partner = cls.env['res.partner'].create({
- 'name': 'Test Partner 2',
- 'parent_id': False,
- })
- cls.journal = cls.env['account.journal'].create({
- 'name': 'Test Journal',
- 'type': 'bank',
- })
- cls.invoice = cls.env['account.invoice'].create({
- 'name': 'Test Invoice 3',
- 'partner_id': cls.partner.id,
- 'type': 'out_invoice',
- 'journal_id': cls.journal.id,
- 'invoice_line_ids': [(0, 0, {
- 'account_id': cls.a_receivable.id,
- 'name': 'Test line',
- 'quantity': 1.0,
- 'price_unit': 100.00,
- })],
- })
- cls.statement = cls.env['account.bank.statement'].create({
- 'journal_id': cls.journal.id})
+ cls.account_type = cls.env["account.account.type"].create(
+ {"name": "Test Account Type"}
+ )
+ cls.a_receivable = cls.env["account.account"].create(
+ {
+ "code": "TAA",
+ "name": "Test Receivable Account",
+ "internal_type": "receivable",
+ "user_type_id": cls.account_type.id,
+ }
+ )
+ cls.partner = cls.env["res.partner"].create(
+ {"name": "Test Partner 2", "parent_id": False,}
+ )
+ cls.journal = cls.env["account.journal"].create(
+ {"name": "Test Journal", "type": "bank",}
+ )
+ cls.invoice = cls.env["account.invoice"].create(
+ {
+ "name": "Test Invoice 3",
+ "partner_id": cls.partner.id,
+ "type": "out_invoice",
+ "journal_id": cls.journal.id,
+ "invoice_line_ids": [
+ (
+ 0,
+ 0,
+ {
+ "account_id": cls.a_receivable.id,
+ "name": "Test line",
+ "quantity": 1.0,
+ "price_unit": 100.00,
+ },
+ )
+ ],
+ }
+ )
+ cls.statement = cls.env["account.bank.statement"].create(
+ {"journal_id": cls.journal.id}
+ )
def test_global(self):
self.invoice.action_invoice_open()
self.assertTrue(self.invoice.move_id)
self.invoice.move_id.post()
- wizard_o = self.env['account.statement.line.create']
+ wizard_o = self.env["account.statement.line.create"]
context = wizard_o._context.copy()
- context.update({
- 'active_model': 'account.bank.statement',
- 'active_id': self.statement.id,
- })
- wizard = wizard_o.with_context(context).create({
- 'statement_id': self.statement.id,
- 'partner_id': self.partner.id,
- 'journal_ids': [(4, self.journal.id)],
- 'allow_blocked': True,
- 'date_type': 'move',
- 'move_date': fields.Date.today(),
- 'invoice': False,
- })
+ context.update(
+ {"active_model": "account.bank.statement", "active_id": self.statement.id,}
+ )
+ wizard = wizard_o.with_context(context).create(
+ {
+ "statement_id": self.statement.id,
+ "partner_id": self.partner.id,
+ "journal_ids": [(4, self.journal.id)],
+ "allow_blocked": True,
+ "date_type": "move",
+ "move_date": fields.Date.today(),
+ "invoice": False,
+ }
+ )
wizard.populate()
self.assertEqual(len(wizard.move_line_ids), 1)
line = wizard.move_line_ids
diff --git a/account_bank_statement_import_move_line/views/account_bank_statement_view.xml b/account_bank_statement_import_move_line/views/account_bank_statement_view.xml
index c66af69a..ab637dcf 100644
--- a/account_bank_statement_import_move_line/views/account_bank_statement_view.xml
+++ b/account_bank_statement_import_move_line/views/account_bank_statement_view.xml
@@ -1,20 +1,20 @@
-
-
+
-
account.bank.statement.form.population
account.bank.statement
-
+
-
+
-
diff --git a/account_bank_statement_import_move_line/wizards/account_statement_line_create.py b/account_bank_statement_import_move_line/wizards/account_statement_line_create.py
index 7a2e9d69..7b8d97dc 100644
--- a/account_bank_statement_import_move_line/wizards/account_statement_line_create.py
+++ b/account_bank_statement_import_move_line/wizards/account_statement_line_create.py
@@ -5,115 +5,127 @@ from odoo import _, api, fields, models
class AccountStatementLineCreate(models.TransientModel):
- _name = 'account.statement.line.create'
- _description = 'Wizard to create statement lines'
+ _name = "account.statement.line.create"
+ _description = "Wizard to create statement lines"
- statement_id = fields.Many2one(
- 'account.bank.statement', string='Bank Statement')
- partner_id = fields.Many2one('res.partner', string='Partner Related',
- domain=['|', ('parent_id', '=', False),
- ('is_company', '=', True)])
- journal_ids = fields.Many2many(
- 'account.journal', string='Journals Filter')
- target_move = fields.Selection([
- ('posted', 'All Posted Entries'),
- ('all', 'All Entries'),
- ], string='Target Moves')
- allow_blocked = fields.Boolean(
- string='Allow Litigation Move Lines')
- invoice = fields.Boolean(
- string='Linked to an Invoice or Refund')
- date_type = fields.Selection([
- ('due', 'Due Date'),
- ('move', 'Move Date'),
- ], string="Type of Date Filter", required=True)
- due_date = fields.Date(string="Due Date",
- default=fields.Date.context_today)
- move_date = fields.Date(string='Move Date',
- default=fields.Date.context_today)
- move_line_ids = fields.Many2many(
- 'account.move.line', string='Move Lines')
+ statement_id = fields.Many2one("account.bank.statement", string="Bank Statement")
+ partner_id = fields.Many2one(
+ "res.partner",
+ string="Partner Related",
+ domain=["|", ("parent_id", "=", False), ("is_company", "=", True)],
+ )
+ journal_ids = fields.Many2many("account.journal", string="Journals Filter")
+ target_move = fields.Selection(
+ [("posted", "All Posted Entries"), ("all", "All Entries"),],
+ string="Target Moves",
+ )
+ allow_blocked = fields.Boolean(string="Allow Litigation Move Lines")
+ invoice = fields.Boolean(string="Linked to an Invoice or Refund")
+ date_type = fields.Selection(
+ [("due", "Due Date"), ("move", "Move Date"),],
+ string="Type of Date Filter",
+ required=True,
+ )
+ due_date = fields.Date(string="Due Date", default=fields.Date.context_today)
+ move_date = fields.Date(string="Move Date", default=fields.Date.context_today)
+ move_line_ids = fields.Many2many("account.move.line", string="Move Lines")
@api.model
def default_get(self, field_list):
res = super().default_get(field_list)
- active_model = self.env.context.get('active_model')
- if active_model == 'account.bank.statement':
- statement = self.env[active_model].browse(
- self.env.context.get('active_id')).exists()
+ active_model = self.env.context.get("active_model")
+ if active_model == "account.bank.statement":
+ statement = (
+ self.env[active_model]
+ .browse(self.env.context.get("active_id"))
+ .exists()
+ )
if statement:
- res.update({
- 'target_move': 'posted',
- 'date_type': 'due',
- 'invoice': True,
- 'statement_id': statement.id,
- })
+ res.update(
+ {
+ "target_move": "posted",
+ "date_type": "due",
+ "invoice": True,
+ "statement_id": statement.id,
+ }
+ )
return res
@api.multi
def _prepare_move_line_domain(self):
self.ensure_one()
- domain = [('reconciled', '=', False),
- ('account_id.internal_type', 'in', ('payable',
- 'receivable')),
- ('company_id', '=', self.env.user.company_id.id)]
+ domain = [
+ ("reconciled", "=", False),
+ ("account_id.internal_type", "in", ("payable", "receivable")),
+ ("company_id", "=", self.env.user.company_id.id),
+ ]
if self.journal_ids:
- domain += [('journal_id', 'in', self.journal_ids.ids)]
+ domain += [("journal_id", "in", self.journal_ids.ids)]
else:
- journals = self.env['account.journal'].search([])
- domain += [('journal_id', 'in', journals.ids)]
+ journals = self.env["account.journal"].search([])
+ domain += [("journal_id", "in", journals.ids)]
if self.partner_id:
- domain += [('partner_id', '=', self.partner_id.id)]
- if self.target_move == 'posted':
- domain += [('move_id.state', '=', 'posted')]
+ domain += [("partner_id", "=", self.partner_id.id)]
+ if self.target_move == "posted":
+ domain += [("move_id.state", "=", "posted")]
if not self.allow_blocked:
- domain += [('blocked', '!=', True)]
- if self.date_type == 'due':
+ domain += [("blocked", "!=", True)]
+ if self.date_type == "due":
domain += [
- '|',
- ('date_maturity', '<=', self.due_date),
- ('date_maturity', '=', False)]
- elif self.date_type == 'move':
- domain.append(('date', '<=', self.move_date))
+ "|",
+ ("date_maturity", "<=", self.due_date),
+ ("date_maturity", "=", False),
+ ]
+ elif self.date_type == "move":
+ domain.append(("date", "<=", self.move_date))
if self.invoice:
- domain.append(('invoice_id', '!=', False))
- paylines = self.env['account.payment'].search([
- ('state', 'in', ('draft', 'posted', 'sent')),
- ('move_line_ids', '!=', False)])
+ domain.append(("invoice_id", "!=", False))
+ paylines = self.env["account.payment"].search(
+ [
+ ("state", "in", ("draft", "posted", "sent")),
+ ("move_line_ids", "!=", False),
+ ]
+ )
if paylines:
- move_in_payment_ids = paylines.mapped('move_line_ids.id')
- domain += [('id', 'not in', move_in_payment_ids)]
+ move_in_payment_ids = paylines.mapped("move_line_ids.id")
+ domain += [("id", "not in", move_in_payment_ids)]
return domain
@api.multi
def populate(self):
domain = self._prepare_move_line_domain()
- lines = self.env['account.move.line'].search(domain)
+ lines = self.env["account.move.line"].search(domain)
self.move_line_ids = False
self.move_line_ids = lines
action = {
- 'name': _('Select Move Lines to Create Statement'),
- 'type': 'ir.actions.act_window',
- 'res_model': 'account.statement.line.create',
- 'view_mode': 'form',
- 'target': 'new',
- 'res_id': self.id,
- 'context': self._context,
+ "name": _("Select Move Lines to Create Statement"),
+ "type": "ir.actions.act_window",
+ "res_model": "account.statement.line.create",
+ "view_mode": "form",
+ "target": "new",
+ "res_id": self.id,
+ "context": self._context,
}
return action
@api.onchange(
- 'date_type', 'move_date', 'due_date', 'journal_ids', 'invoice',
- 'target_move', 'allow_blocked', 'partner_id')
+ "date_type",
+ "move_date",
+ "due_date",
+ "journal_ids",
+ "invoice",
+ "target_move",
+ "allow_blocked",
+ "partner_id",
+ )
def move_line_filters_change(self):
domain = self._prepare_move_line_domain()
- res = {'domain': {'move_line_ids': domain}}
+ res = {"domain": {"move_line_ids": domain}}
return res
@api.multi
def create_statement_lines(self):
for rec in self:
if rec.move_line_ids and rec.statement_id:
- rec.move_line_ids.create_statement_line_from_move_line(
- rec.statement_id)
+ rec.move_line_ids.create_statement_line_from_move_line(rec.statement_id)
return True
diff --git a/account_bank_statement_import_move_line/wizards/account_statement_line_create_view.xml b/account_bank_statement_import_move_line/wizards/account_statement_line_create_view.xml
index e6eaeddc..db3a20bb 100644
--- a/account_bank_statement_import_move_line/wizards/account_statement_line_create_view.xml
+++ b/account_bank_statement_import_move_line/wizards/account_statement_line_create_view.xml
@@ -1,63 +1,73 @@
-
+
-
account_statement_line_create_form
account.statement.line.create
-
-
+
Create Lines from Move Lines
account.statement.line.create
form
new
-