From ca68d56219736186220fdd67d7c4fff6147244a5 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 11 Dec 2020 16:38:12 +0100 Subject: [PATCH] [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. --- base_global_discount/__manifest__.py | 2 +- .../migrations/12.0.2.0.0/post_migrate.py | 10 ++++++++++ base_global_discount/models/res_partner.py | 12 ++++++++++++ base_global_discount/readme/CONFIGURE.rst | 1 + base_global_discount/readme/USAGE.rst | 3 ++- base_global_discount/security/ir.model.access.csv | 2 +- base_global_discount/security/security.xml | 5 ++++- base_global_discount/views/global_discount_views.xml | 7 +++++-- base_global_discount/views/res_partner_views.xml | 9 +++++++-- 9 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 base_global_discount/migrations/12.0.2.0.0/post_migrate.py diff --git a/base_global_discount/__manifest__.py b/base_global_discount/__manifest__.py index 28ae4418..e1cac3dd 100644 --- a/base_global_discount/__manifest__.py +++ b/base_global_discount/__manifest__.py @@ -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', ], diff --git a/base_global_discount/migrations/12.0.2.0.0/post_migrate.py b/base_global_discount/migrations/12.0.2.0.0/post_migrate.py new file mode 100644 index 00000000..141c2f62 --- /dev/null +++ b/base_global_discount/migrations/12.0.2.0.0/post_migrate.py @@ -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 diff --git a/base_global_discount/models/res_partner.py b/base_global_discount/models/res_partner.py index 16a25aca..ee9c87a0 100644 --- a/base_global_discount/models/res_partner.py +++ b/base_global_discount/models/res_partner.py @@ -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, + ) diff --git a/base_global_discount/readme/CONFIGURE.rst b/base_global_discount/readme/CONFIGURE.rst index 0e5cea40..bb80f62d 100644 --- a/base_global_discount/readme/CONFIGURE.rst +++ b/base_global_discount/readme/CONFIGURE.rst @@ -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. diff --git a/base_global_discount/readme/USAGE.rst b/base_global_discount/readme/USAGE.rst index 8d9135e4..0750fc83 100644 --- a/base_global_discount/readme/USAGE.rst +++ b/base_global_discount/readme/USAGE.rst @@ -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. diff --git a/base_global_discount/security/ir.model.access.csv b/base_global_discount/security/ir.model.access.csv index 33fcbd8f..e6e0d9fa 100644 --- a/base_global_discount/security/ir.model.access.csv +++ b/base_global_discount/security/ir.model.access.csv @@ -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 diff --git a/base_global_discount/security/security.xml b/base_global_discount/security/security.xml index 7adb4ae9..42fd4950 100644 --- a/base_global_discount/security/security.xml +++ b/base_global_discount/security/security.xml @@ -12,5 +12,8 @@ - + + Manage Global Discounts + + diff --git a/base_global_discount/views/global_discount_views.xml b/base_global_discount/views/global_discount_views.xml index 3023274e..4a293a51 100644 --- a/base_global_discount/views/global_discount_views.xml +++ b/base_global_discount/views/global_discount_views.xml @@ -41,9 +41,12 @@ tree,form - + sequence="1" parent="base.menu_ir_property" + groups="base_global_discount.group_global_discount" + /> diff --git a/base_global_discount/views/res_partner_views.xml b/base_global_discount/views/res_partner_views.xml index be4aae3a..ec40ca40 100644 --- a/base_global_discount/views/res_partner_views.xml +++ b/base_global_discount/views/res_partner_views.xml @@ -8,11 +8,16 @@ - + - +