Browse Source

Apr 19 : [UPDT] Updated 'hide_menu_user'

pull/275/head
AjmalCybro 2 years ago
parent
commit
c86003709e
  1. 1
      hide_menu_user/README.rst
  2. 3
      hide_menu_user/__init__.py
  3. 14
      hide_menu_user/__manifest__.py
  4. 7
      hide_menu_user/doc/RELEASE_NOTES.md
  5. 4
      hide_menu_user/models/__init__.py
  6. 28
      hide_menu_user/models/res_user.py
  7. 30
      hide_menu_user/models/restrict_menu.py
  8. 2
      hide_menu_user/security/ir.model.access.csv
  9. 3
      hide_menu_user/security/security.xml
  10. BIN
      hide_menu_user/static/description/images/003.png
  11. BIN
      hide_menu_user/static/description/images/1.png
  12. BIN
      hide_menu_user/static/description/images/14.png
  13. BIN
      hide_menu_user/static/description/images/2.png
  14. BIN
      hide_menu_user/static/description/images/4.png
  15. BIN
      hide_menu_user/static/description/images/6.png
  16. BIN
      hide_menu_user/static/description/images/7.png
  17. BIN
      hide_menu_user/static/description/images/8.png
  18. BIN
      hide_menu_user/static/description/images/9.png
  19. 232
      hide_menu_user/static/description/index.html
  20. 5
      hide_menu_user/views/res_users.xml
  21. 23
      hide_menu_user/wizard/__init__.py
  22. 28
      hide_menu_user/wizard/import__menu_list_views.xml
  23. 71
      hide_menu_user/wizard/import_menu_list.py

1
hide_menu_user/README.rst

@ -21,7 +21,6 @@ Credits
* Developer:
(v14) Sreerag @ Cybrosys
Contacts
--------
* Mail Contact : odoo@cybrosys.com

3
hide_menu_user/__init__.py

@ -3,7 +3,7 @@
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Copyright (C) 2022-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
@ -21,3 +21,4 @@
#############################################################################
from . import models
from . import wizard

14
hide_menu_user/__manifest__.py

@ -3,7 +3,7 @@
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Copyright (C) 2022-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
@ -22,7 +22,8 @@
{
'name': 'Hide Any Menu User Wise',
'version': '14.0.1.0.1',
'version': '14.0.1.1.1',
'category': 'Extra Tools',
'summary': 'Hide Any Menu Item User Wise',
'description': 'Hide Any Menu Item User Wise, Hide Menu Items, Hide Menu',
'author': 'Cybrosys Techno Solutions',
@ -31,9 +32,16 @@
'website': "https://www.cybrosys.com",
'depends': ['base'],
'data': [
'security/security.xml',
'security/ir.model.access.csv',
'views/res_users.xml',
'security/security.xml'
'wizard/import__menu_list_views.xml',
],
"external_dependencies": {
"python": [
"openpyxl",
],
},
'license': 'LGPL-3',
'images': ['static/description/banner.png'],
'installable': True,

7
hide_menu_user/doc/RELEASE_NOTES.md

@ -1,9 +1,10 @@
## Module <hide_menu_user>
#### 15.07.2021
#### Version 14.0.1.0.0
#### ADD
- Initial commit for hide_menu_user
### 24.02.2023
### Version 14.0.1.1.1
### ADD
- Added a new feature, to import the list of hide specific menus

4
hide_menu_user/models/__init__.py

@ -3,7 +3,7 @@
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Copyright (C) 2022-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
@ -19,5 +19,5 @@
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from . import res_user
from . import restrict_menu

28
hide_menu_user/models/res_user.py

@ -3,7 +3,7 @@
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Copyright (C) 2022-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
@ -22,15 +22,16 @@
from odoo import models, fields, api
class HideMenuUser(models.Model):
""" Inherited Users"""
_inherit = 'res.users'
@api.model_create_multi
def create(self, vals_list):
@api.model
def create(self, vals):
"""
Else the menu will be still hidden even after removing from the list
"""
for vals in vals_list:
self.clear_caches()
return super(HideMenuUser, self).create(vals)
@ -43,7 +44,6 @@ class HideMenuUser(models.Model):
menu.write({
'restrict_user_ids': [(4, self.id)]
})
print(res,'resssssssssss')
self.clear_caches()
return res
@ -62,7 +62,17 @@ class HideMenuUser(models.Model):
'hidden to this user ')
is_admin = fields.Boolean(compute=_get_is_admin)
class RestrictMenu(models.Model):
_inherit = 'ir.ui.menu'
restrict_user_ids = fields.Many2many('res.users')
def action_import(self):
"""This function will open a wizard where you can select the file which want to be import"""
wizard = self.env['import.menu.list.wizard'].create({
'name': self.name,
'user_id': self.id
})
return {
'name': 'Wizard',
'type': 'ir.actions.act_window',
'res_model': 'import.menu.list.wizard',
'view_mode': 'form',
'res_id': wizard.id,
'target': 'new'
}

