This question has been flagged
1 Reply
4360 Views

class order_details(osv.osv):
    _name='order.details'
    _columns={
              'name':fields.char('Name of Customer'),
              'order_line':fields.one2many('order.detail.line','name_id','Ordering'),
              }
order_details()
    
class order_details_line(osv.osv):
    _name='order.detail.line'
    
    def onchange_name(self, cr, uid, ids,name_id, context=None):
        res = {}
    
        if name_id:
            dish = self.pool.get('dish.dish')
            dish_obj=dish.browse(cr, uid,name_id, context=context)
            res['value'] = {'o_chef':dish_obj.d_chef.id,'o_category':dish_obj.d_category.id, 'o_price': dish_obj.d_price,}
        return res
    
    def _get_total(self, cr, uid, ids, fields, args, context=None):
        ttl = {}
        for x in self.browse(cr, uid, ids, context=context):
                ttl[x.id]={'o_price':0.0,'o_discount':0.0,'o_total':0.0}
                ttl[x.id]['o_total'] = x.o_price - x.o_discount
        return ttl
    
    _columns={
             
             'name_id':fields.many2one('dish.dish','Name of Dish'),
             'o_category':fields.many2one('category.category','Category'),
             'o_chef':fields.many2one('chef.chef','Name of Chef'),
             'o_price':fields.float('Price'),
             'o_discount':fields.float('Discount'),
             'o_total':fields.function(_get_total, string='Total', type='float', multi="o_total",store=True),
              
              }
    _rec_name='name_id'
order_details_line()

 

 

This is my code.here the  "def onchange_name" function is not working.give me a solutions

Avatar
Discard

What problem you facing ?

Best Answer

Hi

Refere this link may help you

https://www.odoo.com/forum/Help-1/question/OpenERP-load-one2many-records-list-7851

Avatar
Discard