您好我的网站上有一个链接到webcontroller的按钮,可以检查某些条件。现在,当满足某些条件时,我想打开警告或弹出屏幕,任何人都知道如何实现这一目标。因此,从web控制器打开一个弹出窗口(或者最不喜欢新的网页)。
网络模板:
<a t-attf-href="/shop/product/#{ str(product.id)+'-'+str(user_id.id) }/notinstock" class="btn btn-danger btn-lg mt8">Out of Stock</a>
网络控制器:
@http.route(['/shop/product/<prod_n_customer>/notinstock'], type='http', auth="public", website=True)
def testfunctie(self, prod_n_customer, **post):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
prod_out_stock = pool['prod_out_of_stock']
product, customer= prod_n_customer.split('-')
product = int(product)
customer= int(customer)
exist= prod_out_stock.search(cr, uid, [('prod_id','=',product),('customer_id','=',customer)], context=context)
date= datetime.now()
if not exist:
cr.execute("insert into prod_out_of_stock(create_date, prod_id, customer_id) values('%s','%s','%s')" % (date,product,customer))
HERE COMES THE WARNING POP UP SAYING SOME MESSAGE
答案 0 :(得分:2)
有两种方法可以做到:
route having type='http'
route having type='json'
在第一个中,只需验证您的情况并使用werkzeug.utils.redirect(mszpageurl ) or request.redirect(mszpageurl
)
在第二种情况下,使用jsonRpc调用控制器方法。
openerp.jsonRpc('/yoururl', 'call', {'prod_n_customer': prod_n_customer}).then(function (response )
{
do popup using jquery on same page or set the location redirect to your mszpageurl based on response
})
.fail(function (err)
{
console.log(err);
});
答案 1 :(得分:0)
一种解决方案可能是引发 UserError
from odoo import exceptions
...
raise exceptions.UserError("your explanation here")
...