Skip to content

Commit

Permalink
update coda modules
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-demeyer committed Nov 20, 2020
1 parent 7669871 commit fe9d52c
Show file tree
Hide file tree
Showing 29 changed files with 1,077 additions and 460 deletions.
4 changes: 2 additions & 2 deletions account_bank_statement_advanced/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright 2009-2019 Noviat
# Copyright 2009-2020 Noviat
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Advanced Bank Statement',
'version': '11.0.1.1.0',
'version': '11.0.1.5.0',
'license': 'AGPL-3',
'author': 'Noviat',
'website': 'http://www.noviat.com',
Expand Down
49 changes: 45 additions & 4 deletions account_bank_statement_advanced/models/account_bank_statement.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2009-2019 Noviat.
# Copyright 2009-2020 Noviat.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, _
Expand All @@ -14,12 +14,24 @@ class AccountBankStatement(models.Model):
"at this date.\n"
"This is useful if the accounting period in which the entries "
"should normally be booked is already closed.")
foreign_currency = fields.Boolean(
compute='_compute_foreign_currency',
store=True)

@api.multi
@api.depends('currency_id')
def _compute_foreign_currency(self):
for rec in self:
if rec.currency_id != rec.company_id.currency_id:
rec.foreign_currency = True
else:
rec.foreign_currency = False

@api.multi
def automatic_reconcile(self):
reconcile_note = ''
for st in self:
reconcile_note = self._automatic_reconcile(
reconcile_note += st._automatic_reconcile(
reconcile_note=reconcile_note)
if reconcile_note:
module = __name__.split('addons.')[1].split('.')[0]
Expand All @@ -33,13 +45,13 @@ def automatic_reconcile(self):
'res_model': 'bank.statement.automatic.reconcile.result.view',
'view_id': result_view.id,
'target': 'new',
'context': dict(self._context, note=reconcile_note),
'context': dict(self.env.context, note=reconcile_note),
'type': 'ir.actions.act_window',
}
else:
return True

def _automatic_reconcile(self, reconcile_note):
def _automatic_reconcile(self, reconcile_note='', st_lines=None):
"""
Placeholder for modules that implement automatic reconciliation (e.g.
l10n_be_coda_advanced) as a preprocessing step before entering
Expand All @@ -52,3 +64,32 @@ def _automatic_reconcile(self, reconcile_note):
"""
self.ensure_one()
return reconcile_note

@api.multi
def reconciliation_widget_preprocess(self):
"""
This method as well as the javascript code calling this method
has not been designed for inherit.
In order to stay as close as possible to the standard code
we have used the following trick:
- in the javascript code we append the st_line_ids as negative
values to the statement_ids
- in this method we apply the statement lines passed to this method
via this trick as a filter on the result
This is not a good solution from a performance standpoint since
all statement lines are browsed where we need only the selected ones.
"""
statement_ids = self.ids
if not statement_ids or statement_ids[-1] > 0:
return super().reconciliation_widget_preprocess()
for i, st_id in enumerate(statement_ids[::-1]):
if st_id > 0:
break
cnt = len(statement_ids)
st_line_ids = statement_ids[-i:]
st_line_ids = [-x for x in st_line_ids]
statements = self[:cnt - i]
res = super(AccountBankStatement, statements).\
reconciliation_widget_preprocess()
res['st_lines_ids'] = st_line_ids
return res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2009-2019 Noviat.
# Copyright 2009-2020 Noviat.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


