0

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'
4

1 回答 1

1

_inherit='sale.order'

def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
    cur_obj = self.pool.get('res.currency')
    res = {}

    for order in self.browse(cr, uid, ids, context=context):


        res[order.id] = {
            'amount_untaxed': 0.0,
            'amount_tax': 0.0,
            'amount_total': 0.0,
            'amt_total':0.0
        }
        val = val1 =  0.0
        cur = order.pricelist_id.currency_id
        for line in order.order_line:
            val1 += line.price_subtotal

            val += self._amount_line_tax(cr, uid, line, context=context)
        res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val)
        res[order.id]['amount_untaxed'] = cur_obj.round(cr, uid, cur, val1)
        #import pprint
        #pprint.pprint( res[order.id]['amt_total'] )
        res[order.id]['amount_untaxed'] -= order.amt_total
        res[order.id]['amount_total'] = res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']
   #     res[order.id]['amount_total'] -=order.amt_total
    return res


def _get_order(self, cr, uid, ids, context=None):
    result = {}
    for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context):
        result[line.order_id.id] = True
    return result.keys()

场地

 'purchase_order':fields.many2one('purchase.order', 'Old Gold', ondelete="cascade"),
            'amt_total':fields.related('purchase_order', 'amount_total', type='float', relation='purchase.order', string="Amount", readonly=True),
            'qty_related':fields.related('purchase_order','order_line', 'product_qty', type='float',relation='purchase.order', string='Weight',readonly=True),
于 2014-03-15T11:09:25.533 回答