30
hide_menu_user/models/restrict_menu.py

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2022-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from odoo import models, fields
class RestrictMenu(models.Model):
""" Inherited Menu Items"""
_inherit = 'ir.ui.menu'
restrict_user_ids = fields.Many2many('res.users', store=True)

2
hide_menu_user/security/ir.model.access.csv

@ -0,0 +1,2 @@
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_import_menu_list_wizard,access_import_menu_list_wizard,model_import_menu_list_wizard,base.group_user,1,1,1,1
1 id name model_id/id group_id/id perm_read perm_write perm_create perm_unlink
2 access_import_menu_list_wizard access_import_menu_list_wizard model_import_menu_list_wizard base.group_user 1 1 1 1

3
hide_menu_user/security/security.xml

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="restrict_menu_user" model="ir.rule">
<field name="name">Restrict Menu from Users</field>
<field ref="model_ir_ui_menu" name="model_id"/>
<field name="domain_force">[('restrict_user_ids','not in',user.id)]</field>
</record>
</odoo>

BIN
hide_menu_user/static/description/images/003.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

BIN
hide_menu_user/static/description/images/1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

BIN
hide_menu_user/static/description/images/14.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

BIN
hide_menu_user/static/description/images/2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

BIN
hide_menu_user/static/description/images/4.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

BIN
hide_menu_user/static/description/images/6.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

BIN
hide_menu_user/static/description/images/7.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

BIN
hide_menu_user/static/description/images/8.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

BIN
hide_menu_user/static/description/images/9.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

232
hide_menu_user/static/description/index.html

