Jesse
Jesse

Reputation: 769

Odoo generate warning (pop up) from web controller

Hi I have a button on my website linked to a webcontroller which checks for some conditions. Now when some condition is met I want to open a warning or pop up screen, anybody an idea how I can achieve this. So open a popup window (or least preferred a new webpage) from the webcontroller.

web template:

<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>

web controller:

@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

Upvotes: 2

Views: 3414

Answers (2)

Symen
Symen

Reputation: 106

One solution could be to raise a UserError

from odoo import exceptions
...
raise exceptions.UserError("your explanation here")
...

Upvotes: 0

Prakash Kumar
Prakash Kumar

Reputation: 2594

There are two way to doing it:

  • route having type='http'
  • route having type='json'

In the first one just validate your condition and use either werkzeug.utils.redirect(mszpageurl ) or request.redirect(mszpageurl)

In the second case call the controller method using 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);
    });

Upvotes: 2

Related Questions