Browse Source

Merge pull request #18 from taktik/master

[MIG] web_easy_switch_company
pull/39/head
Pedro M. Baeza 11 years ago
parent
commit
529e7cb8b0
  1. 20
      placeholder/__init__.py
  2. 51
      placeholder/__openerp__.py
  3. 1
      web_easy_switch_company/__init__.py
  4. 2
      web_easy_switch_company/__openerp__.py
  5. 0
      web_easy_switch_company/controllers/__init__.py
  6. 21
      web_easy_switch_company/controllers/main.py
  7. 0
      web_easy_switch_company/model/__init__.py
  8. 0
      web_easy_switch_company/model/res_company.py
  9. 2
      web_easy_switch_company/model/res_users.py
  10. 0
      web_easy_switch_company/static/description/icon.png
  11. 0
      web_easy_switch_company/static/description/selection-off.png
  12. 0
      web_easy_switch_company/static/description/selection-on.png
  13. 12
      web_easy_switch_company/static/src/js/switch_company.js
  14. 41
      web_easy_switch_company/static/src/xml/switch_company.xml
  15. 7
      web_easy_switch_company/view/res_users_view.xml

20
placeholder/__init__.py

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
#
# 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/>.
#
##############################################################################

51
placeholder/__openerp__.py

@ -1,51 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
#
# 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": "placeholder",
"version": "1.0",
"author": "Therp BV",
"license": "AGPL-3",
"complexity": "normal",
"description": """
This is a placeholder module because odoo checks if an addons path contains
addons at all. This makes travis fail, so we need this until the first addon is
ported.
Please remove as soon as you commit your first port!
""",
"category": "",
"depends": [
],
"data": [
],
"js": [
],
"css": [
],
"qweb": [
],
"auto_install": False,
"installable": True,
"application": False,
"external_dependencies": {
'python': [],
},
}

1
__unported__/web_easy_switch_company/__init__.py → web_easy_switch_company/__init__.py

@ -19,6 +19,5 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import model
from . import controllers

2
__unported__/web_easy_switch_company/__openerp__.py → web_easy_switch_company/__openerp__.py

@ -66,6 +66,6 @@ Copyright, Author and Licence:
'qweb': [
'static/src/xml/switch_company.xml',
],
'installable': False,
'installable': True,
'auto_install': False,
}

0
__unported__/web_easy_switch_company/controllers/__init__.py → web_easy_switch_company/controllers/__init__.py

21
__unported__/web_easy_switch_company/controllers/main.py → web_easy_switch_company/controllers/main.py

@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
##############################################################################
# #############################################################################
#
# Web Easy Switch Company module for OpenERP
# Copyright (C) 2014 GRAP (http://www.grap.coop)
@ -18,14 +18,17 @@
# 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(openerp.addons.web.http.Controller):
_cp_path = '/web_easy_switch_company/switch'
@openerp.addons.web.http.jsonrequest
def change_current_company(self, req, company_id):
req.session.model('res.users').change_current_company(company_id)
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

0
__unported__/web_easy_switch_company/model/__init__.py → web_easy_switch_company/model/__init__.py

0
__unported__/web_easy_switch_company/model/res_company.py → web_easy_switch_company/model/res_company.py

2
__unported__/web_easy_switch_company/model/res_users.py → web_easy_switch_company/model/res_users.py

@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
##############################################################################
# #############################################################################
#
# Web Easy Switch Company module for OpenERP
# Copyright (C) 2014 GRAP (http://www.grap.coop)

0
__unported__/web_easy_switch_company/static/src/img/icon.png → web_easy_switch_company/static/description/icon.png

Before

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

After

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

0
__unported__/web_easy_switch_company/static/src/img/selection-off.png → web_easy_switch_company/static/description/selection-off.png

Before

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

After

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

0
__unported__/web_easy_switch_company/static/src/img/selection-on.png → web_easy_switch_company/static/description/selection-on.png

Before

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

After

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

12
__unported__/web_easy_switch_company/static/src/js/switch_company.js → web_easy_switch_company/static/src/js/switch_company.js

@ -62,6 +62,8 @@ openerp.web_easy_switch_company = function (instance) {
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}
@ -102,8 +104,8 @@ openerp.web_easy_switch_company = function (instance) {
// Note: calling res.company.name_search with
// user_preference=True in the context does
// not work either.
new instance.web.Model('res.users').call('fields_view_get',{context:{'form_view_ref':'base.view_users_form_simple_modif'}}).then(function(res){
var res_company = res.fields.company_id.selection;
new instance.web.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
@ -116,10 +118,10 @@ openerp.web_easy_switch_company = function (instance) {
id: res_company[i][0]
});
if (res_company[i][0] == self.current_company_id){
logo_state = '/web_easy_switch_company/static/src/img/selection-on.png';
logo_state = '/web_easy_switch_company/static/description/selection-on.png';
}
else{
logo_state = '/web_easy_switch_company/static/src/img/selection-off.png';
logo_state = '/web_easy_switch_company/static/description/selection-off.png';
}
self.companies.push({
id: res_company[i][0],
@ -145,7 +147,7 @@ openerp.web_easy_switch_company = function (instance) {
this._super(parent);
var switch_button = new instance.web.SwitchCompanyWidget();
switch_button.appendTo(instance.webclient.$el.find('.oe_systray'));
},
}
});

41
__unported__/web_easy_switch_company/static/src/xml/switch_company.xml → web_easy_switch_company/static/src/xml/switch_company.xml

@ -21,24 +21,29 @@
<template>
<t t-name="web_easy_switch_company.SwitchCompanyWidget">
<span class="oe_user_menu oe_topbar_item oe_dropdown_toggle oe_dropdown_arrow">
<span>
<t t-esc="widget.current_company_name"/>
</span>
<ul class="oe_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>
</span>
<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>

7
__unported__/web_easy_switch_company/view/res_users_view.xml → web_easy_switch_company/view/res_users_view.xml

@ -13,5 +13,12 @@
</field>
</field>
</record>
<template id="assets_backend" name="web_tests 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