Skip to content

Commit

Permalink
add account tag setting to account autoconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-demeyer committed Feb 25, 2019
1 parent 48123dc commit 31a2ac5
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 46 deletions.
4 changes: 2 additions & 2 deletions l10n_be_coa_multilang/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright 2009-2018 Noviat
# Copyright 2009-2019 Noviat
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Belgium - Multilingual Chart of Accounts (en/nl/fr)',
'version': '11.0.1.0.0',
'version': '11.0.1.1.0',
'license': 'AGPL-3',
'author': "Noviat",
'website': 'http://www.noviat.com',
Expand Down
4 changes: 4 additions & 0 deletions l10n_be_coa_multilang/data/account_account_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,28 @@
<field name="name">Purchases of raw materials</field>
<field name="code">600000</field>
<field name="user_type_id" ref="account.data_account_type_expenses"/>
<field name="tag_ids" eval="[(6,0,[ref('account.account_tag_operating')])]"/>
<field name="chart_template_id" ref="l10n_be_coa_multilang_template"/>
</record>
<record id="aatn_654000" model="account.account.template">
<field name="name">Exchange rate losses</field>
<field name="code">654000</field>
<field name="user_type_id" ref="account.data_account_type_expenses"/>
<field name="tag_ids" eval="[(6,0,[ref('account.account_tag_financing')])]"/>
<field name="chart_template_id" ref="l10n_be_coa_multilang_template"/>
</record>
<record id="aatn_700000" model="account.account.template">
<field name="name">Sales</field>
<field name="code">700000</field>
<field name="user_type_id" ref="account.data_account_type_revenue"/>
<field name="tag_ids" eval="[(6,0,[ref('account.account_tag_operating')])]"/>
<field name="chart_template_id" ref="l10n_be_coa_multilang_template"/>
</record>
<record id="aatn_754000" model="account.account.template">
<field name="name">Exchange rate gains</field>
<field name="code">754000</field>
<field name="user_type_id" ref="account.data_account_type_revenue"/>
<field name="tag_ids" eval="[(6,0,[ref('account.account_tag_financing')])]"/>
<field name="chart_template_id" ref="l10n_be_coa_multilang_template"/>
</record>
<record id="aatn_999999" model="account.account.template">
Expand Down
85 changes: 84 additions & 1 deletion l10n_be_coa_multilang/data/be_legal_financial_reportscheme.xml

Large diffs are not rendered by default.

78 changes: 53 additions & 25 deletions l10n_be_coa_multilang/models/account_account.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 api, fields, models, _
Expand All @@ -20,17 +20,26 @@ def _onchange_code(self):
countries = self._get_be_scheme_countries()
if self.code and \
self.company_id.country_id.code in countries:
update = []
if self._origin.code:
old = self._get_be_reportscheme_tag(self._origin.code)
if old.report_id:
update.append((3, old.report_id.id))
new = self._get_be_reportscheme_tag(self.code)
if new.report_id:
update.append((4, new.report_id.id))
if update:
self.financial_report_ids = update
self.user_type_id = new.account_type_id
entry, entries = self._get_be_reportscheme_entry(self.code)

be_reports = entries.mapped('report_id')
for report in self.financial_report_ids:
if report in be_reports and report != entry.report_id:
self.financial_report_ids -= report
if entry.report_id not in self.financial_report_ids:
self.financial_report_ids += entry.report_id

cf_tags = self._get_cash_flow_statement_tags()
for tag in self.tag_ids:
if tag in cf_tags and tag not in entry.account_tag_ids:
self.tag_ids -= tag
for new_tag in entry.account_tag_ids:
if new_tag not in self.tag_ids:
self.tag_ids += new_tag

if self.user_type_id != entry.account_type_id:
self.user_type_id = entry.account_type_id

if hasattr(super(AccountAccount, self), '_onchange_code'):
super(AccountAccount, self)._onchange_code()

Expand All @@ -54,13 +63,16 @@ def create(self, vals):
company = self.env[
'res.company']._company_default_get('account.account')
if company.country_id.code in self._get_be_scheme_countries():
scheme_tag = self._get_be_reportscheme_tag(vals.get('code', ''))
if scheme_tag:
if scheme_tag.report_id:
entry, entries = self._get_be_reportscheme_entry(
vals.get('code', ''))
if entry:
if entry.report_id:
vals['financial_report_ids'] = [
(4, scheme_tag.report_id.id)]
(4, entry.report_id.id)]
if not vals.get('user_type_id'):
vals['user_type_id'] = scheme_tag.account_type_id.id
vals['user_type_id'] = entry.account_type_id.id
if not vals.get('tag_ids'):
vals['tag_ids'] = [(6, 0, entry.account_tag_ids.ids)]
return super(AccountAccount, self).create(vals)

@api.multi
Expand All @@ -72,16 +84,17 @@ def write(self, vals):
or self.company_id
if company.country_id.code in self._get_be_scheme_countries():
update = []
old = self._get_be_reportscheme_tag(self.code)
old, entries = self._get_be_reportscheme_entry(self.code)
if old.report_id:
update.append((3, old.report_id.id))
new = self._get_be_reportscheme_tag(vals.get('code', ''))
new, entries = self._get_be_reportscheme_entry(
vals.get('code', ''))
if new.report_id:
update.append((4, new.report_id.id))
if update:
vals['financial_report_ids'] = vals.get(
'financial_report_ids', [])
vals['financial_report_ids'].append(update)
vals['financial_report_ids'].extend(update)
return super(AccountAccount, self).write(vals)

