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

How to write test that expects error

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

Hi,

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(
                ...,
                points=-10,
                ))

Because this always gives me an error.

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

0 follower(s)

Stats

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