Skip to content

Commit

Permalink
[11.0][FIX]belgian reports - add codes
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-demeyer committed May 23, 2019
1 parent 9c49796 commit 809ad88
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion l10n_be_coa_multilang/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
'name': 'Belgium - Multilingual Chart of Accounts (en/nl/fr)',
'version': '11.0.1.1.0',
'version': '11.0.1.1.1',
'license': 'AGPL-3',
'author': "Noviat",
'website': 'http://www.noviat.com',
Expand Down
33 changes: 18 additions & 15 deletions l10n_be_coa_multilang/models/account_financial_report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2009-2018 Noviat
# Copyright 2009-2019 Noviat
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models
Expand All @@ -11,32 +11,35 @@ class AccountFinancialReport(models.Model):
invisible = fields.Boolean(
help="Hide this entry from the printed report.")

def _convert_to_cache(self, values, update=False, validate=True):
def _get_children_by_order(self):
"""
The 'report.account.report_financial, get_account_lines' method
does not allow to include extra fields in list of returned
value dicts.
We bypass this limitation by adding the 'code' to the 'name'
field for the belgian reports.
field for the belgian reports in the cache.
In Odoo 10.0 and initially also Odoo 11.0 we used the
_convert_to_cache method to do this.
The convert_to_cache technique doesn't work any more for this purpose
as from 2019-02-04 (commit 36551615b7265ad83dbf9d1207ff9ee59b7069f3,
[IMP] read, cache: faster read by updating the cache by fields)
We now update the cache here.
TODO:
make PR to add an '_update_account_lines' method into the
get_account_lines method so that this code can be replaced
by a cleaner solution.
"""
res = super(AccountFinancialReport, self)._convert_to_cache(
values, update=update, validate=validate)
if self.env.context.get('add_code_to_name') \
and res.get('code') and res.get('name'):
res['name'] += ' - (' + res['code'] + ')'
return res

def _get_children_by_order(self):
if self.env.context.get('get_children_by_sequence'):
res = self.search(
recs = self.search(
[('id', 'child_of', self.ids[0]), ('invisible', '=', 0)],
order='sequence ASC')
else:
res = super(
AccountFinancialReport, self)._get_children_by_order()
return res
recs = super()._get_children_by_order()
if self.env.context.get('add_code_to_name'):
field = self._fields['name']
for r in recs:
if r.code and r.name:
val = r.name + ' - (' + r.code + ')'
self.env.cache.set(r, field, val)
return recs
16 changes: 7 additions & 9 deletions l10n_be_coa_multilang/report/report_account_report_financial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2009-2018 Noviat
# Copyright 2009-2019 Noviat
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models
Expand All @@ -9,13 +9,11 @@ class ReportAccountReportFinancial(models.AbstractModel):

def get_account_lines(self, data):
ctx = self.env.context.copy()
if 'used_context' in data \
and data['used_context'].get('get_children_by_sequence'):
ctx.update({
'get_children_by_sequence': True,
'add_code_to_name': True,
})
lines = super(
if 'used_context' in data:
if data['used_context'].get('get_children_by_sequence'):
ctx['get_children_by_sequence'] = True
if data['used_context'].get('add_code_to_name'):
ctx['add_code_to_name'] = True
return super(
ReportAccountReportFinancial, self.with_context(ctx)
).get_account_lines(data)
return lines
7 changes: 5 additions & 2 deletions l10n_be_coa_multilang/wizards/accounting_report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2009-2017 Noviat
# Copyright 2009-2019 Noviat
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models
Expand All @@ -19,5 +19,8 @@ def _build_contexts(self, data):
self.env.ref('%s.%s' % (module, ref))
for ref in refs]
if account_report in be_legal_reports:
result.update({'get_children_by_sequence': True})
result.update({
'get_children_by_sequence': True,
'add_code_to_name': True,
})
return result

0 comments on commit 809ad88

Please sign in to comment.