2
0

[ADD][12.0] account_template_active

This commit is contained in:
Sylvain LE GAL 2020-05-04 15:17:28 +02:00
parent fe86277ea2
commit f1526dc6c7
22 changed files with 482 additions and 0 deletions

View File

@ -0,0 +1,8 @@
==============================
Disable Account Template Items
==============================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

View File

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

View File

@ -0,0 +1,24 @@
# Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Disable Account Template Items",
"version": "12.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"summary": "Allow to disable / enable account template items"
" (tax, fiscal position, account)",
"author": "GRAP, Odoo Community Association (OCA)",
"maintainers": ["legalsylvain"],
"website": "https://github.com/OCA/account-financial-tools",
"depends": [
"account",
],
"data": [
"views/view_account_account_template.xml",
"views/view_account_fiscal_position_template.xml",
"views/view_account_tax_template.xml",
],
"installable": True,
}

View File

@ -0,0 +1,50 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_template_active
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-05-04 16:56+0000\n"
"PO-Revision-Date: 2020-05-04 16:56+0000\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_template_active
#: model:ir.model,name:account_template_active.model_account_fiscal_position_account_template
msgid "Accounts Mapping Template of Fiscal Position"
msgstr ""
#. module: account_template_active
#: model:ir.model.fields,field_description:account_template_active.field_account_account_template__active
#: model:ir.model.fields,field_description:account_template_active.field_account_fiscal_position_account_template__active
#: model:ir.model.fields,field_description:account_template_active.field_account_fiscal_position_tax_template__active
#: model:ir.model.fields,field_description:account_template_active.field_account_fiscal_position_template__active
msgid "Active"
msgstr ""
#. module: account_template_active
#: model:ir.model,name:account_template_active.model_account_fiscal_position_tax_template
msgid "Tax Mapping Template of Fiscal Position"
msgstr ""
#. module: account_template_active
#: model:ir.model,name:account_template_active.model_account_fiscal_position_template
msgid "Template for Fiscal Position"
msgstr ""
#. module: account_template_active
#: model:ir.model,name:account_template_active.model_account_account_template
msgid "Templates for Accounts"
msgstr ""
#. module: account_template_active
#: model:ir.model,name:account_template_active.model_account_tax_template
msgid "Templates for Taxes"
msgstr ""

View File

@ -0,0 +1,50 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_template_active
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-05-04 16:57+0000\n"
"PO-Revision-Date: 2020-05-04 16:57+0000\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_template_active
#: model:ir.model,name:account_template_active.model_account_fiscal_position_account_template
msgid "Accounts Mapping Template of Fiscal Position"
msgstr "Modèle de mapping de compte de position fiscale"
#. module: account_template_active
#: model:ir.model.fields,field_description:account_template_active.field_account_account_template__active
#: model:ir.model.fields,field_description:account_template_active.field_account_fiscal_position_account_template__active
#: model:ir.model.fields,field_description:account_template_active.field_account_fiscal_position_tax_template__active
#: model:ir.model.fields,field_description:account_template_active.field_account_fiscal_position_template__active
msgid "Active"
msgstr "Actif"
#. module: account_template_active
#: model:ir.model,name:account_template_active.model_account_fiscal_position_tax_template
msgid "Tax Mapping Template of Fiscal Position"
msgstr "Modèle de mapping de taxe de position fiscale"
#. module: account_template_active
#: model:ir.model,name:account_template_active.model_account_fiscal_position_template
msgid "Template for Fiscal Position"
msgstr "Modèle de position fiscale"
#. module: account_template_active
#: model:ir.model,name:account_template_active.model_account_account_template
msgid "Templates for Accounts"
msgstr "Modèles pour les comptes"
#. module: account_template_active
#: model:ir.model,name:account_template_active.model_account_tax_template
msgid "Templates for Taxes"
msgstr "Modèles pour les taxes"

View File

@ -0,0 +1,5 @@
from . import account_account_template
from . import account_fiscal_position_account_template
from . import account_fiscal_position_tax_template
from . import account_fiscal_position_template
from . import account_tax_template

View File

@ -0,0 +1,24 @@
# Copyright (C) 2015 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class AccountAccountTemplate(models.Model):
_inherit = "account.account.template"
active = fields.Boolean(string="Active", default=True)
def write(self, vals):
FpaTemplate = self.env["account.fiscal.position.account.template"]
if "active" in vals and not vals.get("active"):
# Disable account.account.template should disable
# account.fiscal.position.account.template associated
fpaTemplates = FpaTemplate.search([
"|",
("account_src_id", "in", self.ids),
("account_dest_id", "in", self.ids),
])
fpaTemplates.write({"active": False})
return super().write(vals)

