1.so在这里继承销售订单和po的m2o字段,但它给了我错误,即except_orm:Programming Error There is no reference available for purchase.order
2.我还想从销售订单小计价格中减去采购订单小计价格并显示在销售订单总价上
class sale_inherit_course(orm.Model):
_inherit='sale.order'
_columns={
'create_course':fields.boolean('Create Course'),
'course_name':fields.many2one('openacademy.course', 'Course', ondelete="cascade"),
'responsible': fields.related('course_name', 'responsible_id', type='many2one', relation='res.users', string="co-ordinator", readonly=True),
'buy_back':fields.boolean('Buy Back'),
'purchase_order':fields.many2one('purchase.order', 'Create Back Order', ondelete="cascade"),
'responsible_me': fields.related('purchase_order', 'responsible_id', type='many2one', relation='res.users', string="User", readonly=True),
}
def create(self, cr, uid, vals, context=None):
if vals.get('create_course'):
course_obj=self.pool.get('openacademy.course')
sequence=self.pool.get('ir.sequence').get(cr, uid, 'openacademy.course.seq')
new_course=course_obj.create(cr, uid, {'name':sequence,'responsible_id':vals.get('user_id')}, context=context)
import pprint
pprint.pprint( vals )
vals['course_name']=new_course
pprint.pprint( vals )
elif vals.get('buy_back'):
purchase_obj=self.pool.get('purchase.order')
sequence=self.pool.get('ir.sequence').get(cr, uid, 'purchase.order')
new_purchase=purchase_obj.create(cr, uid, {'name':sequence,'responsible_id':vals.get('user_id')}, context=context)
vals['purchase_order']=new_purchase
return super(sale_inherit_course, self).create(cr, uid, vals, context=context)
这里发生错误即
except_orm: ('Programming Error', 'There is no reference available for purchase.order'