Skip to content

Commit

Permalink
Merge PR #99 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
OCA-git-bot committed Mar 13, 2020
2 parents 4a60d12 + a715266 commit b2a473c
Show file tree
Hide file tree
Showing 23 changed files with 394 additions and 0 deletions.
Empty file.
1 change: 1 addition & 0 deletions account_fiscal_position_usage_group/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
27 changes: 27 additions & 0 deletions account_fiscal_position_usage_group/__manifest__.py
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,
}
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>
17 changes: 17 additions & 0 deletions account_fiscal_position_usage_group/demo/res_groups.xml
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>
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 ""

61 changes: 61 additions & 0 deletions account_fiscal_position_usage_group/i18n/fr.po
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."
4 changes: 4 additions & 0 deletions account_fiscal_position_usage_group/models/__init__.py
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
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")
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 account_fiscal_position_usage_group/models/account_invoice.py
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'))))
26 changes: 26 additions & 0 deletions account_fiscal_position_usage_group/models/res_partner.py
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'))))
6 changes: 6 additions & 0 deletions account_fiscal_position_usage_group/readme/CONFIGURE.rst
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sylvain LE GAL (https://twitter.com/legalsylvain);
7 changes: 7 additions & 0 deletions account_fiscal_position_usage_group/readme/DESCRIPTION.rst
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
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.
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.
1 change: 1 addition & 0 deletions account_fiscal_position_usage_group/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_module
72 changes: 72 additions & 0 deletions account_fiscal_position_usage_group/tests/test_module.py
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)
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>

0 comments on commit b2a473c

Please sign in to comment.