View File

@ -0,0 +1,24 @@
# Copyright (C) 2018-Today GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class AccountFiscalPositionAccountTemplate(models.Model):
_inherit = "account.fiscal.position.account.template"
active = fields.Boolean("Active", default=True)
def write(self, vals):
AccountTemplate = self.env["account.account.template"]
if vals.get("active", False):
# enable account.fiscal.position.account.template should enable
# related account.account.template
account_ids = set(
self.mapped("account_src_id").ids
+ self.mapped("account_dest_id").ids
)
accountTemplates = AccountTemplate.browse(account_ids)
accountTemplates.write({"active": True})
return super().write(vals)

View File

@ -0,0 +1,24 @@
# Copyright (C) 2019-Today GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class AccountFiscalPositionTaxTemplate(models.Model):
_inherit = "account.fiscal.position.tax.template"
active = fields.Boolean("Active", default=True)
def write(self, vals):
TaxTemplate = self.env["account.tax.template"]
if vals.get("active", False):
# enable account.fiscal.position.tax.template should enable
# related account.tax.template
tax_ids = set(
self.mapped("tax_src_id").ids
+ self.mapped("tax_dest_id").ids
)
taxTemplates = TaxTemplate.browse(tax_ids)
taxTemplates.write({"active": True})
return super().write(vals)

View File

@ -0,0 +1,11 @@
# Copyright (C) 2019-Today GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class AccountFiscalPositionTemplate(models.Model):
_inherit = "account.fiscal.position.template"
active = fields.Boolean("Active", default=True)

View File

@ -0,0 +1,22 @@
# Copyright (C) 2020 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models
class AccountTaxTemplate(models.Model):
_inherit = "account.tax.template"
def write(self, vals):
FptTemplate = self.env["account.fiscal.position.tax.template"]
if "active" in vals and not vals.get("active"):
# Disable account.tax.template should disable
# account.fiscal.position.tax.template associated
fptTemplates = FptTemplate.search([
"|",
("tax_src_id", "in", self.ids),
("tax_dest_id", "in", self.ids),
])
fptTemplates.write({"active": False})
return super().write(vals)

View File

@ -0,0 +1 @@
* Sylvain LE GAL <https://twitter.com/legalsylvain>

View File

@ -0,0 +1,40 @@
This module allows to disable account template items, adding
an ``active`` field on the following models:
* ``account.account.template``
.. figure:: ../static/description/account_account_template_tree.png
* ``account.fiscal.position.template`` and it two related models
* ``account.fiscal.position.account.template``
* ``account.fiscal.position.tax.template``
.. figure:: ../static/description/account_fiscal_position_template_form.png
This module can be interesting in a multi company context,
if you install a lot of accounting templates, with some changes.
It can also be interesting if you want to developp a custom localization
module based on the official one, but with some removed / added / altered items.
**Note:**
* The field ``active`` is present in the Odoo ``account`` module for the model
``account.tax.template``. for that field, this module only adds the ``active``
field on the tree view.
.. figure:: ../static/description/account_tax_template_tree.png
For consistency reason,
* if user disables an ``account.account.template`` it will disable the related
``account.fiscal.position.account.template``
* if user disables an ``account.tax.template`` it will disable the related
``account.fiscal.position.tax.template``
* if user enables an ``account.fiscal.position.account.template`` it will enable the
related ``account.account.template``
* if user enables an ``account.fiscal.position.tax.template`` it will enable the
related ``account.tax.template``

View File

@ -0,0 +1,7 @@
* Go to Configuration > Templates
* Select then the template you want to change.
**Note:**
You could need the OCA module ``account_menu`` (same repository) to
access to some of the items.

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

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

View File

