Odoo Help


How to write test that expects error

Stefan Braspenning
on 12/15/13, 7:33 AM 853 views


I'm create a module to try and learn OpenERP. I want a res.partner to have points and for each sale he does he needs to get an extra point.

When you create a res.partner you can give him an initial points value, but it can't be negative. class res_partner(osv.Model): _inherit = 'res.partner'

   _columns = {
        'points': fields.integer(string = 'Collected points'),

    _defaults = {
                 'points': 0,

   def _check_points(self, cr, uid, ids, context=None):
    obj = self.browse(cr, uid, ids[0], context=context)
    if obj.points < 0:
        return False
    return True

_constraints = [
    (_check_points, 'Points must be 0 or above', ['points']),

How do I write my test?

def test_negative_points(self):
        cr, uid = self.cr, self.uid
        loyalty_id = self.partner_model.create(cr, uid, dict(

Because this always gives me an error.

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 12/15/13, 7:33 AM
Seen: 853 times
Last updated: 3/16/15, 8:10 AM