From f4400be75d9d97d607d2733e8589b1c7f3577bf3 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. [UPD] Update base_global_discount.pot --- base_global_discount/README.rst | 4 +++- base_global_discount/__manifest__.py | 2 +- .../i18n/base_global_discount.pot | 19 +++++++++++++++++++ base_global_discount/models/res_partner.py | 14 ++++++++++++++ base_global_discount/readme/CONFIGURE.rst | 1 + base_global_discount/readme/USAGE.rst | 3 ++- .../security/ir.model.access.csv | 2 +- base_global_discount/security/security.xml | 4 ++++ .../views/global_discount_views.xml | 1 + .../views/res_partner_views.xml | 17 +++++++++++++++++ 10 files changed, 63 insertions(+), 4 deletions(-) diff --git a/base_global_discount/README.rst b/base_global_discount/README.rst index 3996ceef4..17cbdba7d 100644 --- a/base_global_discount/README.rst +++ b/base_global_discount/README.rst @@ -39,6 +39,7 @@ Configuration 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. @@ -46,7 +47,8 @@ To use this module, you need to: Usage ===== -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/__manifest__.py b/base_global_discount/__manifest__.py index c16fc614d..67dc352d3 100644 --- a/base_global_discount/__manifest__.py +++ b/base_global_discount/__manifest__.py @@ -10,8 +10,8 @@ "license": "AGPL-3", "depends": ["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/i18n/base_global_discount.pot b/base_global_discount/i18n/base_global_discount.pot index 58ce06fc7..52e6ea435 100644 --- a/base_global_discount/i18n/base_global_discount.pot +++ b/base_global_discount/i18n/base_global_discount.pot @@ -91,12 +91,24 @@ msgstr "" msgid "Last Updated on" msgstr "" +#. module: base_global_discount +#: model:res.groups,name:base_global_discount.group_global_discount +msgid "Manage Global Discounts" +msgstr "" + #. module: base_global_discount #: model:ir.model.fields,field_description:base_global_discount.field_res_partner__supplier_global_discount_ids #: model:ir.model.fields,field_description:base_global_discount.field_res_users__supplier_global_discount_ids +#: model_terms:ir.ui.view,arch_db:base_global_discount.res_partner_form_view msgid "Purchase Global Discounts" msgstr "" +#. module: base_global_discount +#: model:ir.model.fields,field_description:base_global_discount.field_res_partner__supplier_global_discount_ids_readonly +#: model:ir.model.fields,field_description:base_global_discount.field_res_users__supplier_global_discount_ids_readonly +msgid "Purchase Global Discounts (readonly)" +msgstr "" + #. module: base_global_discount #: model:ir.model.fields.selection,name:base_global_discount.selection__global_discount__discount_scope__purchase msgid "Purchases" @@ -105,9 +117,16 @@ msgstr "" #. module: base_global_discount #: model:ir.model.fields,field_description:base_global_discount.field_res_partner__customer_global_discount_ids #: model:ir.model.fields,field_description:base_global_discount.field_res_users__customer_global_discount_ids +#: model_terms:ir.ui.view,arch_db:base_global_discount.res_partner_form_view msgid "Sale Global Discounts" msgstr "" +#. module: base_global_discount +#: model:ir.model.fields,field_description:base_global_discount.field_res_partner__customer_global_discount_ids_readonly +#: model:ir.model.fields,field_description:base_global_discount.field_res_users__customer_global_discount_ids_readonly +msgid "Sale Global Discounts (readonly)" +msgstr "" + #. module: base_global_discount #: model:ir.model.fields.selection,name:base_global_discount.selection__global_discount__discount_scope__sale msgid "Sales" diff --git a/base_global_discount/models/res_partner.py b/base_global_discount/models/res_partner.py index 1a01b9929..5f504bf2e 100644 --- a/base_global_discount/models/res_partner.py +++ b/base_global_discount/models/res_partner.py @@ -22,3 +22,17 @@ 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 in v14 if it's fixed + customer_global_discount_ids_readonly = fields.Many2many( + string="Sale Global Discounts (readonly)", + related="customer_global_discount_ids", + readonly=True, + ) + supplier_global_discount_ids_readonly = fields.Many2many( + string="Purchase Global Discounts (readonly)", + related="supplier_global_discount_ids", + readonly=True, + ) diff --git a/base_global_discount/readme/CONFIGURE.rst b/base_global_discount/readme/CONFIGURE.rst index 0e5cea40e..bb80f62da 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 5615b886b..079332b79 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 33fcbd8f6..e6e0d9faa 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 eeb722c61..234c7c0ed 100644 --- a/base_global_discount/security/security.xml +++ b/base_global_discount/security/security.xml @@ -13,4 +13,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 5cf4e77a6..fd22e9257 100644 --- a/base_global_discount/views/global_discount_views.xml +++ b/base_global_discount/views/global_discount_views.xml @@ -42,5 +42,6 @@ name="Global Discounts" 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 78ec97de4..4b64c4928 100644 --- a/base_global_discount/views/res_partner_views.xml +++ b/base_global_discount/views/res_partner_views.xml @@ -10,6 +10,14 @@ + @@ -17,6 +25,15 @@ +