- inventory_line_obj.unlink(cr, uid, line_ids, context=context)
- #compute the inventory lines and create them
- vals = self._get_inventory_lines(cr, uid, inventory, context=context)
- for product_line in vals:
- inventory_line_obj.create(cr, uid, product_line, context=context)
+ if not line_ids:
+ #compute the inventory lines and create them
+ vals = self._get_inventory_lines(cr, uid, inventory, context=context)
+ for product_line in vals:
+ inventory_line_obj.create(cr, uid, product_line, context=context)
+ else:
+ # On import calculate theoretical quantity
+ quant_obj = self.pool.get("stock.quant")
+ for line in inventory.line_ids:
+ dom = [('company_id', '=', line.company_id.id), ('location_id', 'child_of', line.location_id.id), ('lot_id', '=', line.prod_lot_id.id),
+ ('product_id','=', line.product_id.id), ('owner_id', '=', line.partner_id.id)]
+ if line.package_id:
+ dom += [('package_id', '=', line.package_id.id)]
+ quants = quant_obj.search(cr, uid, dom, context=context)
+ tot_qty = 0
+ for quant in quant_obj.browse(cr, uid, quants, context=context):
+ tot_qty += quant.qty
+ inventory_line_obj.write(cr, uid, [line.id], {'theoretical_qty': tot_qty}, context=context)
+