Odoo Help


How to troubleshoot AssertionError

Abdullah Sofan
on 12/8/14, 6:23 AM 1,092 views

I have the below code which creates a course and a product with the same name and price. The code works when creating a record, but when the course name or any other field is edited the code returns an AssertionError without any explanation. 

How can I troubleshoot this kind of error. Also, can you check the code and see if it is correct? 

Thanks in advance


class intrac_courses(osv.osv):

    def create(self, cr, uid, vals, context=None):
        if not vals:
            vals = {}
        if context is None:
           context = {}
        product_name = vals.get('name', '1')
        product_fee = vals.get('course_fee', '0.0')
        product_desc = vals.get('course_outline', '')
        product_obj = self.pool.get('product.template')
        product_type = 'service'
        vals['prod_id']= product_obj.create(cr, uid, {'name' : product_name, 'type': product_type, 'list_price': product_fee, 'description': product_desc }, context=context)
        return super(intrac_courses, self).create(cr, uid, vals, context=context)

    def write(self, cr, uid, ids, vals, context=None):
        written = super(intrac_courses, self).write(cr, uid, ids, vals, context=context)
        reads = self.read(cr, uid, ids, ['prod_id','name','course_fee','course_outline'], context=context)
        for record in reads:
            product_id = record['prod_id']
            if product_id:
                product_vals = {
                    'name' : record['name'] or '',
                    'list_price' : record['course_fee'] or 0.0,
                    'description' : record['course_outline'] or '',
                    'type' : 'service'
                product_obj = self.pool.get('product.template')
        return written

    _name = 'intrac.courses'
    _columns = {
        'prod_id': fields.char('Product ID'),
        'course_id': fields.char('Course ID'),
        'course_category': fields.selection([('General English','General English'),('Intensive English','Intensive English'),('English for Special Purposes','English for Special Purposes'),('Business Edge','Business Edge'),('Information Technology','Information Technology'),('Other','Other')], 'Course Category', required=True),
        'name': fields.char('Course Name', size=100, required=True),
        'course_arabic_name': fields.char('Arabic Name', size=100),
        'course_long_name': fields.char('Long Name', size=200, required=True),
        'course_duration': fields.integer('Duration (Hours)', required=True),
        'course_fee': fields.char('Fees Per Trainee'),
        'course_outline': fields.html('Course Outline & Details'),
        'course_notes': fields.one2many('intrac.courses.notes', 'course_name', 'Course Notes'),

Try returning True instead of written, as write should return True

Currenda Sp. z o.o., Mariusz Mizgier
on 12/8/14, 7:36 AM
Abdullah Sofan
On 12/8/14, 7:55 AM


The problem turned out to be that i declared the field prod_id as char instead of integer. write() method id should be an integer.

So, by changing this:

'prod_id': fields.char('Product ID'),


prod_id': fields.integer('Product ID'),

Solved the problem.


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

2 follower(s)


Asked: 12/8/14, 6:23 AM
Seen: 1092 times
Last updated: 3/16/15, 8:10 AM