Odoo Help

Welcome!

This community is for professionals and enthusiasts of our products and services. Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

0

How to avoid double entry?

By
evon_dun
on 9/25/13, 9:09 AM 777 views

I added a field cartage about an half year ago, and i tried adding another field the exact same way. I get only one issue that is the entry i insert gets a double insert. Please anyone could help?

>     def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
>         cur_obj = self.pool.get('res.currency')
>         res = {}
>         cartageflag = 'false'
>         ordercartageflag = 'true'
>         line_id = 0
>         order_id = 0
>         cartage_price = 0
>         oldcartage = 0
>         oldlabour = 0
>         labour_price = 0
>         labourflag = 'false'
>         orderlabourflag = 'true'
>         checklabourflag = 'false'
>         oid = 0
> 
> 
>         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,
>           }
>             val = val1 = 0.0
>             cur = order.pricelist_id.currency_id        
> 
>             if order.cartage > 0.0:
>                 cartageflag = 'true'
>             if order.labour > 0.0:
>                 labourflag = 'true'
> 
>             for line in order.order_line:
>                 if cartageflag == 'true':
>                     if line.name == 'Cartage':
>                         ordercartageflag = 'false'            line_id
> = line.id             oldcartage = line.price_unit            cr.execute('update
> sale_order_line set price_unit=%s
> where id=%s',(order.cartage,line.id,))
>       
>           #line.update({'price_unit':order.cartage})
>       if labourflag == 'true':
>                     if line.name == 'Labour':
>                         orderlabourflag = 'false'
>                         line_id = line.id
>                         oldlabour = line.price_unit
>                         cr.execute('update sale_order_line set
> price_unit=%s where
> id=%s',(order.labour,line.id,))
>                 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)
>             res[order.id]['amount_total'] =
> res[order.id]['amount_untaxed'] +
> res[order.id]['amount_tax']
>             
>             if ordercartageflag == 'true':
>                 res[order.id]['amount_total'] =
> res[order.id]['amount_total'] +
> order.cartage            
>             elif ordercartageflag == 'false':
>                 if oldcartage != order.cartage:
>                     res[order.id]['amount_total'] =
> (res[order.id]['amount_total'] +
> order.cartage) - oldcartage
>                     
>             if orderlabourflag == 'true':
>                 res[order.id]['amount_total'] =
> res[order.id]['amount_total'] +
> order.labour            
>             elif orderlabourflag == 'false':
>                 if oldlabour != order.labour:
>                     res[order.id]['amount_total'] =
> (res[order.id]['amount_total'] +
> order.labour) - oldlabour
> 
> 
>         
>         oid = order.id
>         if cartageflag == 'true' and ordercartageflag == 'true':
>             self.pool.get('sale.order.line').create(cr,
> uid, {
>                 'order_id':oid,
>                 'name':'Cartage',               
>                 'price_unit':order.cartage,
>                 'product_uos_qty':1,                
>                 'product_uom':1,
>                 'product_uom_qty':1,
>                 'delay':7,
>                 'discount': 0.0})
> 
>             if labourflag == 'true' and orderlabourflag == 'true':
>                 self.pool.get('sale.order.line').create(cr,
> uid, {
>                     'order_id':oid,
>                     'name':'Labour',               
>                     'price_unit':order.labour,
>                     'product_uos_qty':1,                
>                     'product_uom':1,
>                     'product_uom_qty':1,
>                     'delay':7,
>                     'discount': 0.0})




        return res

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

0 follower(s)

Stats

Asked: 9/25/13, 9:09 AM
Seen: 777 times
Last updated: 3/16/15, 8:10 AM