@ -0,0 +1,75 @@
# Copyright (C) 2020 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
class TestModule(TransactionCase):
def setUp(self):
super().setUp()
self.ACTemplate = self.env["account.chart.template"]
self.AATemplate = self.env["account.account.template"]
self.ATTemplate = self.env["account.tax.template"]
self.AFPTemplate = self.env["account.fiscal.position.template"]
self.AFPATemplate =\
self.env["account.fiscal.position.account.template"]
self.AFPTTemplate = self.env["account.fiscal.position.tax.template"]
self.receivable_type = self.env.ref(
"account.data_account_type_receivable")
self.template = self.ACTemplate.create({
"name": "Chart of Account",
"bank_account_code_prefix": "BNK",
"cash_account_code_prefix": "CSH",
"transfer_account_code_prefix": "TRSF",
"currency_id": self.env.ref("base.EUR").id,
})
self.account_template = self.AATemplate.create({
"name": "Account Template",
"code": "CODE",
"user_type_id": self.receivable_type.id,
"chart_template_id": self.template.id,
})
self.tax_template = self.ATTemplate.create({
"name": "Tax Template",
"chart_template_id": self.template.id,
"amount": 10.0,
})
self.fiscal_position = self.AFPTemplate.create({
"name": "Fiscal Position",
"chart_template_id": self.template.id,
})
self.fiscal_position_account = self.AFPATemplate.create({
"account_src_id": self.account_template.id,
"account_dest_id": self.account_template.id,
"position_id": self.fiscal_position.id,
})
self.fiscal_position_tax = self.AFPTTemplate.create({
"tax_src_id": self.tax_template.id,
"position_id": self.fiscal_position.id,
})
def test_tax_template(self):
self.tax_template.active = False
self.assertEqual(
self.fiscal_position_tax.active, False,
"Disable Tax template should disable Fiscal Position Tax")
self.fiscal_position_tax.active = True
self.assertEqual(
self.tax_template.active, True,
"Enable Fiscal Position Tax should enable Tax Template")
def test_account_template(self):
self.account_template.active = False
self.assertEqual(
self.fiscal_position_account.active, False,
"Disable Account template should disable Fiscal Position Account")
self.fiscal_position_account.active = True
self.assertEqual(
self.account_template.active, True,
"Enable Fiscal Position Account should enable Account Template")

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
@author: Quentin DUPONT <quentin.dupont@grap.coop>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="view_account_account_template_tree" model="ir.ui.view">
<field name="model">account.account.template</field>
<field name="inherit_id" ref="account.view_account_template_tree" />
<field name="arch" type="xml">
<xpath expr="//tree" position="attributes">
<attribute name="decoration-muted">not active</attribute>
</xpath>
<field name="user_type_id" position="after">
<field name="active" widget="boolean_toggle"/>
</field>
</field>
</record>
<record id="view_account_account_template_form" model="ir.ui.view">
<field name="model">account.account.template</field>
<field name="inherit_id" ref="account.view_account_template_form" />
<field name="arch" type="xml">
<field name="chart_template_id" position="after">
<field name="active"/>
</field>
</field>
</record>
<record id="account.action_account_template_form" model="ir.actions.act_window">
<field name="context">{"active_test": False}</field>
</record>
</odoo>

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
@author: Quentin DUPONT <quentin.dupont@grap.coop>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="view_account_fiscal_position_template_tree" model="ir.ui.view">
<field name="model">account.fiscal.position.template</field>
<field name="inherit_id" ref="account.view_account_position_template_tree" />
<field name="arch" type="xml">
<xpath expr="//tree" position="attributes">
<attribute name="decoration-muted">not active</attribute>
</xpath>
<field name="name" position="after">
<field name="active" widget="boolean_toggle"/>
</field>
</field>
</record>
<record id="view_account_fiscal_position_template_form" model="ir.ui.view">
<field name="model">account.fiscal.position.template</field>
<field name="inherit_id" ref="account.view_account_position_template_form" />
<field name="arch" type="xml">
<field name="chart_template_id" position="after">
<field name="active"/>
</field>
<xpath expr="//field[@name='tax_ids']/tree" position="attributes">
<attribute name="decoration-muted">not active</attribute>
</xpath>
<xpath expr="//field[@name='tax_ids']/tree/field[@name='tax_dest_id']" position="after">
<field name="active" widget="boolean_toggle"/>
</xpath>
<xpath expr="//field[@name='tax_ids']/form/field[@name='tax_dest_id']" position="after">
<field name="active"/>
</xpath>
<xpath expr="//field[@name='account_ids']/tree/field[@name='account_dest_id']" position="after">
<field name="active" widget="boolean_toggle"/>
</xpath>
<xpath expr="//field[@name='account_ids']/form/field[@name='account_dest_id']" position="after">
<field name="active"/>
</xpath>
</field>
</record>
<record id="account.action_account_fiscal_position_template_form" model="ir.actions.act_window">
<field name="context">{"active_test": False}</field>
</record>
</odoo>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2020 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="view_account_tax_template_tree" model="ir.ui.view">
<field name="model">account.tax.template</field>
<field name="inherit_id" ref="account.view_account_tax_template_tree"/>
<field name="arch" type="xml">
<xpath expr="//tree" position="attributes">
<attribute name="decoration-muted">not active</attribute>
</xpath>
<field name="description" position="after">
<field name="active" widget="boolean_toggle"/>
</field>
</field>
</record>
<record id="account.action_account_tax_template_form" model="ir.actions.act_window">
<field name="context">{"active_test": False}</field>
</record>
</odoo>