def _get_be_scheme_countries(self):
Expand All @@ -91,13 +104,28 @@ def _get_be_scheme_countries(self):
"""
return ['BE']

def _get_be_reportscheme_tag(self, code):
scheme_tags = self.env[
def _get_cash_flow_statement_tags(self):
"""
Use this method if you have changed the standard
'account_reports' Cash Flow report
"""
tags = self.env['account.account.tag']
refs = [
'account.account_tag_operating',
'account.account_tag_financing',
'account.account_tag_investing',
]
for ref in refs:
tags += self.env.ref(ref)
return tags

def _get_be_reportscheme_entry(self, code):
entries = self.env[
'be.legal.financial.reportscheme'].search([])
scheme_tag = scheme_tags.filtered(
entry = entries.filtered(
lambda r: r.account_group == code[0:len(r.account_group)])
if len(scheme_tag) > 1:
if len(entry) > 1:
raise UserError(
_("Configuration Error in the "
"Belgian Legal Financial Report Scheme."))
return scheme_tag
return entry, entries
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 fields, models
Expand All @@ -17,6 +17,10 @@ class BeLegalFinancialReportscheme(models.Model):
comodel_name='account.account.type',
string='Account Type',
required=True)
account_tag_ids = fields.Many2many(
comodel_name='account.account.tag',
relation='be_scheme_account_tag_rel',
string='Tags')
report_id = fields.Many2one(
comodel_name='account.financial.report',
string='Report Entry',
Expand Down
25 changes: 14 additions & 11 deletions l10n_be_coa_multilang/views/be_legal_financial_reportscheme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@
<field name="model">be.legal.financial.reportscheme</field>
<field name="arch" type="xml">
<form string="Belgian Legal Financial Report Scheme">
<group col="6">
<group>
<field name="account_group"/>
<field name="account_type_id"/>
<field name="account_tag_ids" widget="many2many_tags"
domain="[('applicability', '!=', 'taxes')]"
options="{'no_open': True}"/>
<field name="report_id"/>
</group>
<notebook>
<page string="Accounts">
<field name="account_ids">
<tree string="Accounts">
<field name="code"/>
<field name="name"/>
</tree>
</field>
</page>
</notebook>
<notebook>
<page string="Accounts">
<field name="account_ids">
<tree string="Accounts">
<field name="code"/>
<field name="name"/>
</tree>
</field>
</page>
</notebook>
</form>
</field>
</record>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<record id="l10n_be_coa_multilang_config_action_todo" model="ir.actions.todo">
<field name="name">l10n_be_coa_multilang setup wizard</field>
<field name="action_id" ref="l10n_be_coa_multilang_config_action"/>
<field name="type">automatic</field>
</record>

</odoo>
27 changes: 23 additions & 4 deletions l10n_be_coa_multilang/wizards/l10n_be_update_be_reportscheme.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 api, fields, models, _
Expand All @@ -9,6 +9,10 @@ class l10n_be_update_be_reportscheme(models.TransientModel):
_name = 'l10n_be.update_be_reportscheme'
_description = 'Update BNB/NBB financial reports configuration'

update_account_type = fields.Boolean(
help="Update also Account Types")
update_account_tags = fields.Boolean(
help="Update also Account Tags")
note = fields.Text('Result', readonly=True)

def _update_be_reportscheme(self):
Expand All @@ -20,6 +24,7 @@ def _update_be_reportscheme(self):
upd_ctx = {'update_be_reportscheme': True}
scheme_table = self.env['be.legal.financial.reportscheme'].search([])
be_reports = scheme_table.mapped('report_id')
cf_tags = self.env['account.account']._get_cash_flow_statement_tags()
accounts = self.env[
'account.account'].with_context(upd_ctx).search([])

Expand All @@ -32,13 +37,13 @@ def _update_be_reportscheme(self):
be_scheme_accounts += account
break

# delete old reporting configuration
for account in be_scheme_accounts:

updates = []
old = account.financial_report_ids.filtered(
lambda r: r in be_reports)
if old:
updates.append((3, old.id))
for o in old:
updates.append((3, o.id))
be_report_entries = scheme_table.filtered(
lambda x:
account.code[:len(x.account_group)] == x.account_group)
Expand All @@ -51,6 +56,20 @@ def _update_be_reportscheme(self):
updates.append((4, be_report.id))
account.financial_report_ids = updates

if self.update_account_type:
account_type = be_report_entries.account_type_id
if account.user_type_id != account_type:
account.user_type_id = account_type

if self.update_account_tags:
account_tags = be_report_entries.account_tag_ids
for tag in account.tag_ids:
if tag in cf_tags and tag not in account_tags:
account.tag_ids -= tag
for new_tag in account_tags:
if new_tag not in account.tag_ids:
account.tag_ids += new_tag

# write list of entries that are not included in
# the BNB reports to the note field
non_be_scheme_accounts = accounts - be_scheme_accounts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<group>
<label string="Update general accounts reporting configuration for Belgian BNB/NBB legal reportscheme." width="500"/>
</group>
<group>
<field name="update_account_type"/>
<field name="update_account_tags"/>
</group>
<footer>
<button name="update_be_reportscheme" string="Update" type="object" class="oe_highlight"/>
or
Expand Down Expand Up @@ -57,7 +61,6 @@
<record id="l10n_be_update_be_reportscheme_todo" model="ir.actions.todo">
<field name="name">Belgian BNB/NBB reportscheme Configuration</field>
<field name="action_id" ref="l10n_be_update_be_reportscheme_action"/>
<field name="type">manual</field>
<field name="state">done</field>
</record>
</data>
Expand Down

0 comments on commit 31a2ac5

Please sign in to comment.