Expand Down Expand Up @@ -56,10 +56,11 @@ class AccountBankStatementLine(models.Model):
"the <CdtrRefInf> reference is recorded in this field.")
reconcile_get = fields.Char(
string='Reconciled', compute='_compute_reconcile_get', readonly=True)
moves_state = fields.Char(
moves_state = fields.Selection(
string='Moves State',
selection=[('draft', 'Unposted'), ('posted', 'Posted')],
compute='_compute_moves_state',
readonly=True)
store=True)
# update existing fields
state = fields.Selection(store=True)
date = fields.Date(string='Entry Date')
Expand Down Expand Up @@ -91,21 +92,22 @@ def _compute_reconcile_get(self):
"""
self.reconcile_get = res

@api.one
@api.depends('journal_entry_ids')
@api.multi
@api.depends('journal_entry_ids.move_id.state')
def _compute_moves_state(self):
state = False
moves = self.journal_entry_ids.mapped('move_id')
states = moves.mapped('state')
if states:
state = any([x == 'draft' for x in states]) \
and _('Unposted') or _('Posted')
self.moves_state = state
for line in self:
state = False
moves = line.journal_entry_ids.mapped('move_id')
states = moves.mapped('state')
if states:
state = any([x == 'draft' for x in states]) \
and 'draft' or 'posted'
line.moves_state = state

@api.onchange('currency_id', 'val_date', 'date')
def _onchange_currency_id(self):
if self.currency_id:
self.amount_currency = self.statement_id.currency.with_context(
if self.currency_id and not self.amount_currency:
self.amount_currency = self.statement_id.currency_id.with_context(
date=self.val_date or self.date).compute(
self.amount, self.currency_id)
if not self.currency_id:
Expand Down Expand Up @@ -169,3 +171,43 @@ def _prepare_reconciliation_move(self, move_ref):
if self.statement_id.accounting_date:
data['date'] = self.statement_id.accounting_date
return data

@api.multi
def manual_reconcile(self):
statements = self.mapped('statement_id')
action = self.env.ref('account.action_bank_reconcile_bank_statements')
return {
'name': action.name,
'tag': action.tag,
'context': {
'statement_ids': statements.ids,
'st_line_ids': self.ids,
},
'type': 'ir.actions.client',
}

@api.multi
def automatic_reconcile(self):
reconcile_note = ''
statements = self.mapped('statement_id')
for st in statements:
st_lines = self.filtered(lambda r: r.statement_id == st)
reconcile_note += st._automatic_reconcile(
reconcile_note=reconcile_note, st_lines=st_lines)
if reconcile_note:
module = __name__.split('addons.')[1].split('.')[0]
result_view = self.env.ref(
'%s.bank_statement_automatic_reconcile_result_view_form'
% module)
return {
'name': _("Automatic Reconcile remarks:"),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'bank.statement.automatic.reconcile.result.view',
'view_id': result_view.id,
'target': 'new',
'context': dict(self.env.context, note=reconcile_note),
'type': 'ir.actions.act_window',
}
else:
return True
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
# Copyright 2009-2020 Noviat.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
*/
odoo.define('account_bank_statement_advanced.ReconciliationModel', function (require) {
"use strict";

var ReconciliationModel = require('account.ReconciliationModel');

ReconciliationModel.StatementModel.include({

load: function (context) {
if (context && context.statement_ids && context.st_line_ids) {
context.statement_ids = context.statement_ids.concat(
context.st_line_ids.map(function (x) {return x * -1})
);
};
return this._super(context);
},

loadData: function (ids, excluded_ids) {
var context = this.context;
if (context && context.st_line_ids) {
ids = context.st_line_ids;
};
return this._super(ids, excluded_ids);
},

});

});
34 changes: 28 additions & 6 deletions account_bank_statement_advanced/views/account_bank_statement.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<field name="model">account.bank.statement</field>
<field name="inherit_id" ref="account.view_bank_statement_form"/>
<field name="arch" type="xml">
<!--
<!--
placeholder for modules that implement automatic reconciliation, e.g.
- l10n_be_coda_advanced
-->
-->
<button name="%(account.action_bank_reconcile_bank_statements)d" position="before">
<button name="automatic_reconcile" string="Automatic Reconcile" type="object" class="oe_highlight" invisible="1"/>
<button name="automatic_reconcile" string="Automatic Reconcile" type="object" class="oe_highlight" attrs="{'invisible': 1}"/>
</button>
<button name="%(account.action_bank_reconcile_bank_statements)d" position="attributes">
<attribute name="string">Manual Reconcile</attribute>
Expand All @@ -38,7 +38,10 @@
<field name="date" position="after">
<field name="accounting_date"/>
</field>

<field name="currency_id" position="after">
<field name="foreign_currency" invisible="1"/>
</field>

<xpath expr="//page[@name='statement_line_ids']/field[@name='line_ids']/tree" position="attributes">
<attribute name="decoration-info">amount and not journal_entry_ids</attribute>
</xpath>
Expand All @@ -48,15 +51,34 @@
<xpath expr="//page[@name='statement_line_ids']/field[@name='line_ids']/tree/field[@name='ref']" position="attributes">
<attribute name="groups"/>
</xpath>

<xpath expr="//page[@name='statement_line_ids']/field[@name='line_ids']/tree/field[@name='amount_currency']" position="attributes">
<attribute name="invisible"/>
<attribute name="attrs">{'column_invisible': [('parent.foreign_currency', '=', False)]}</attribute>
</xpath>
<xpath expr="//page[@name='statement_line_ids']/field[@name='line_ids']/tree/field[@name='currency_id']" position="attributes">
<attribute name="invisible"/>
<attribute name="attrs">{'column_invisible': [('parent.foreign_currency', '=', False)]}</attribute>
</xpath>
<xpath expr="//page[@name='statement_line_ids']/field[@name='line_ids']/tree" position="after">
<form string="Statement Line" create="false" delete="false">
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" name="button_view_moves"
string="Journal Entries" type="object"
attrs="{'invisible': [('journal_entry_ids', '=', [])]}" icon="fa-bars"/>
<button class="oe_stat_button" name="manual_reconcile"
attrs="{'invisible': ['|', '|', ('journal_entry_ids', '!=', []), ('state', '=', 'confirm'), ('amount', '=', 0)]}"
string="Manual Reconcile" type="object"
icon="fa-share-square-o"/>
<!--
placeholder for modules that implement automatic reconciliation, e.g.
- l10n_be_coda_advanced
-->
<button class="oe_stat_button" name="automatic_reconcile"
attrs="{'invisible': 1}"
string="Automatic Reconcile" type="object"
icon="fa-gears"/>
<button name="button_cancel_reconciliation"
attrs="{'invisible': ['|',('journal_entry_ids', '=', []), ('state', '=', 'confirm')]}"
attrs="{'invisible': ['|', ('journal_entry_ids', '=', []), ('state', '=', 'confirm')]}"
string="Cancel" type="object" icon="fa fa-undo text-warning"/>
</div>
<group name="invisible">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,24 @@
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" name="button_view_moves"
string="Journal Entries" type="object"
attrs="{'invisible': [('journal_entry_ids', '=', [])]}" icon="fa-bars"/>
attrs="{'invisible': [('journal_entry_ids', '=', [])]}"
icon="fa-bars"/>
<button class="oe_stat_button" name="manual_reconcile"
attrs="{'invisible': ['|', '|', ('journal_entry_ids', '!=', []), ('state', '=', 'confirm'), ('amount', '=', 0)]}"
string="Manual Reconcile" type="object"
icon="fa-share-square-o"/>
<!--
placeholder for modules that implement automatic reconciliation, e.g.
- l10n_be_coda_advanced
-->
<button class="oe_stat_button" name="automatic_reconcile"
attrs="{'invisible': 1}"
string="Automatic Reconcile" type="object"
icon="fa-gears"/>
<button class="oe_stat_button" name="button_cancel_reconciliation"
attrs="{'invisible': ['|', ('journal_entry_ids', '=', []), ('state', '=', 'confirm')]}"
string="Revert reconciliation" type="object"
icon="fa fa-undo text-warning"/>
</div>
</group>
<group col="4" position="attributes">
Expand Down Expand Up @@ -102,6 +119,9 @@
domain="[('amount', '&lt;', 0)]"
help="Amount &lt; 0"/>
<separator/>
<filter name="no_moves" string="No Moves"
domain="[('moves_state', '=', False), ('amount', '!=', 0)]"
help="Statement Lines without Journal Entreis"/>
<filter name="draft" string="Draft"
domain="[('state', '=', 'draft')]"
help="Draft Statement Lines"/>
Expand Down
1 change: 1 addition & 0 deletions account_bank_statement_advanced/views/assets_backend.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<template id="assets_backend" name="account assets" inherit_id="account.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/account_bank_statement_advanced/static/src/js/reconciliation_model.js"></script>
<script type="text/javascript" src="/account_bank_statement_advanced/static/src/js/reconciliation_renderer.js"></script>
</xpath>
</template>
Expand Down
4 changes: 2 additions & 2 deletions l10n_be_coda_advanced/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright 2009-2019 Noviat.
# Copyright 2009-2020 Noviat.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Belgium - Advanced CODA statements Import',
'version': '11.0.1.2.0',
'version': '11.0.1.6.1',
'license': 'AGPL-3',
'author': 'Noviat',
'website': 'http://www.noviat.com',
Expand Down
30 changes: 30 additions & 0 deletions l10n_be_coda_advanced/migrations/11.0.1.6/post-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2009-2020 Noviat.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import base64
import logging

from odoo import api, SUPERUSER_ID

_logger = logging.getLogger(__name__)


def migrate(cr, version):
env = api.Environment(cr, SUPERUSER_ID, {})

codas = env['account.coda'].search([])
for coda in codas:
data = coda.coda_data
if not is_base64(data):
coda.coda_data = base64.b64encode(data)
_logger.warn(
"CODA File %s (%s) has been repaired",
coda.name, coda.coda_creation_date)


def is_base64(data):
try:
data = data.replace(b'\n', b'')
return data == base64.b64encode(base64.b64decode(data))
except Exception:
return False
1 change: 1 addition & 0 deletions l10n_be_coda_advanced/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
from . import account_coda_trans_type
from . import account_coda_trans_code
from . import account_coda_trans_category
from . import coda_account_mapping_rule
from . import coda_bank_account
Loading

0 comments on commit fe9d52c

Please sign in to comment.