Merge PR #570 into 15.0

Signed-off-by pedrobaeza
This commit is contained in:
OCA-git-bot
2023-02-23 15:38:04 +00:00
28 changed files with 810 additions and 189 deletions

View File

@@ -6,9 +6,9 @@
{
"name": "Import Statement Files",
"category": "Accounting",
"version": "15.0.2.2.1",
"version": "15.0.3.0.0",
"license": "LGPL-3",
"depends": ["account"],
"depends": ["account_statement_import_base"],
"author": "Odoo SA, Akretion, Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
"development_status": "Mature",
@@ -17,7 +17,6 @@
"security/ir.model.access.csv",
"wizard/account_statement_import_view.xml",
"views/account_journal.xml",
"views/account_bank_statement_line.xml",
],
"demo": [
"demo/partner_bank.xml",

View File

@@ -1,2 +1 @@
from . import account_journal
from . import account_bank_statement_line

View File

@@ -1,25 +0,0 @@
<?xml version="1.0" ?>
<!--
Copyright 2020 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
-->
<odoo>
<record id="view_bank_statement_line_form" model="ir.ui.view">
<field name="model">account.bank.statement.line</field>
<field name="inherit_id" ref="account.view_bank_statement_line_form" />
<field name="arch" type="xml">
<field name="transaction_type" position="before">
<field name="account_number" />
</field>
<field name="transaction_type" position="after">
<field name="partner_bank_id" />
</field>
<field name="move_id" position="after">
<field name="unique_import_id" groups="base.group_no_one" />
</field>
</field>
</record>
</odoo>

View File

@@ -23,9 +23,7 @@ class AccountStatementImport(models.TransientModel):
)
statement_filename = fields.Char()
def import_file_button(self):
"""Process the file chosen in the wizard, create bank statement(s)
and return an action."""
def _import_file(self):
self.ensure_one()
result = {
"statement_ids": [],
@@ -43,34 +41,25 @@ class AccountStatementImport(models.TransientModel):
)
)
self.env["ir.attachment"].create(self._prepare_create_attachment(result))
if self.env.context.get("return_regular_interface_action"):
action = (
self.env.ref("account.action_bank_statement_tree").sudo().read([])[0]
return result
def import_file_button(self):
"""Process the file chosen in the wizard, create bank statement(s)
and return an action."""
result = self._import_file()
action = self.env["ir.actions.actions"]._for_xml_id(
"account.action_bank_statement_tree"
)
if len(result["statement_ids"]) == 1:
action.update(
{
"view_mode": "form,tree",
"views": False,
"res_id": result["statement_ids"][0],
}
)
if len(result["statement_ids"]) == 1:
action.update(
{
"view_mode": "form,tree",
"views": False,
"res_id": result["statement_ids"][0],
}
)
else:
action["domain"] = [("id", "in", result["statement_ids"])]
else:
# dispatch to reconciliation interface
lines = self.env["account.bank.statement.line"].search(
[("statement_id", "in", result["statement_ids"])]
)
action = {
"type": "ir.actions.client",
"tag": "bank_statement_reconciliation_view",
"context": {
"statement_line_ids": lines.ids,
"company_ids": self.env.user.company_ids.ids,
"notifications": result["notifications"],
},
}
action["domain"] = [("id", "in", result["statement_ids"])]
return action
def _prepare_create_attachment(self, result):
@@ -283,43 +272,15 @@ class AccountStatementImport(models.TransientModel):
)
return journal
@api.model
def _update_partner_from_account_number(self, lvals):
partner_bank = self.env["res.partner.bank"].search(
[("acc_number", "=", lvals["account_number"])], limit=1
)
if partner_bank:
lvals["partner_bank_id"] = partner_bank.id
lvals["partner_id"] = partner_bank.partner_id.id
def _complete_stmts_vals(self, stmts_vals, journal, account_number):
speeddict = journal._statement_line_import_speeddict()
for st_vals in stmts_vals:
st_vals["journal_id"] = journal.id
for lvals in st_vals["transactions"]:
unique_import_id = lvals.get("unique_import_id")
if unique_import_id:
sanitized_account_number = sanitize_account_number(account_number)
lvals["unique_import_id"] = (
(
sanitized_account_number
and sanitized_account_number + "-"
or ""
)
+ str(journal.id)
+ "-"
+ unique_import_id
)
if (
not lvals.get("partner_bank_id")
and lvals.get("account_number")
and not lvals.get("partner_id")
):
# Find the partner from his bank account number
# The partner selected during the
# reconciliation process will be linked to the bank account
# when the statement is closed (code in the account module)
self._update_partner_from_account_number(lvals)
journal._statement_line_import_update_unique_import_id(
lvals, account_number
)
journal._statement_line_import_update_hook(lvals, speeddict)
if not lvals.get("payment_ref"):
raise UserError(_("Missing payment_ref on a transaction."))
return stmts_vals

