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.

1

How to troubleshoot AssertionError

By
Abdullah Sofan
on 12/8/14, 6:23 AM 712 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')
                product_obj.write(cr,uid,[product_id],product_vals,context=context)
        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'),
    }
intrac_courses()

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
1
Abdullah Sofan
On 12/8/14, 7:55 AM

Solved.

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'),

to

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

Solved the problem.

 

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

2 follower(s)

Stats

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