[IMP] base_global_discount: add specific security group

This way, it will be easier to decide who can set discount or not. The
current group scope is too broad.
This commit is contained in:
david
2020-12-11 16:38:12 +01:00
parent ec3123c72b
commit ca68d56219
9 changed files with 43 additions and 8 deletions

View File

@@ -13,8 +13,8 @@
'product',
],
'data': [
'security/ir.model.access.csv',
'security/security.xml',
'security/ir.model.access.csv',
'views/global_discount_views.xml',
'views/res_partner_views.xml',
],

View File

@@ -0,0 +1,10 @@
# Copyright 2020 David Vidal
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from openupgradelib.openupgrade import migrate
@migrate()
def migrate(env, version):
"""Put all partner managers as global discount managers"""
users = env.ref("base.group_partner_manager").users
env.ref("base_global_discount.group_global_discount").users = users

View File

@@ -20,3 +20,15 @@ class ResPartner(models.Model):
string='Purchase Global Discounts',
domain=[('discount_scope', '=', 'purchase')],
)
# HACK: Looks like UI doesn't behave well with Many2many fields and
# negative groups when the same field is shown. In this case, we want to
# show the readonly version to any not in the global discount group.
# TODO: Check if it's fixed in future versions
customer_global_discount_ids_readonly = fields.Many2many(
related="customer_global_discount_ids",
readonly=True,
)
supplier_global_discount_ids_readonly = fields.Many2many(
related="customer_global_discount_ids",
readonly=True,
)

View File

@@ -1,5 +1,6 @@
To use this module, you need to:
#. Go to *Settings > Users*, choose yours and set *Manage Global Discounts*.
#. Go to *Settings > Parameters > Global Discounts*
#. Choose the discount scope (sales or purchases).
#. You can also restrict it to a certain company if needed.

View File

@@ -1,4 +1,5 @@
You can assign global discounts to partners as well:
You can assign global discounts to partners as well. You'll need the proper
permission (*Manage Global Discounts*):
#. Go to a partner that is a company.
#. Go to the *Sales & Purchases* tab.

View File

@@ -1,3 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_global_discount_user,Global Discount Users,model_global_discount,base.group_user,1,0,0,0
access_global_discount_partner_manager,Global Discount Partner Manager,model_global_discount,base.group_partner_manager,1,1,1,1
access_global_discount_manager,Global Discount Manager,model_global_discount,base_global_discount.group_global_discount,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_global_discount_user Global Discount Users model_global_discount base.group_user 1 0 0 0
3 access_global_discount_partner_manager access_global_discount_manager Global Discount Partner Manager Global Discount Manager model_global_discount base.group_partner_manager base_global_discount.group_global_discount 1 1 1 1

View File

@@ -12,5 +12,8 @@
<field name="perm_write" eval="1"/>
<field name="perm_unlink" eval="1"/>
</record>
<record id="group_global_discount" model="res.groups">
<field name="name">Manage Global Discounts</field>
<field name="category_id" ref="base.module_category_hidden"/>
</record>
</odoo>

View File

@@ -41,9 +41,12 @@
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_global_discount"
<menuitem
id="menu_global_discount"
action="action_global_discount_tree"
name="Global Discounts"
sequence="1" parent="base.menu_ir_property"/>
sequence="1" parent="base.menu_ir_property"
groups="base_global_discount.group_global_discount"
/>
</odoo>

View File

@@ -8,11 +8,16 @@
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<group name="sale" position="inside">
<field name="customer_global_discount_ids" widget="many2many_tags"
<field name="customer_global_discount_ids" widget="many2many_tags" groups="base_global_discount.group_global_discount"
attrs="{'invisible': [('customer', '=', False), ('is_company', '=', False), ('parent_id', '!=', False)]}"/>
<field name="customer_global_discount_ids_readonly" widget="many2many_tags"
groups="!base_global_discount.group_global_discount"
attrs="{'invisible': [('customer', '=', False), ('is_company', '=', False), ('parent_id', '!=', False)]}"/>
</group>
<group name="purchase" position="inside">
<field name="supplier_global_discount_ids" widget="many2many_tags"
<field name="supplier_global_discount_ids" widget="many2many_tags" groups="base_global_discount.group_global_discount"
attrs="{'invisible': [('supplier', '=', False), ('is_company', '=', False), ('parent_id', '!=', False)]}"/>
<field name="supplier_global_discount_ids" widget="many2many_tags" groups="!base_global_discount.group_global_discount"
attrs="{'invisible': [('supplier', '=', False), ('is_company', '=', False), ('parent_id', '!=', False)]}"/>
</group>
</field>