Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Can you apply a theme based on the user who logs in?

By
Darrel
on 12/3/14, 1:43 PM 849 views

We want to let clients sign in to our system and each see only the menu items, pages, and layout/theme that we have made for that particular client.

I've been following the theme tutorial here (http://odoo-80.readthedocs.org/en/latest/guides/themes.html) but I don't see how to choose the theme based on the user viewing the page. I'm still pretty new to Odoo. Any ideas?

Edit: I'm also trying to figure out how to apply a theme to specific areas (controllers or actions) of the odoo site. Any links to documentation or tutorials on this would be appreciated.

@Darrel, I think you would need to build a custom theme and use a combination of t-if statements and group access rights to achieve what you require. Could you post back with details on exactly what you are trying to achieve with examples of what you'd like to achieve (eg. custom pages only viewable by certain user groups). This will make it easier for people to offer you advice on how you might be able to achieve your requirements.

Luke Branch
on 12/4/14, 5:45 AM
sure, Luke.

I work for an ecommerce company, and we have two specific goals
requiring custom themes.

a) We want to let ecommerce clients log into Odoo and view reports on
our services, which are branded to that client. And b) We want
multiple separate layouts for the frontend website and product list,
based on the domain the website is being served from.

I think I can implement a new theme for the frontend, by having a
module with templates which inherit web.assets_backend,
website.assets_frontend and 'layout.' What I'm having trouble figuring
out is how (or if) I can make that CSS and HTML dependent on the user
viewing the page, for a, and the domain the site is being accessed
from, for b.

If it helps, we can ignore b) for now, since I am still quite new to
Odoo and the answer may become clear in time.

I would appreciate any help you can provide. There's still a lot I
don't understand about how the website module was able to create a
frontend and give it a separate layout like it has.

Darrel


On Thu, Dec 4, 2014 at 2:45 AM, Luke <luke-weairsoft-com@mail.odoo.com> wrote:
> @Darrel, I think you would need to build a custom theme and use a
> combination of t-if statements and group access rights to achieve what you
> require. Could you post back with details on exactly what you are trying to
> achieve with examples of what you'd like to achieve (eg. custom pages only
> viewable by certain user groups). This will make it easier for people to
> offer you advice on how you might be able to achieve your requirements.
>
> --
> Luke
> Sent by Odoo S.A. using Odoo about Forum Post Can you apply a theme based on
> the user who logs in?

>> I am trying to understand the mechanism behind how the website module
>> has a 'frontend' section which uses a different layout that the
>> regular admin area.

>> I thought I might see something in it's main.py controller class but
>> haven't found anything relevant yet.

>> For context, my two layout related goals are to a) apply a new layout
>> to a limited part of the website's frontend, and b) change that layout
>> depending on the user who is viewing the page (so, load a css file
>> specific to the user account).

>> Any tips, or links to documentation would be appreciated. I have gone
>> through this (http://odoo-80.readthedocs.org/en/latest/guides/themes.html)
>> but still don't see how to the actual areas covered by different
>> themes are controlled.
Darrel
on 12/4/14, 3:32 PM
2

Luke Branch

--Luke Branch--
1531
| 6 7 8
Mui Wo, Lantau, Hong Kong
--Luke Branch--

...

Luke Branch
On 12/4/14, 11:04 PM

In regards to b) I believe what you are referring to is a multi-website type setup (similar to Magento's Website > Store > Store View architecture). Point b) is being worked on in version 9.0 (currently the master branch - runbot.odoo.com), however it is many months away from being released as a stable release. From what I understand version 9 will allow you to run multiple websites with different theme modules, different products, CMS pages, etc. from one database. Currently with Odoo 8.0 it is only really feasible to run one website with one set of CMS pages and products for the page.

While technically it is feasible to build some custom modules to achieve this type of functionality based on domain, etc. I think they would be hack methods/workarounds at best due to the fact the underlying architecture is not there to support it properly.

With that being said in regards to point a) you can certainly achieve what you want to do in regards to applying different user/user group access rights to certain CMS pages, reports, products, etc. by building your own module(s) to acheive the functionality.

I have achieved a few things with building a custom module to create some user-specific and user group specific functionality by liberally using the t-if and group access rights functionality in one of my custom theme modules that is being built for a client who sells airsoft products here:

http://www.aegguns.com

This website allows for distributor-only features by applying different variations on the following statement:

t-if="not user_id.partner_id.name == 'Public user'"

for example showing an add to cart button for logged in users only you could use the following snippet:
 

<template id="product_add_to_cart_Custom" inherit_id="website_sale.product" name="Add To Quote - Logged In" customize_show="True">

    <xpath expr="//a[@id='add_to_cart']" position="replace">

        <a t-if="not user_id.partner_id.name == 'Public user'" id="add_to_cart" class="btn btn-primary btn-lg mt8 js_check_product a-submit" href="#"><i class="fa fa-angle-double-right"></i>&amp;nbsp;&amp;nbsp;&amp;nbsp;Add to Quotation</a>

    </xpath>

</template>

In regards to group access rights, I believe there are a number of posts in this forum about them. Martin Apitz seems to be quite knowledgeable about this kind of thing. You can see his original answer to my question here regarding setting up distributor-only pricing on the website here:

https://www.odoo.com/forum/help-1/question/how-to-remove-pricing-for-not-logged-in-users-on-e-commerce-website-for-distributor-business-to-business-sales-52924

if you're interested in following the developments on Odoo 9.0 you can take a look at the runbots:

http://runbot.odoo.com/

take a look at the master branch (9.0 under development) and you can login to any of these instances by using username: admin, password: admin. If you'd like to take a look at what is being worked on for Website > Store > Store View type architecture in 9.0 you can take a look under Settings >> Website Settings > localhost (click on the dropdown box and create new). 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

4 follower(s)

Stats

Asked: 12/3/14, 1:43 PM
Seen: 849 times
Last updated: 3/16/15, 8:10 AM