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