[REF] web_easy_switch_company. use new API ; new readme syntax ; add image description
[IMP] Add new setting to have the choice to go the home page, or to keep to the current viewpull/1129/head
-
42web_easy_switch_company/README.rst
-
24web_easy_switch_company/__init__.py
-
67web_easy_switch_company/__openerp__.py
-
23web_easy_switch_company/controllers/__init__.py
-
26web_easy_switch_company/controllers/main.py
-
9web_easy_switch_company/data/ir_config_parameter.xml
-
9web_easy_switch_company/demo/res_company.xml
-
9web_easy_switch_company/demo/res_groups.xml
-
11web_easy_switch_company/demo/res_groups.yml
-
9web_easy_switch_company/demo/res_users.xml
-
57web_easy_switch_company/model/res_company.py
-
31web_easy_switch_company/model/res_users.py
-
3web_easy_switch_company/models/__init__.py
-
25web_easy_switch_company/models/res_company.py
-
14web_easy_switch_company/models/res_users.py
-
8web_easy_switch_company/readme/CONFIGURE.rst
-
1web_easy_switch_company/readme/CONTRIBUTORS.rst
-
9web_easy_switch_company/readme/DESCRIPTION.rst
-
1web_easy_switch_company/readme/ROADMAP.rst
-
2web_easy_switch_company/readme/USAGE.rst
-
BINweb_easy_switch_company/static/description/switch_company_menu.png
-
4web_easy_switch_company/static/src/css/switch_company.css
-
0web_easy_switch_company/static/src/img/selection-off.png
-
0web_easy_switch_company/static/src/img/selection-on.png
-
94web_easy_switch_company/static/src/js/switch_company.js
-
25web_easy_switch_company/static/src/xml/switch_company.xml
-
25web_easy_switch_company/view/res_users_view.xml
-
11web_easy_switch_company/views/templates.xml
-
16web_easy_switch_company/views/view_res_users.xml
@ -0,0 +1,42 @@ |
|||
**This file is going to be generated by oca-gen-addon-readme.** |
|||
|
|||
*Manual changes will be overwritten.* |
|||
|
|||
Please provide content in the ``readme`` directory: |
|||
|
|||
* **DESCRIPTION.rst** (required) |
|||
* INSTALL.rst (optional) |
|||
* CONFIGURE.rst (optional) |
|||
* **USAGE.rst** (optional, highly recommended) |
|||
* DEVELOP.rst (optional) |
|||
* ROADMAP.rst (optional) |
|||
* HISTORY.rst (optional, recommended) |
|||
* **CONTRIBUTORS.rst** (optional, highly recommended) |
|||
* CREDITS.rst (optional) |
|||
|
|||
Content of this README will also be drawn from the addon manifest, |
|||
from keys such as name, authors, maintainers, development_status, |
|||
and license. |
|||
|
|||
A good, one sentence summary in the manifest is also highly recommended. |
|||
**This file is going to be generated by oca-gen-addon-readme.** |
|||
|
|||
*Manual changes will be overwritten.* |
|||
|
|||
Please provide content in the ``readme`` directory: |
|||
|
|||
* **DESCRIPTION.rst** (required) |
|||
* INSTALL.rst (optional) |
|||
* CONFIGURE.rst (optional) |
|||
* **USAGE.rst** (optional, highly recommended) |
|||
* DEVELOP.rst (optional) |
|||
* ROADMAP.rst (optional) |
|||
* HISTORY.rst (optional, recommended) |
|||
* **CONTRIBUTORS.rst** (optional, highly recommended) |
|||
* CREDITS.rst (optional) |
|||
|
|||
Content of this README will also be drawn from the addon manifest, |
|||
from keys such as name, authors, maintainers, development_status, |
|||
and license. |
|||
|
|||
A good, one sentence summary in the manifest is also highly recommended. |
@ -1,23 +1,3 @@ |
|||
# -*- encoding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Web Easy Switch Company module for OpenERP |
|||
# Copyright (C) 2014 GRAP (http://www.grap.coop) |
|||
# @author Sylvain LE GAL (https://twitter.com/legalsylvain) |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# 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 Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from . import model |
|||
# coding: utf-8 |
|||
from . import models |
|||
from . import controllers |
@ -1,23 +1,2 @@ |
|||
# -*- encoding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Web Easy Switch Company module for OpenERP |
|||
# Copyright (C) 2014 GRAP (http://www.grap.coop) |
|||
# @author Sylvain LE GAL (https://twitter.com/legalsylvain) |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# 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 Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
# coding: utf-8 |
|||
from . import main |
@ -0,0 +1,9 @@ |
|||
<?xml version='1.0' encoding='UTF-8' ?> |
|||
<openerp><data noupdate="1"> |
|||
|
|||
<record id="keep_url" model="ir.config_parameter"> |
|||
<field name="key">web_easy_switch_company.keep_url</field> |
|||
<field name="value">False</field> |
|||
</record> |
|||
|
|||
</data></openerp> |
@ -0,0 +1,9 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
|
|||
<openerp><data> |
|||
|
|||
<record id="other_company" model="res.company"> |
|||
<field name="name">Other Company</field> |
|||
</record> |
|||
|
|||
</data></openerp> |
@ -0,0 +1,9 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
|
|||
<openerp><data> |
|||
|
|||
<record id="base.group_multi_company" model="res.groups"> |
|||
<field name="users" eval="[(4, ref('base.user_root'))]" /> |
|||
</record> |
|||
|
|||
</data></openerp> |
@ -0,0 +1,9 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
|
|||
<openerp><data> |
|||
|
|||
<record id="base.user_root" model="res.users"> |
|||
<field name="company_ids" eval="[(4, ref('other_company'))]" /> |
|||
</record> |
|||
|
|||
</data></openerp> |
@ -1,57 +0,0 @@ |
|||
# -*- encoding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Web Easy Switch Company module for OpenERP |
|||
# Copyright (C) 2014 GRAP (http://www.grap.coop) |
|||
# @author Sylvain LE GAL (https://twitter.com/legalsylvain) |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# 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 Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
from openerp.osv import fields |
|||
from openerp.osv.orm import Model |
|||
from openerp.tools import image_resize_image |
|||
|
|||
|
|||
class res_company(Model): |
|||
_inherit = 'res.company' |
|||
|
|||
# Custom Section |
|||
def _switch_company_get_companies_from_partner( |
|||
self, cr, uid, ids, context=None): |
|||
return self.pool['res.company'].search( |
|||
cr, uid, [('partner_id', 'in', ids)], context=context) |
|||
|
|||
# Fields function Section |
|||
def _get_logo_topbar(self, cr, uid, ids, _field_name, _args, context=None): |
|||
result = dict.fromkeys(ids, False) |
|||
for record in self.browse(cr, uid, ids, context=context): |
|||
size = (48, 48) |
|||
result[record.id] = image_resize_image( |
|||
record.partner_id.image, size) |
|||
return result |
|||
|
|||
# Columns Section |
|||
_columns = { |
|||
'logo_topbar': fields.function( |
|||
_get_logo_topbar, |
|||
string="Logo displayed in the switch company menu", |
|||
type="binary", store={ |
|||
'res.company': (lambda s, c, u, i, x: i, ['partner_id'], 10), |
|||
'res.partner': (_switch_company_get_companies_from_partner, |
|||
['image'], 10), |
|||
} |
|||
), |
|||
} |
@ -1,31 +0,0 @@ |
|||
# -*- encoding: utf-8 -*- |
|||
# ############################################################################# |
|||
# |
|||
# Web Easy Switch Company module for OpenERP |
|||
# Copyright (C) 2014 GRAP (http://www.grap.coop) |
|||
# @author Sylvain LE GAL (https://twitter.com/legalsylvain) |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# 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 Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
from openerp.osv.orm import Model |
|||
|
|||
|
|||
class res_users(Model): |
|||
_inherit = 'res.users' |
|||
|
|||
# Custom Function Section |
|||
def change_current_company(self, cr, uid, company_id, context=None): |
|||
return self.write(cr, uid, uid, {'company_id': company_id}) |
@ -0,0 +1,3 @@ |
|||
# coding: utf-8 |
|||
from . import res_users |
|||
from . import res_company |
@ -0,0 +1,25 @@ |
|||
# coding: utf-8 |
|||
# Copyright (C) 2014 - 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 openerp import api, fields, models |
|||
from openerp.tools import image_resize_image |
|||
|
|||
|
|||
class ResCompany(models.Model): |
|||
_inherit = 'res.company' |
|||
|
|||
# Columns Section |
|||
logo_topbar = fields.Binary( |
|||
compute='_compute_logo_topbar', store=True, |
|||
string="Logo displayed in the switch company menu") |
|||
|
|||
# Compute Section |
|||
@api.multi |
|||
@api.depends('partner_id.image') |
|||
def _compute_logo_topbar(self): |
|||
for company in self: |
|||
size = (48, 48) |
|||
company.logo_topbar = image_resize_image( |
|||
company.partner_id.image, size) |
@ -0,0 +1,14 @@ |
|||
# coding: utf-8 |
|||
# Copyright (C) 2014 - 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 openerp import api, models |
|||
|
|||
|
|||
class ResUsers(models.Model): |
|||
_inherit = 'res.users' |
|||
|
|||
@api.model |
|||
def change_current_company(self, company_id): |
|||
return self.env.user.write({'company_id': company_id}) |
@ -0,0 +1,8 @@ |
|||
When you switch the company, you can choose to stay on the current model and |
|||
item, you are viewing, or to go back to the home page. (by default) |
|||
|
|||
To configure that setting: |
|||
|
|||
* Go to 'Settings' / 'Technical' / 'Parameters' / 'system Parameters' |
|||
* Set the key ``web_easy_switch_company.keep_url`` to ``True`` to keep the url |
|||
when switching the company. |
@ -0,0 +1 @@ |
|||
* Sylvain LE GAL (https://twitter.com/legalsylvain) |
@ -0,0 +1,9 @@ |
|||
This module adds a new menu in the top bar to switch to another company more |
|||
easily and removes the old behaviour to switch company. |
|||
|
|||
.. figure:: ../static/description/switch_company_menu.png |
|||
|
|||
**Technical information** |
|||
|
|||
It creates a field function ``logo_topbar`` on ``res.company`` to have a good |
|||
resized logo. |
@ -0,0 +1 @@ |
|||
* It would be interesting to show the structure of the companies |
@ -0,0 +1,2 @@ |
|||
|
|||
* Video : http://www.youtube.com/watch?v=Cpm6dg-IEQQ |
After Width: 421 | Height: 123 | Size: 14 KiB |
@ -1,5 +1,5 @@ |
|||
.switch_company_menu { |
|||
height: auto; |
|||
max-height: 50vh; |
|||
max-height: 100vh; |
|||
overflow-x: hidden; |
|||
cursor: pointer; |
|||
} |
Before Width: 16 | Height: 16 | Size: 112 B After Width: 16 | Height: 16 | Size: 112 B |
Before Width: 16 | Height: 16 | Size: 445 B After Width: 16 | Height: 16 | Size: 445 B |
@ -1,25 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<openerp> |
|||
<data> |
|||
|
|||
<record id="view_res_users_simple_modif_form" model="ir.ui.view"> |
|||
<field name="name">res.users.form</field> |
|||
<field name="model">res.users</field> |
|||
<field name="inherit_id" ref="base.view_users_form_simple_modif"/> |
|||
<field name="arch" type="xml"> |
|||
<!-- hide old behaviour to change company --> |
|||
<field name="company_id" position="attributes"> |
|||
<attribute name="invisible">1</attribute> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
<template id="assets_backend" name="web_easy_switch_company assets" inherit_id="web.assets_backend"> |
|||
<xpath expr="." position="inside"> |
|||
<script type="text/javascript" src="/web_easy_switch_company/static/src/js/switch_company.js"></script> |
|||
<link rel="stylesheet" href="/web_easy_switch_company/static/src/css/switch_company.css"/> |
|||
</xpath> |
|||
</template> |
|||
|
|||
</data> |
|||
</openerp> |
@ -0,0 +1,11 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<openerp><data> |
|||
|
|||
<template id="assets_backend" name="web_easy_switch_company assets" inherit_id="web.assets_backend"> |
|||
<xpath expr="." position="inside"> |
|||
<script type="text/javascript" src="/web_easy_switch_company/static/src/js/switch_company.js"></script> |
|||
<link rel="stylesheet" href="/web_easy_switch_company/static/src/css/switch_company.css"/> |
|||
</xpath> |
|||
</template> |
|||
|
|||
</data></openerp> |
@ -0,0 +1,16 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<openerp><data> |
|||
|
|||
<record id="view_res_users_simple_modif_form" model="ir.ui.view"> |
|||
<field name="name">res.users.form</field> |
|||
<field name="model">res.users</field> |
|||
<field name="inherit_id" ref="base.view_users_form_simple_modif"/> |
|||
<field name="arch" type="xml"> |
|||
<!-- hide old behaviour to change company --> |
|||
<field name="company_id" position="attributes"> |
|||
<attribute name="invisible">1</attribute> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
</data></openerp> |