View File

@@ -21,11 +21,11 @@
<footer>
<button
name="import_file_button"
string="Import"
string="Import and View"
type="object"
class="btn-primary"
context="{'return_regular_interface_action': True}"
/> <!-- The context may be temporary... waiting for the port of the reconcile interface -->
/>
<button string="Cancel" class="btn-default" special="cancel" />
</footer>
</form>

View File

@@ -0,0 +1,84 @@
=====================================
Base module for Bank Statement Import
=====================================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png
:target: https://odoo-community.org/page/development-status
:alt: Mature
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github
:target: https://github.com/OCA/bank-statement-import/tree/14.0/account_statement_import_base
:alt: OCA/bank-statement-import
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/bank-statement-import-14-0/bank-statement-import-14-0-account_statement_import_base
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/174/14.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This is a technical module designed to share code between 2 other modules:
* **account_statement_import** that allows to import bank statements from files,
* **account_statement_import_online** that allows to import bank statements from webservices/APIs.
**Table of contents**
.. contents::
:local:
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-statement-import/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_base%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Akretion
Contributors
~~~~~~~~~~~~
* Alexis de Lattre <alexis.delattre@akretion.com>
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
.. |maintainer-alexis-via| image:: https://github.com/alexis-via.png?size=40px
:target: https://github.com/alexis-via
:alt: alexis-via
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-alexis-via|
This module is part of the `OCA/bank-statement-import <https://github.com/OCA/bank-statement-import/tree/14.0/account_statement_import_base>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,19 @@
# Copyright 2022 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
{
"name": "Base module for Bank Statement Import",
"category": "Accounting",
"version": "15.0.1.0.0",
"license": "LGPL-3",
"depends": ["account"],
"author": "Akretion, Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
"development_status": "Mature",
"website": "https://github.com/OCA/bank-statement-import",
"data": [
"views/account_bank_statement_line.xml",
],
"installable": True,
}

View File

@@ -0,0 +1,68 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_statement_import_base
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: account_statement_import_base
#: model:ir.model.constraint,message:account_statement_import_base.constraint_account_bank_statement_line_unique_import_id
msgid "A bank account transaction can be imported only once!"
msgstr ""
#. module: account_statement_import_base
#: model:ir.model,name:account_statement_import_base.model_account_bank_statement_line
msgid "Bank Statement Line"
msgstr ""
#. module: account_statement_import_base
#: model:ir.model.fields,field_description:account_statement_import_base.field_account_bank_statement_line__display_name
#: model:ir.model.fields,field_description:account_statement_import_base.field_account_journal__display_name
msgid "Display Name"
msgstr ""
#. module: account_statement_import_base
#: model:ir.model.fields,field_description:account_statement_import_base.field_account_bank_statement_line__id
#: model:ir.model.fields,field_description:account_statement_import_base.field_account_journal__id
msgid "ID"
msgstr ""
#. module: account_statement_import_base
#: model:ir.model.fields,field_description:account_statement_import_base.field_account_bank_statement_line__unique_import_id
msgid "Import ID"
msgstr ""
#. module: account_statement_import_base
#: model:ir.model,name:account_statement_import_base.model_account_journal
msgid "Journal"
msgstr ""
#. module: account_statement_import_base
#: model:ir.model.fields,field_description:account_statement_import_base.field_account_bank_statement_line____last_update
#: model:ir.model.fields,field_description:account_statement_import_base.field_account_journal____last_update
msgid "Last Modified on"
msgstr ""
#. module: account_statement_import_base
#: model_terms:ir.ui.view,arch_db:account_statement_import_base.view_bank_statement_line_form
msgid "Notes"
msgstr ""
#. module: account_statement_import_base
#: model:ir.model.fields,field_description:account_statement_import_base.field_account_bank_statement_line__raw_data
#: model_terms:ir.ui.view,arch_db:account_statement_import_base.view_bank_statement_line_form
msgid "Raw Data"
msgstr ""
#. module: account_statement_import_base
#: model_terms:ir.ui.view,arch_db:account_statement_import_base.view_bank_statement_line_form
msgid "Technical Information"
msgstr ""

View File

@@ -0,0 +1,2 @@
from . import account_bank_statement_line
from . import account_journal

View File

@@ -1,7 +1,6 @@
# Copyright 2004-2020 Odoo S.A.
# Copyright 2020 Akretion France (http://www.akretion.com/)
# Copyright 2022 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from odoo import fields, models
@@ -10,8 +9,9 @@ class AccountBankStatementLine(models.Model):
_inherit = "account.bank.statement.line"
# Ensure transactions can be imported only once
# (if the import format provides unique transaction ids)
# if the import format provides unique transaction IDs
unique_import_id = fields.Char(string="Import ID", readonly=True, copy=False)
raw_data = fields.Text(readonly=True, copy=False)
_sql_constraints = [
(

View File

@@ -0,0 +1,69 @@
# Copyright 2022 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from odoo import api, models
from odoo.addons.base.models.res_bank import sanitize_account_number
class AccountJournal(models.Model):
_inherit = "account.journal"
def _statement_line_import_speeddict(self):
"""This method is designed to be inherited by reconciliation modules.
These modules can take advantage of this method to pre-fetch data
that will later be used for many statement lines (to avoid
searching data for each statement line).
The goal is to improve performances.
"""
self.ensure_one()
speeddict = {"account_number": {}}
partner_banks = self.env["res.partner.bank"].search_read(
[("company_id", "in", (False, self.company_id.id))],
["acc_number", "partner_id"],
)
for partner_bank in partner_banks:
speeddict["account_number"][partner_bank["acc_number"]] = {
"partner_id": partner_bank["partner_id"][0],
"partner_bank_id": partner_bank["id"],
}
return speeddict
def _statement_line_import_update_hook(self, st_line_vals, speeddict):
"""This method is designed to be inherited by reconciliation modules.
In this method you can:
- update the partner of the line by writing st_line_vals['partner_id']
- set an automated counter-part via counterpart_account_id by writing
st_line_vals['counterpart_account_id']
- do anythink you want with the statement line
"""
self.ensure_one()
if st_line_vals.get("account_number"):
st_line_vals["account_number"] = self._sanitize_bank_account_number(
st_line_vals["account_number"]
)
if not st_line_vals.get("partner_id") and speeddict["account_number"].get(
st_line_vals["account_number"]
):
st_line_vals.update(
speeddict["account_number"][st_line_vals["account_number"]]
)
def _statement_line_import_update_unique_import_id(
self, st_line_vals, account_number
):
self.ensure_one()
if st_line_vals.get("unique_import_id"):
sanitized_acc_number = self._sanitize_bank_account_number(account_number)
st_line_vals["unique_import_id"] = (
(sanitized_acc_number and sanitized_acc_number + "-" or "")
+ str(self.id)
+ "-"
+ st_line_vals["unique_import_id"]
)
@api.model
def _sanitize_bank_account_number(self, account_number):
"""Hook for extension"""
return sanitize_account_number(account_number)

View File

@@ -0,0 +1 @@
* Alexis de Lattre <alexis.delattre@akretion.com>

View File

@@ -0,0 +1,4 @@
This is a technical module designed to share code between 2 other modules:
* **account_statement_import** that allows to import bank statements from files,
* **account_statement_import_online** that allows to import bank statements from webservices/APIs.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -0,0 +1,425 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<title>Base module for Bank Statement Import</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="base-module-for-bank-statement-import">
<h1 class="title">Base module for Bank Statement Import</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Mature" src="https://img.shields.io/badge/maturity-Mature-brightgreen.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/bank-statement-import/tree/14.0/account_statement_import_base"><img alt="OCA/bank-statement-import" src="https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/bank-statement-import-14-0/bank-statement-import-14-0-account_statement_import_base"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/174/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This is a technical module designed to share code between 2 other modules:</p>
<ul class="simple">
<li><strong>account_statement_import</strong> that allows to import bank statements from files,</li>
<li><strong>account_statement_import_online</strong> that allows to import bank statements from webservices/APIs.</li>
</ul>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#bug-tracker" id="id1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id5">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/bank-statement-import/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_base%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id2">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id3">Authors</a></h2>
<ul class="simple">
<li>Akretion</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id4">Contributors</a></h2>
<ul class="simple">
<li>Alexis de Lattre &lt;<a class="reference external" href="mailto:alexis.delattre&#64;akretion.com">alexis.delattre&#64;akretion.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/alexis-via"><img alt="alexis-via" src="https://github.com/alexis-via.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/bank-statement-import/tree/14.0/account_statement_import_base">OCA/bank-statement-import</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" ?>
<!--
Copyright 2022 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
-->
<odoo>
<record id="view_bank_statement_line_form" model="ir.ui.view">
<field name="model">account.bank.statement.line</field>
<field name="inherit_id" ref="account.view_bank_statement_line_form" />
<field name="arch" type="xml">
<field name="statement_id" position="attributes">
<attribute
name="invisible"
>not context.get('statement_line_main_view')</attribute>
</field>
<xpath expr="//field[@name='company_id']/.." position="attributes">
<attribute name="col">2</attribute>
</xpath>
<field name="sequence" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="narration" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="transaction_type" position="after">
<field name="partner_bank_id" />
</field>
<sheet position="inside">
<notebook>
<page name="narration" string="Notes">
<field name="narration" nolabel="1" />
</page>
<page name="technical" string="Technical Information">
<group name="tech-fields">
<field name="unique_import_id" />
<field name="partner_name" />
<field name="account_number" />
<field name="is_reconciled" />
</group>
<group name="raw_data" string="Raw Data">
<field name="raw_data" nolabel="1" />
</group>
</page>
</notebook>
</sheet>
</field>
</record>
</odoo>

View File

@@ -4,7 +4,7 @@
{
"name": "Online Bank Statements",
"version": "15.0.2.0.0",
"version": "15.0.3.0.0",
"author": "CorporateHub, Odoo Community Association (OCA)",
"maintainers": ["alexey-pelykh"],
"website": "https://github.com/OCA/bank-statement-import",
@@ -12,8 +12,7 @@
"category": "Accounting",
"summary": "Online bank statements update",
"depends": [
"account",
"account_statement_import",
"account_statement_import_base",
"web_widget_dropdown_dynamic",
],
"data": [
@@ -23,7 +22,6 @@
"wizards/online_bank_statement_pull_wizard.xml",
"views/actions.xml",
"views/account_journal.xml",
"views/account_bank_statement_line.xml",
"views/online_bank_statement_provider.xml",
],
"installable": True,

View File

@@ -0,0 +1,17 @@
# Copyright 2022 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade
@openupgrade.migrate()
def migrate(env, version):
column = openupgrade.get_legacy_name("online_raw_data")
if openupgrade.column_exists(env.cr, "account_bank_statement_line", column):
openupgrade.logged_query(
env.cr,
"UPDATE account_bank_statement_line SET raw_data={online_raw_data}".format(
online_raw_data=column,
),
)

View File

@@ -0,0 +1,19 @@
# Copyright 2022 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade
_column_renames = {
"account_bank_statement_line": [
("online_raw_data", None),
]
}
@openupgrade.migrate()
def migrate(env, version):
if openupgrade.column_exists(
env.cr, "account_bank_statement_line", "online_raw_data"
):
openupgrade.rename_columns(env.cr, _column_renames)

View File

@@ -1,5 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import account_journal
from . import account_bank_statement_line
from . import online_bank_statement_provider

View File

@@ -1,18 +0,0 @@
# Copyright 2021 Therp BV <https://therp.nl>.
# @author: Ronald Portier <ronald@therp.nl>.
# Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
"""Add raw data to statement line, to solve import issues."""
from odoo import fields, models
class AccountBankStatementLine(models.Model):
"""Add raw data to statement line, to solve import issues."""
_inherit = "account.bank.statement.line"
online_raw_data = fields.Text(
help="The complete data retrieved online for this transaction",
readonly=True,
copy=False,
)

View File

@@ -12,7 +12,6 @@ from pytz import timezone, utc
from odoo import _, api, fields, models
from odoo.addons.base.models.res_bank import sanitize_account_number
from odoo.addons.base.models.res_partner import _tz_get
_logger = logging.getLogger(__name__)
@@ -257,6 +256,8 @@ class OnlineBankStatementProvider(models.Model):
"""Get lines from line data, but only for the right date."""
AccountBankStatementLine = self.env["account.bank.statement.line"]
provider_tz = timezone(self.tz) if self.tz else utc
journal = self.journal_id
speeddict = journal._statement_line_import_speeddict()
filtered_lines = []
for line_values in lines_data:
date = line_values["date"]
@@ -280,23 +281,18 @@ class OnlineBankStatementProvider(models.Model):
date = date.replace(tzinfo=utc)
date = date.astimezone(provider_tz).replace(tzinfo=None)
line_values["date"] = date
journal._statement_line_import_update_unique_import_id(
line_values, self.account_number
)
unique_import_id = line_values.get("unique_import_id")
if unique_import_id:
unique_import_id = self._generate_unique_import_id(unique_import_id)
line_values.update({"unique_import_id": unique_import_id})
if AccountBankStatementLine.sudo().search(
[("unique_import_id", "=", unique_import_id)], limit=1
):
continue
bank_account_number = line_values.get("account_number")
if bank_account_number:
sanitized_account_number = self._sanitize_bank_account_number(
bank_account_number
)
line_values["account_number"] = sanitized_account_number
self._update_partner_from_account_number(line_values)
if not line_values.get("payment_ref"):
line_values["payment_ref"] = line_values.get("ref")
journal._statement_line_import_update_hook(line_values, speeddict)
filtered_lines.append(line_values)
return filtered_lines
@@ -347,36 +343,6 @@ class OnlineBankStatementProvider(models.Model):
date_since = date_since.replace(tzinfo=utc).astimezone(tz)
return date_since.date()
def _generate_unique_import_id(self, unique_import_id):
self.ensure_one()
return (
(self.account_number and self.account_number + "-" or "")
+ str(self.journal_id.id)
+ "-"
+ unique_import_id
)
def _sanitize_bank_account_number(self, bank_account_number):
"""Hook for extension"""
self.ensure_one()
return sanitize_account_number(bank_account_number)
def _update_partner_from_account_number(self, line_values):
"""Lookup partner using account number."""
self.ensure_one()
partner_bank = self.env["res.partner.bank"].search(
[
("acc_number", "=", line_values["account_number"]),
"|",
("company_id", "=", False),
("company_id", "=", self.company_id.id),
],
limit=1,
)
if partner_bank:
line_values["partner_bank_id"] = partner_bank.id
line_values["partner_id"] = partner_bank.partner_id.id
def _get_next_run_period(self):
self.ensure_one()
if self.interval_type == "minutes":

View File

@@ -1,25 +0,0 @@
<?xml version="1.0" ?>
<odoo>
<record id="view_bank_statement_line_form" model="ir.ui.view">
<field name="model">account.bank.statement.line</field>
<field
name="inherit_id"
ref="account_statement_import.view_bank_statement_line_form"
/>
<field name="arch" type="xml">
<field name="move_id" position="after">
<field name="partner_name" />
</field>
<xpath expr="//sheet" position="inside">
<group colspan="4" col="1">
<separator string="Raw Data" />
<field
name="online_raw_data"
nolabel="1"
groups="base.group_no_one"
/>
</group>
</xpath>
</field>
</record>
</odoo>

View File

@@ -11,7 +11,7 @@
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form" />
<field name="arch" type="xml">
<page name="bank_account" position="inside">
<xpath expr="//field[@name='bank_statements_source']/.." position="after">
<group
name="online_bank_statements"
string="Online Bank Statements (OCA)"
@@ -47,7 +47,7 @@
class="oe_read_only"
/>
</group>
</page>
</xpath>
<xpath expr="/form/sheet" position="before">
<header>
<button

View File

@@ -241,7 +241,7 @@ class OnlineBankStatementProviderPonto(models.Model):
"payment_ref": attributes.get("remittanceInformation", ref),
"unique_import_id": transaction["id"],
"amount": attributes["amount"],
"online_raw_data": transaction,
"raw_data": transaction,
}
if attributes.get("counterpartReference"):
vals_line["account_number"] = attributes["counterpartReference"]

View File

@@ -0,0 +1 @@
../../../../account_statement_import_base

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)