0

1.so inherit here sale order and m2o field for po but it has given me error i.e except_orm:Programming Error There is no reference available for purchase.order

2.I also want to subtract purchase order subtotal price from the sale order subtotal price and show on to the sale order Total Price

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)  

Here Error Occur that is

except_orm: ('Programming Error', 'There is no reference available for purchase.order'
dirkk
  • 6,160
  • 5
  • 33
  • 51
Atul Jain
  • 1,053
  • 11
  • 36
  • No idea what this code is meant to do, but I find it suspicious that you seem to create a column `'purchase_order'` and then always refer to a column `'purchase.order'`. Might this be the problem? – tobias_k Jan 13 '14 at 12:56
  • yes i want purchase order from the sales Order and calculate the total price like (sale_order_totalprice=(sale_order_subtotal_price - purchase_order_total_price)) – Atul Jain Jan 14 '14 at 06:39
  • yes your hint solvable for me, but How i can compute the value of purchase and sale – Atul Jain Jan 14 '14 at 12:40
  • Would be best if you put this as a new question with the other bug fixed. – tobias_k Jan 14 '14 at 13:33

1 Answers1

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()

Field

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