Commits

Raimon Esteve (Zikzakmedia) committed 2dff97b

[IMP] Sale Order line Delivey. Create or update

Comments (0)

Files changed (2)

         return result
 sale_order()
 
+class sale_order_line(osv.osv):
+    _inherit = 'sale.order.line'
+
+    _columns = {
+        'delivery_line': fields.boolean('Delivery', help="Delivery line"),
+     }
+
+sale_order_line()
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 

wizard/delivery_sale_order.py

                 taxes = grid.carrier_id.product_id.taxes_id
                 fpos = order.fiscal_position or False
                 taxes_ids = acc_fp_obj.map_tax(cr, uid, fpos, taxes)
-                line_obj.create(cr, uid, {
+                values = {
                     'order_id': order.id,
                     'name': grid.carrier_id.name,
                     'product_uom_qty': 1,
                     'product_id': grid.carrier_id.product_id.id,
                     'price_unit': grid_obj.get_price(cr, uid, grid.id, order, time.strftime('%Y-%m-%d'), context),
                     'tax_id': [(6,0,taxes_ids)],
-                    'type': 'make_to_stock'
-                })
+                    'type': 'make_to_stock',
+                    'delivery_line': True,
+                }
+                lines = line_obj.search(cr, uid, ([('order_id','=',order.id),('delivery_line','=',True)]))
+                #update or create order line delivery
+                if len(lines)>0:
+                    line_obj.write(cr, uid, lines[0], values)
+                else:
+                    line_obj.create(cr, uid, values)
     
         return {'type': 'ir.actions.act_window_close'}