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

Raise an error in Odoo 8

By
José
on 12/11/14, 7:09 AM 8,313 views

Hello, I am developing a module in Odoo 8. I have inherited product.pricelist class which definition is

class product_pricelist(osv.osv):

In my definition I have

class product_pricelist(models.Model):
    _inherit = 'product.pricelist'

When in my code I try to execute the line

raise osv.except_osv(_('Warning!'), _("At least one pricelist has no active version !\nPlease create or activate one."))

I have an error because global name osv is not defined. What is the best way to throw an exception and display an error in Odoo 8? Thanks!

4

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 12/11/14, 7:49 AM

You use openerp.exceptions ( except_orm() or Warning() ) like this:

from openerp.exceptions import except_orm, Warning, RedirectWarning
class product_pricelist(models.Model):
    _inherit = 'product.pricelist'

    @api.multi
    def FOO(self):
        if True:
          raise except_orm('FOO','Lorem ipsum dolor sit amet')
        else:  
          raise Warning('Lorem ipsum dolor sit amet')

 

0
Umesh Choudhari
On 4/18/16, 6:46 AM

@zbik , I tried what u said but it gives error as follows

Traceback (most recent call last):

File "/opt/odoopro/openerp/http.py", line 539, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/opt/odoopro/openerp/http.py", line 1417, in _dispatch_nodb

func, arguments = self.nodb_routing_map.bind_to_environ(request.httprequest.environ).match()

File "/usr/lib/python2.7/dist-packages/werkzeug/routing.py", line 1433, in match

raise NotFound()

NotFound: 404: Not Found

0
José
On 12/15/14, 7:32 AM

Thanks, it works! But how can I display a warning message and then continue with the execution of the method?

Another question, how can I display a "Yes/No" message, if the user presses "Yes" the method continues and if the user presses "No" the execution stop?

José
on 12/15/14, 8:49 AM

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

1 follower(s)

Stats

Asked: 12/11/14, 7:09 AM
Seen: 8313 times
Last updated: 10/7/16, 7:25 AM