@ -126,25 +126,27 @@
style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">
<!-- endo of img -->
<!-- img -->
<div class="d-flex m-0" style="border-bottom: 1px solid #e5e5e5 !important;">
<div class="mr-3">
<h3
style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">
03</h3>
04</h3>
</div>
<div>
<h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">
Hiding the menu
Select the menu
</h3>
<p
style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">
Let's select these menu for this user 'Mark Demo'
Select those menus and save
</p>
</div>
</div>
<img src="./images/screenshot-3.png" class="img-responsive border"
<img src="./images/screenshot-4.png" class="img-responsive border"
style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">
<!-- endo of img -->
@ -153,20 +155,20 @@
<div class="mr-3">
<h3
style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">
04</h3>
05</h3>
</div>
<div>
<h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">
Select the menu
Menus are Hidden
</h3>
<p
style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">
Select those menus and save
As you can see the menus and corresponding views are now hidden for the user
</p>
</div>
</div>
<img src="./images/screenshot-4.png" class="img-responsive border"
<img src="./images/screenshot-5.png" class="img-responsive border"
style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">
<!-- endo of img -->
@ -175,21 +177,44 @@
<div class="mr-3">
<h3
style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">
05</h3>
06</h3>
</div>
<div>
<h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">
Menus are Hidden
Option hidden for Admin user
</h3>
<p
style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">
As you can see the menus and corresponding views are now hidden for the user
Option to hide menu for an admin user is disabled as this may create issues in the
workflow
</p>
</div>
</div>
<img src="./images/screenshot-5.png" class="img-responsive border"
<img src="./images/screenshot-6.png" class="img-responsive border"
style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">
<!-- endo of img -->
<!-- img -->
<!-- <div class="d-flex m-0" style="border-bottom: 1px solid #e5e5e5 !important;">-->
<!-- <div class="mr-3">-->
<!-- <h3-->
<!-- style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">-->
<!-- 06</h3>-->
<!-- </div>-->
<!-- <div>-->
<!-- <h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">-->
<!-- Option hidden for Admin user-->
<!-- </h3>-->
<!-- <p-->
<!-- style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">-->
<!-- Option to hide menu for an admin user is disabled as this may create issues in the-->
<!-- workflow-->
<!-- </p>-->
<!-- </div>-->
<!-- </div>-->
<!-- <img src="./images/screenshot-3.png" class="img-responsive border"-->
<!-- style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">-->
<!-- endo of img -->
<!-- img -->
@ -197,21 +222,194 @@
<div class="mr-3">
<h3
style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">
06</h3>
07</h3>
</div>
<div>
<h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">
Option hidden for Admin user
Select Add a line option from the order line
</h3>
<p
style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">
Option to hide menu for an admin user is disabled as this may create issues in the
workflow
To export the list of menu, first we want to select the menus, for that click on add a line
</p>
</div>
</div>
<img src="./images/screenshot-6.png" class="img-responsive border"
<img src="./images/003.png" class="img-responsive border"
style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">
<!-- endo of img -->
<!-- img -->
<div class="d-flex m-0" style="border-bottom: 1px solid #e5e5e5 !important;">
<div class="mr-3">
<h3
style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">
08</h3>
</div>
<div>
<h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">
Select the menus that we want to export
</h3>
<p
style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">
From the list of menus, we can select the menu items that we want to export. After that
click on export option
</p>
</div>
</div>
<img src="./images/4.png" class="img-responsive border"
style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">
<!-- endo of img --> <!-- img -->
<div class="d-flex m-0" style="border-bottom: 1px solid #e5e5e5 !important;">
<div class="mr-3">
<h3
style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">
09</h3>
</div>
<div>
<h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">
Select the Parent Path to fields to export
</h3>
<p
style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">
From the left side of the window, we are able to select the fields that we want to export.
Don't forget to add the <strong>Parent Path </strong> to fields to export
</p>
</div>
</div>
<img src="./images/9.png" class="img-responsive border"
style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">
<!-- endo of img -->
<!-- img -->
<!-- <div class="d-flex m-0" style="border-bottom: 1px solid #e5e5e5 !important;">-->
<!-- <div class="mr-3">-->
<!-- <h3-->
<!-- style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">-->
<!-- 10</h3>-->
<!-- </div>-->
<!-- <div>-->
<!-- <h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">-->
<!-- Option hidden for Admin user-->
<!-- </h3>-->
<!-- <p-->
<!-- style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">-->
<!-- Option to hide menu for an admin user is disabled as this may create issues in the-->
<!-- workflow-->
<!-- </p>-->
<!-- </div>-->
<!-- </div>-->
<!-- <img src="./images/2.png" class="img-responsive border"-->
<!-- style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">-->
<!-- endo of img -->
<!-- img -->
<div class="d-flex m-0" style="border-bottom: 1px solid #e5e5e5 !important;">
<div class="mr-3">
<h3
style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">
10</h3>
</div>
<div>
<h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">
Click on export button
</h3>
<p
style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">
Now export the selected list of menu by clicking on Export button
</p>
</div>
</div>
<img src="./images/6.png" class="img-responsive border"
style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">
<!-- endo of img -->
<!-- img -->
<div class="d-flex m-0" style="border-bottom: 1px solid #e5e5e5 !important;">
<div class="mr-3">
<h3
style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">
11</h3>
</div>
<div>
<h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">
Select the User
</h3>
<p
style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">
Select the User to whom which we want to import the list of menus
</p>
</div>
</div>
<img src="./images/1.png" class="img-responsive border"
style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">
<!-- end of img -->
<!-- img -->
<div class="d-flex m-0" style="border-bottom: 1px solid #e5e5e5 !important;">
<div class="mr-3">
<h3
style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">
12</h3>
</div>
<div>
<h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">
Click on Import button
</h3>
<p
style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">
In the page 'Hide Specific Menu', you can see a Import button. click on that
</p>
</div>
</div>
<img src="./images/7.png" class="img-responsive border"
style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">
<!-- endo of img -->
<!-- img -->
<div class="d-flex m-0" style="border-bottom: 1px solid #e5e5e5 !important;">
<div class="mr-3">
<h3
style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">
13</h3>
</div>
<div>
<h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">
Upload the file
</h3>
<p
style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">
A wizard will open, and we are able to upload the file in xls format.Finally click on Import button
</p>
</div>
</div>
<img src="./images/8.png" class="img-responsive border"
style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">
<!-- endo of img -->
<!-- img -->
<div class="d-flex m-0" style="border-bottom: 1px solid #e5e5e5 !important;">
<div class="mr-3">
<h3
style="font-size: 2rem !important; font-weight: 800 !important; color: #ffffff !important; background-color: #AC1015 !important; padding: 1rem !important; width: 70px !important; height: 75px !important;">
14</h3>
</div>
<div>
<h3 style="font-size: 1.7rem !important; font-weight: 600 !important;">
Imported the menus
</h3>
<p
style="color: #212529 !important; font-size: 1.3rem !important; font-weight: 300 !important;">
List of menus are imported in the order line
</p>
</div>
</div>
<img src="./images/14.png" class="img-responsive border"
style="margin-top: -15px !important; margin-top: 1rem !important; margin-bottom: 4rem !important;">
<!-- endo of img -->
</div>

