-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] new module account_fiscal_position_usage_group to restrict usag…
…e of fiscal position to some group members
- Loading branch information
1 parent
4a60d12
commit a715266
Showing
23 changed files
with
394 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# 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': 'Account Fiscal Position - Usage Group', | ||
'summary': 'Limit the usage of fiscal positions to defined groups members', | ||
'version': '12.0.1.0.0', | ||
'category': 'Accounting', | ||
'author': 'GRAP,Odoo Community Association (OCA)', | ||
'maintainers': ['legalsylvain'], | ||
'development_status': 'Beta', | ||
'website': 'https://github.com/OCA/account-fiscal-rule', | ||
'license': 'AGPL-3', | ||
'depends': [ | ||
'account_coa_menu', | ||
], | ||
'data': [ | ||
'views/view_account_fiscal_position.xml', | ||
'views/view_account_fiscal_position_template.xml', | ||
], | ||
'demo': [ | ||
'demo/res_groups.xml', | ||
'demo/account_fiscal_position.xml', | ||
], | ||
'installable': True, | ||
} |
21 changes: 21 additions & 0 deletions
21
account_fiscal_position_usage_group/demo/account_fiscal_position.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
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). | ||
--> | ||
|
||
<odoo> | ||
|
||
<record id="fiscal_position_everybody" model="account.fiscal.position"> | ||
<field name="name">Fiscal Position for everybody</field> | ||
<field name="company_id" ref="base.main_company"/> | ||
</record> | ||
|
||
<record id="fiscal_position_restricted" model="account.fiscal.position"> | ||
<field name="name">Fiscal Position Restricted</field> | ||
<field name="company_id" ref="base.main_company"/> | ||
<field name="usage_group_ids" eval="[(6, 0, [ref('demo_group_restricted')])]"/> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
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). | ||
--> | ||
<odoo> | ||
|
||
<record model="res.groups" id="account.group_account_user"> | ||
<field name="users" eval="[(6, 0, [ref('base.user_admin')])]"/> | ||
</record> | ||
|
||
<record model="res.groups" id="demo_group_restricted"> | ||
<field name="name">Demo Group Limited Access</field> | ||
</record> | ||
|
||
</odoo> |
58 changes: 58 additions & 0 deletions
58
account_fiscal_position_usage_group/i18n/account_fiscal_position_usage_group.pot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * account_fiscal_position_usage_group | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 12.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2019-11-19 10:29+0000\n" | ||
"PO-Revision-Date: 2019-11-19 10:29+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_fiscal_position_usage_group | ||
#: model:ir.model,name:account_fiscal_position_usage_group.model_res_partner | ||
msgid "Contact" | ||
msgstr "" | ||
|
||
#. module: account_fiscal_position_usage_group | ||
#: model:res.groups,name:account_fiscal_position_usage_group.demo_group_restricted | ||
msgid "Demo Group Limited Access" | ||
msgstr "" | ||
|
||
#. module: account_fiscal_position_usage_group | ||
#: model:ir.model,name:account_fiscal_position_usage_group.model_account_fiscal_position | ||
msgid "Fiscal Position" | ||
msgstr "" | ||
|
||
#. module: account_fiscal_position_usage_group | ||
#: model:ir.model.fields,help:account_fiscal_position_usage_group.field_account_fiscal_position__usage_group_ids | ||
msgid "If defined, the user should be member to one of there groups, to use this fiscal position when creating or updating a supplier, or an invoice" | ||
msgstr "" | ||
|
||
#. module: account_fiscal_position_usage_group | ||
#: model:ir.model,name:account_fiscal_position_usage_group.model_account_invoice | ||
msgid "Invoice" | ||
msgstr "" | ||
|
||
#. module: account_fiscal_position_usage_group | ||
#: model:ir.model.fields,field_description:account_fiscal_position_usage_group.field_account_fiscal_position__usage_group_ids | ||
msgid "Usage Groups" | ||
msgstr "" | ||
|
||
#. module: account_fiscal_position_usage_group | ||
#: code:addons/account_fiscal_position_usage_group/models/account_invoice.py:19 | ||
#: code:addons/account_fiscal_position_usage_group/models/res_partner.py:19 | ||
#, python-format | ||
msgid "You can not use the fiscal position '%s' because you're not a member of one of the following groups:\n" | ||
"\n" | ||
" - %s\n" | ||
"\n" | ||
"Please contact your accountant or the administrator." | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * account_fiscal_position_usage_group | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 12.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2019-11-19 10:30+0000\n" | ||
"PO-Revision-Date: 2019-11-19 10:30+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_fiscal_position_usage_group | ||
#: model:ir.model,name:account_fiscal_position_usage_group.model_res_partner | ||
msgid "Contact" | ||
msgstr "Contact" | ||
|
||
#. module: account_fiscal_position_usage_group | ||
#: model:res.groups,name:account_fiscal_position_usage_group.demo_group_restricted | ||
msgid "Demo Group Limited Access" | ||
msgstr "Groupe de démonstration à accès limité" | ||
|
||
#. module: account_fiscal_position_usage_group | ||
#: model:ir.model,name:account_fiscal_position_usage_group.model_account_fiscal_position | ||
msgid "Fiscal Position" | ||
msgstr "Position fiscale" | ||
|
||
#. module: account_fiscal_position_usage_group | ||
#: model:ir.model.fields,help:account_fiscal_position_usage_group.field_account_fiscal_position__usage_group_ids | ||
msgid "If defined, the user should be member to one of there groups, to use this fiscal position when creating or updating a supplier, or an invoice" | ||
msgstr "Si défini, l'utilisateur devra être membre de l'un de ces groupes, pour utiliser cette position fiscale, lors de la création ou de la modification d'un partenaire ou d'une facture." | ||
|
||
#. module: account_fiscal_position_usage_group | ||
#: model:ir.model,name:account_fiscal_position_usage_group.model_account_invoice | ||
msgid "Invoice" | ||
msgstr "Facture" | ||
|
||
#. module: account_fiscal_position_usage_group | ||
#: model:ir.model.fields,field_description:account_fiscal_position_usage_group.field_account_fiscal_position__usage_group_ids | ||
msgid "Usage Groups" | ||
msgstr "Groupes d'utilisation" | ||
|
||
#. module: account_fiscal_position_usage_group | ||
#: code:addons/account_fiscal_position_usage_group/models/account_invoice.py:19 | ||
#: code:addons/account_fiscal_position_usage_group/models/res_partner.py:19 | ||
#, python-format | ||
msgid "You can not use the fiscal position '%s' because you're not a member of one of the following groups:\n" | ||
"\n" | ||
" - %s\n" | ||
"\n" | ||
"Please contact your accountant or the administrator." | ||
msgstr "Vous ne pouvez pas utiliser cette position fiscale '%s' car vous n'êtes pas membre de l'un des groupes suivants:\n" | ||
"\n" | ||
" - %s\n" | ||
"\n" | ||
"Veuillez contacter votre comptable ou l'administrateur." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import account_fiscal_position | ||
from . import account_fiscal_position_template | ||
from . import account_invoice | ||
from . import res_partner |
14 changes: 14 additions & 0 deletions
14
account_fiscal_position_usage_group/models/account_fiscal_position.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# 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 AccountFiscalPosition(models.Model): | ||
_inherit = 'account.fiscal.position' | ||
|
||
usage_group_ids = fields.Many2many( | ||
comodel_name='res.groups', string="Usage Groups", help="If defined" | ||
", the user should be member to one of there groups, to use this" | ||
" fiscal position when creating or updating a supplier, or an invoice") |
14 changes: 14 additions & 0 deletions
14
account_fiscal_position_usage_group/models/account_fiscal_position_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# 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' | ||
|
||
usage_group_ids = fields.Many2many( | ||
comodel_name='res.groups', string="Usage Groups", help="If defined" | ||
", the user should be member to one of there groups, to use this" | ||
" fiscal position when creating or updating a supplier, or an invoice") |
26 changes: 26 additions & 0 deletions
26
account_fiscal_position_usage_group/models/account_invoice.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 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 _, api, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class AccountInvoice(models.Model): | ||
_inherit = 'account.invoice' | ||
|
||
@api.constrains("fiscal_position_id") | ||
def _check_access_fiscal_position(self): | ||
for invoice in self: | ||
groups = invoice.mapped( | ||
"fiscal_position_id.usage_group_ids") | ||
if groups and not any( | ||
[x in self.env.user.groups_id.ids for x in groups.ids]): | ||
raise ValidationError(_( | ||
"You can not use the fiscal position '%s' because" | ||
" you're not a member of one of the following groups:\n\n" | ||
" - %s" | ||
"\n\n" | ||
"Please contact your accountant or the administrator.") % ( | ||
invoice.fiscal_position_id.name, | ||
"\n- ".join(groups.mapped('name')))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 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 _, api, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = 'res.partner' | ||
|
||
@api.constrains("property_account_position_id") | ||
def _check_access_fiscal_position(self): | ||
for partner in self: | ||
groups = partner.mapped( | ||
"property_account_position_id.usage_group_ids") | ||
if groups and not any( | ||
[x in self.env.user.groups_id.ids for x in groups.ids]): | ||
raise ValidationError(_( | ||
"You can not use the fiscal position '%s' because" | ||
" you're not a member of one of the following groups:\n\n" | ||
" - %s" | ||
"\n\n" | ||
"Please contact your accountant or the administrator.") % ( | ||
partner.property_account_position_id.name, | ||
"\n- ".join(groups.mapped('name')))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
* To to "Invoicing" / "Configuration" / "Fiscal Positions" | ||
|
||
* Edit or create a new fiscal position and set groups whose members can | ||
use it. | ||
|
||
.. image:: ../static/description/fiscal_position_form.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Sylvain LE GAL (https://twitter.com/legalsylvain); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This module extends the Odoo Accounting module, to add the possibility to | ||
restrict usage of some fiscal positions to members of defined groups. | ||
|
||
Once set, a user will have a blocking message, if he does'nt belong to the | ||
correct group, when he creates or updates partners and invoices. | ||
|
||
.. image:: ../static/description/warning_access_limited.png |
Binary file added
BIN
+24.8 KB
...fiscal_position_usage_group/static/description/account_fiscal_position_form.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.1 KB
...sition_usage_group/static/description/account_fiscal_position_template_form.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.4 KB
account_fiscal_position_usage_group/static/description/warning_access_limited.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# 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.exceptions import ValidationError | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestModule(TransactionCase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.ResPartner = self.env['res.partner'] | ||
self.AccountInvoice = self.env['account.invoice'] | ||
|
||
self.fiscal_position_everybody = self.env.ref( | ||
'account_fiscal_position_usage_group.fiscal_position_everybody') | ||
self.fiscal_position_restricted = self.env.ref( | ||
'account_fiscal_position_usage_group.fiscal_position_restricted') | ||
self.demo_group_restricted = self.env.ref( | ||
'account_fiscal_position_usage_group.demo_group_restricted') | ||
self.partner_vals = { | ||
'name': 'Demo', | ||
} | ||
self.invoice_vals = { | ||
'partner_id': self.env.ref("base.res_partner_2").id, | ||
} | ||
|
||
# Test Section | ||
def test_01_create_partner_with_non_restricted_position(self): | ||
self.partner_vals.update({ | ||
'property_account_position_id': self.fiscal_position_everybody.id, | ||
}) | ||
self.ResPartner.create(self.partner_vals) | ||
|
||
def test_02_create_partner_with_restricted_position_forbidden(self): | ||
self.partner_vals.update({ | ||
'property_account_position_id': self.fiscal_position_restricted.id, | ||
}) | ||
# Should fail if current user is not member of the group | ||
with self.assertRaises(ValidationError): | ||
self.ResPartner.create(self.partner_vals) | ||
|
||
def test_03_create_partner_with_restricted_position_allowed(self): | ||
self.partner_vals.update({ | ||
'property_account_position_id': self.fiscal_position_restricted.id, | ||
}) | ||
# Should success if current user is member of the group | ||
self.demo_group_restricted.users = [self.env.user.id] | ||
self.ResPartner.create(self.partner_vals) | ||
|
||
def test_04_create_invoice_with_non_restricted_position(self): | ||
self.invoice_vals.update({ | ||
'fiscal_position_id': self.fiscal_position_everybody.id, | ||
}) | ||
self.AccountInvoice.create(self.invoice_vals) | ||
|
||
def test_05_create_invoice_with_restricted_position_forbidden(self): | ||
self.invoice_vals.update({ | ||
'fiscal_position_id': self.fiscal_position_restricted.id, | ||
}) | ||
# Should fail if current user is not member of the group | ||
with self.assertRaises(ValidationError): | ||
self.AccountInvoice.create(self.invoice_vals) | ||
|
||
def test_06_create_invoice_with_restricted_position_allowed(self): | ||
self.invoice_vals.update({ | ||
'fiscal_position_id': self.fiscal_position_restricted.id, | ||
}) | ||
# Should success if current user is member of the group | ||
self.demo_group_restricted.users = [self.env.user.id] | ||
self.AccountInvoice.create(self.invoice_vals) |
19 changes: 19 additions & 0 deletions
19
account_fiscal_position_usage_group/views/view_account_fiscal_position.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
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). | ||
--> | ||
<odoo> | ||
|
||
<record id="view_account_fiscal_position_form" model="ir.ui.view"> | ||
<field name="model">account.fiscal.position</field> | ||
<field name="inherit_id" ref="account.view_account_position_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="name" position="after"> | ||
<field name="usage_group_ids" widget="many2many_tags"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
Oops, something went wrong.