从odoo管理Web服务 [英] Manage webservice from odoo
问题描述
我是Odoo 11的新手,我创建了一个名为'coupon'的模块,为此模块,我创建了一个安全组和一个默认用户,该用户已添加到该组中:
I am new to Odoo 11, I have created a module called 'coupon', for this module I have created a security group and a default user that is added to this group:
<record id="default_coupon_user" model="res.users">
<field name="login">couponuser</field>
<field name="password">couponuser</field>
<field name="password_crypt">couponuser</field>
<field name="name">Default User Coupon</field>
<field name="display_name">Default Coupon User</field>
<field name="customer">False</field>
</record>
<record id="coupon_managers_group" model="res.groups" >
<field name="name">Coupon Managers Group</field>
<field name="comment">Coupon Managers Group that will be used in the Coupon microservice.</field>
<field name="category_id" ref="base.module_category_coupon"/>
<field name="users" eval="[(4, ref('coupon.default_coupon_user'))]"/>
</record>
我的模块取决于网站,因为我需要创建一个网站,为此我创建了一个索引页面:
My module depends on website because I need to create a website, for that site I created an index page:
<!-- === Coupon Page === -->
<template id="index_template">
<t t-call="website.layout">
<div id="wrap">
<div class="container">
<h1>Coupons</h1>
<a href="/payum_coupon/create" class="btn btn-primary btn-lg">
Add
</a>
<p>paginas:
<t t-esc="coupons['pg']"/>
</p>
<p>total:
<t t-esc="coupons['total']"/>
</p>
<ul class="clientes">
<t t-foreach="coupons['items']" t-as="i">
<li>
<a t-attf-href="/payum_coupon/{{i['email']}}">
<t t-esc="i['firstName']"/>
<t t-esc="i['lastName']"/>
-
<t t-esc="i['email']"/>
</a>
</li>
</t>
</ul>
</div>
</div>
</t>
</template>
<record id="coupon_page" model="website.page">
<field name="name">Index Coupon page</field>
<field name="website_published">True</field>
<field name="url">/coupon</field>
<field name="view_id" ref="index_template"/>
<field name="groups">coupon.coupon_managers_group</field>
</record>
和website.menu,其代码如下:
and website.menu with the following code:
<record id="coupon_page_link" model="website.menu">
<field name="name">Coupon</field>
<field name="page_id" ref="coupon_page"/>
<field name="parent_id" ref="website.main_menu"/>
</record>
将由所述菜单执行的控制器中的python代码是这样的:
the python code in the controller that will be executed by said menu is this:
@http.route('/coupon', auth='user', website=True)
def index(self, **kw):
#<<my code here>>
我需要几件事:
-
如果在会话中的用户不在'coupon.coupon_managers_group'组中,则显示'索引'页时,菜单不会显示
when the 'index' page is displayed if the user in session is not in the 'coupon.coupon_managers_group' group then the menu is not shown
并且在执行控制器方法'/coupon'时,已验证会话中的用户位于组'coupon.coupon_managers_group'
And that when the controller method '/coupon' is executed it is verified that the user in session is in the group 'coupon.coupon_managers_group'
此站点具有特殊性,并且我的模块没有模型,因为它用于管理api rest应用程序的数据,也就是说,在odoo中,我必须创建列表视图,创建视图等,但是数据被写入并从远程Web服务读取.
This site has a particularity and that my module does not have models, since it is to manage the data of an api rest application, that is, in odoo I have to create the views of list, create, etc., but the data is written and they are read from a remote web service.
我已经在互联网上搜索了许多站点,但是我什么也没找到,因为它们总是涉及到odoo中的本地案例.
I have searched many sites on the internet but I have not found anything, as they always refer to local cases in odoo.
推荐答案
要基于用户组隐藏网站菜单,您可以执行以下操作:
To hide the website menu based on the user group you could do something like this:
from odoo import api, models
class Menu(models.Model):
_inherit = "website.menu"
@api.one
def _compute_visible(self):
if self.clean_url() == '/coupon' and not self.env.user.has_group('coupon.coupon_managers_group'):
return False
return super(Menu, self)._compute_visible()
在路由/coupon
的控制器中,您可以像这样检查用户组:
In the controller of the route /coupon
you could check the user group like:
request.env.user.has_group('coupon.coupon_managers_group')
这篇关于从odoo管理Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!