5
hide_menu_user/views/res_users.xml

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="hide_user_menu" model="ir.ui.view">
@ -7,6 +8,10 @@
<field name="arch" type="xml">
<xpath expr="//notebook" position="inside">
<page string="Hide Specific Menu" attrs="{'invisible': [('is_admin','=', True)]}">
<button string="import" type="object"
name="action_import" class="btn-primary"/>
<br/>
<br/>
<tree>
<field name="hide_menu_ids"/>
</tree>

23
hide_menu_user/wizard/__init__.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2022-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from . import import_menu_list

28
hide_menu_user/wizard/import__menu_list_views.xml

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="import_menu_list_wizard_view_form" model="ir.ui.view">
<field name="name">import.menu.list.form</field>
<field name="model">import.menu.list.wizard</field>
<field name="arch" type="xml">
<form string="Test">
<group class="oe_title">
<field name="name" readonly="1"/>
<field name="user_id" invisible="1"/>
<field name="import_file"/>
</group>
<footer>
<button name="action_import_xls" string="Import" type="object" class="oe_highlight"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="import_menu_list_wizard_action" model="ir.actions.act_window">
<field name="name">Import Menu List</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">import.menu.list.wizard</field>
<field name="view_mode">form</field>
<field name="view_id" ref="import_menu_list_wizard_view_form"/>
<field name="target">new</field>
</record>
</odoo>

71
hide_menu_user/wizard/import_menu_list.py

@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2022-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import base64
import openpyxl
from io import BytesIO
from odoo import models, fields, _
from odoo.exceptions import UserError
class OrderLinesWizard(models.TransientModel):
""" This class contain the fields of wizard and it will import the xslx file"""
_name = 'import.menu.list.wizard'
_description = "Import the menu list"
name = fields.Char(string="Name", Readonly=True)
import_file = fields.Binary(string="Upload Files", help="Select the xlsx file to import ")
user_id = fields.Integer(string="User Id")
def action_import_xls(self):
"""This function will help to import the Excel sheet"""
try:
wb = openpyxl.load_workbook(
filename=BytesIO(base64.b64decode(self.import_file)), read_only=True
)
ws = wb.active
except:
raise UserError(
_('Please insert a valid file'))
col = -1
flag = 0
for rec in ws.iter_rows(min_row=1, max_row=1, min_col=None, max_col=None, values_only=True):
for head in rec:
col = col + 1
if head == 'Parent Path':
flag = 1
break
if flag == 0:
raise UserError(
_('Please insert a parent path in the file'))
for record in ws.iter_rows(min_row=2, max_row=None, min_col=None, max_col=None, values_only=True):
menu_exist = self.env['ir.ui.menu'].search([('parent_path', '=', record[col])]).id
if not menu_exist:
raise UserError(
_('Please have valid parent path'))
res = {
'res_users_id': self.user_id,
'ir_ui_menu_id': menu_exist,
}
self.env['res.users'].search([('id', '=', res['res_users_id'])]).write(
{'hide_menu_ids': [(4, res['ir_ui_menu_id'])]})
Loading…
Cancel
Save