Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

4

How to use Onchange function in one2many

By
Swalih muhammed
on 6/27/14, 1:34 AM 976 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

What problem you facing ?

Jagdish Panchal
on 6/27/14, 1:40 AM
1

Jagdish Panchal

--Jagdish Panchal--
2674
| 5 3 6
Gandhinagar, India
--Jagdish Panchal--

OpenERP Developer

Jagdish Panchal
On 6/27/14, 1:44 AM

Hi

Refere this link may help you

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/27/14, 1:34 AM
Seen: 976 times
Last updated: 3/16/15, 8:10 AM