Ask Your Question
0

How to avoid double entry?

asked 2013-09-25 13:09:07 +0200

evon gravatar image evon flag of India
111 4 9 30

updated 2013-09-25 13:11:17 +0200

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
delete close flag offensive retag edit

Login/Signup to Answer

Documentation

You can download ebooks on Facebook or buy paper book

You can read the online documentation

Question tools

Follow

subscribe to rss feed

Stats

Asked: 2013-09-25 13:09:07 +0200

Seen: 67 times

Last updated: Sep 25 '13