Browse Source

[REF] remove web_easy_switch_company. feature is now in the Odoo web Module

pull/450/head
Sylvain LE GAL 8 years ago
parent
commit
f4a7796510
  1. 92
      web_easy_switch_company/README.rst
  2. 23
      web_easy_switch_company/__init__.py
  3. 41
      web_easy_switch_company/__manifest__.py
  4. 23
      web_easy_switch_company/controllers/__init__.py
  5. 38
      web_easy_switch_company/controllers/main.py
  6. 24
      web_easy_switch_company/model/__init__.py
  7. 57
      web_easy_switch_company/model/res_company.py
  8. 31
      web_easy_switch_company/model/res_users.py
  9. BIN
      web_easy_switch_company/static/description/icon.png
  10. BIN
      web_easy_switch_company/static/description/selection-off.png
  11. BIN
      web_easy_switch_company/static/description/selection-on.png
  12. 152
      web_easy_switch_company/static/src/js/switch_company.js
  13. 49
      web_easy_switch_company/static/src/xml/switch_company.xml
  14. 24
      web_easy_switch_company/view/res_users_view.xml

92
web_easy_switch_company/README.rst

@ -1,92 +0,0 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=======================
web_easy_switch_company
=======================
This module extend web backend and allow user to switch to another company more easily.
Configuration
=============
To configure this module, you need to:
* Enable multi company in your odoo instance
* Add your user in at least 2 companies, and you will see the switch at the upper right corner
Usage
=====
Functionality:
--------------
* Add a new menu in the top bar to switch to another company more easily;
* Remove the old behaviour to switch company;
Documentations:
---------------
* Video : http://www.youtube.com/watch?v=Cpm6dg-IEQQ
Technical information:
----------------------
* Create a field function 'logo_topbar' in res_company to have a good"""
"""resized logo;
Limits:
-------
* It would be interesting to show the structure of the companies;
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/162/9.0
Known issues / Roadmap
======================
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/web/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed `feedback
<https://github.com/OCA/
web/issues/new?body=module:%20
web_easy_switch_company%0Aversion:%20
9.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Copyright: 2014, Groupement Régional Alimentaire de Proximité;
* Author: Sylvain LE GAL (https://twitter.com/legalsylvain);
* Contributor: Nicolas JEUDY - Sudokeys (https://github.com/njeudy)
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

23
web_easy_switch_company/__init__.py

@ -1,23 +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 . import model
from . import controllers

41
web_easy_switch_company/__manifest__.py

@ -1,41 +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/>.
#
##############################################################################
{
'name': 'Multicompany - Easy Switch Company',
'version': '9.0.1.0.0',
'category': 'web',
'author': "GRAP,Sudokeys,Odoo Community Association (OCA)",
'website': 'http://www.grap.coop',
'license': 'AGPL-3',
'depends': [
'web',
],
'data': [
'view/res_users_view.xml',
],
'qweb': [
'static/src/xml/switch_company.xml',
],
'installable': False,
'auto_install': False,
}

23
web_easy_switch_company/controllers/__init__.py

@ -1,23 +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 . import main

38
web_easy_switch_company/controllers/main.py

@ -1,38 +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/>.
#
#############################################################################
import openerp
import openerp.http as http
from openerp.http import request
class WebEasySwitchCompanyController(http.Controller):
@http.route(
'/web_easy_switch_company/switch/change_current_company',
type='json', auth='none')
def change_current_company(self, company_id):
registry = openerp.modules.registry.RegistryManager.get(
request.session.db)
uid = request.session.uid
with registry.cursor() as cr:
res = registry.get("res.users").change_current_company(
cr, uid, company_id)
return res

24
web_easy_switch_company/model/__init__.py

@ -1,24 +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 . import res_users
from . import res_company

57
web_easy_switch_company/model/res_company.py

@ -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),
}
),
}

31
web_easy_switch_company/model/res_users.py

@ -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})

BIN
web_easy_switch_company/static/description/icon.png

Before

Width: 128  |  Height: 128  |  Size: 6.0 KiB

BIN
web_easy_switch_company/static/description/selection-off.png

Before

Width: 16  |  Height: 16  |  Size: 112 B

BIN
web_easy_switch_company/static/description/selection-on.png

Before

Width: 16  |  Height: 16  |  Size: 445 B

152
web_easy_switch_company/static/src/js/switch_company.js

@ -1,152 +0,0 @@
/******************************************************************************
Web Easy Switch Company module for OpenERP
Copyright (C) 2014-2015 GRAP (http://www.grap.coop)
@author Sylvain LE GAL (https://twitter.com/legalsylvain)
@contributor Nicolas JEUDY (https://github.com/njeudy)
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/>.
******************************************************************************/
odoo.define('web.web_easy_switch_company',function (require) {
"use strict";
var Widget = require('web.Widget');
var SystrayMenu = require('web.SystrayMenu');
var web_client = require('web.web_client');
var Model = require('web.Model');
/***************************************************************************
Create an new 'SwitchCompanyWidget' widget that allow users to switch
from a company to another more easily.
***************************************************************************/
var SwitchCompanyWidget = Widget.extend({
template:'web_easy_switch_company.SwitchCompanyWidget',
/***********************************************************************
Overload section
***********************************************************************/
/**
* Overload 'init' function to initialize the values of the widget.
*/
init: function(parent){
this._super(parent);
this.companies = [];
this.current_company_id = 0;
this.current_company_name = '';
},
/**
* Overload 'start' function to load datas from DB.
*/
start: function () {
this._super();
this._load_data();
},
/**
* Overload 'renderElement' function to set events on company items.
*/
renderElement: function() {
var self = this;
this._super();
if (this.companies.length === 1) {
this.$el.hide();
}
else{
this.$el.show();
this.$el.find('.easy_switch_company_company_item').on('click', function(ev) {
var company_id = $(ev.target).data("company-id");
if (company_id != self.current_company_id){
var func = '/web_easy_switch_company/switch/change_current_company';
var param = {'company_id': company_id}
self.rpc(func, param).done(function(res) {
window.location.reload()
});
}
});
}
},
/***********************************************************************
Custom section
***********************************************************************/
/**
* helper function to load data from the server
*/
_fetch: function(model, fields, domain, ctx){
return new Model(model).query(fields).filter(domain).context(ctx).all();
},
/**
* - Load data of the companies allowed to the current users;
* - Launch the rendering of the current widget;
*/
_load_data: function(){
var self = this;
// Request for current users information
this._fetch('res.users',['company_id'],[['id','=',this.session.uid]]).then(function(res_users){
self.current_company_id = res_users[0].company_id[0];
self.current_company_name = res_users[0].company_id[1];
// Request for other companies
// We have to go through fields_view_get to emulate the
// exact (exotic) behavior of the user preferences form in
// fetching the allowed companies wrt record rules.
// Note: calling res.company.name_search with
// user_preference=True in the context does
// not work either.
new Model('res.company').call('name_search',{context:{'user_preference':'True'}}).then(function(res){
var res_company = res;
for ( var i=0 ; i < res_company.length; i++) {
var logo_topbar, logo_state;
// TODO: fetching the logo of other companies fails with the
// default res.company record rule, so we should
// probably remove the logos from the menu :(
logo_topbar = self.session.url(
'/web/binary/image', {
model:'res.company',
field: 'logo_topbar',
id: res_company[i][0]
});
if (res_company[i][0] == self.current_company_id){
logo_state = '/web_easy_switch_company/static/description/selection-on.png';
}
else{
logo_state = '/web_easy_switch_company/static/description/selection-off.png';
}
self.companies.push({
id: res_company[i][0],
name: res_company[i][1],
logo_topbar: logo_topbar,
logo_state: logo_state
});
}
// Update rendering
self.renderElement();
});
});
},
});
SystrayMenu.Items.push(SwitchCompanyWidget);
});

49
web_easy_switch_company/static/src/xml/switch_company.xml

@ -1,49 +0,0 @@
<?xml version="1.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/>. -->
<!-- ********************************************************************** -->
<template>
<t t-name="web_easy_switch_company.SwitchCompanyWidget">
<ul class="nav navbar-nav navbar-right oe_user_menu_placeholder" style="margin-right:10px">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<span class="oe_topbar_name">
<t t-esc="widget.current_company_name"/>
</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<t t-foreach="widget.companies" t-as="company">
<li>
<a class="easy_switch_company_company_item"
href="#"
t-att-data-company-id="company.id">
<img class="oe_topbar_avatar" t-att-src="company.logo_topbar"/>
<img class="oe_topbar_avatar" t-att-src="company.logo_state"/>
<t t-esc="company.name"/>
</a>
</li>
</t>
</ul>
</li>
</ul>
</t>
</template>

24
web_easy_switch_company/view/res_users_view.xml

@ -1,24 +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>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save