[WIP] Move multiple quants at once

bzr revid: jco@openerp.com-20140310175445-qza0jpc3tx724vks
This commit is contained in:
Josse Colpaert 2014-03-10 18:54:45 +01:00
parent 2e7fedb889
commit 1a5e98ad6b
2 changed files with 72 additions and 44 deletions

View File

@ -343,7 +343,22 @@ class stock_quant(osv.osv):
quant = self._quant_create(cr, uid, qty, move, lot_id=lot_id, owner_id=owner_id, src_package_id=src_package_id, dest_package_id=dest_package_id, force_location = location_dest_id, context=context)
if not location_dest_id:
location_dest_id = move.location_dest_id
self.move_single_quant_tuple(cr, uid, quant, qty, move, location_dest_id, context=context)
self.move_single_quant_tuples(cr, uid, [x for x in quants if x[0]], move, location_dest_id, context=context)
def move_single_quant_tuples(self, cr, uid, quants, move, location_dest_id, context=None):
whole_quants = []
for quant, qty in quants:
if not quant:
continue
new_quant = self._quant_split(cr, uid, quant, qty, context=context)
whole_quants.append(quant.id)
if self._check_location(cr, uid, location_dest_id, context=context) and whole_quants:
self.write(cr, SUPERUSER_ID, whole_quants, {'location_id': location_dest_id.id,
'history_ids': [(4, move.id)]}, context=context)
self._quants_reconcile_negative(cr, uid, whole_quants, move, context=context)
def move_single_quant(self, cr, uid, quant, location_to, qty, move, context=None):
@ -492,16 +507,22 @@ class stock_quant(osv.osv):
path.append((4, move.id))
self.write(cr, SUPERUSER_ID, solved_quant_ids, {'history_ids': path}, context=context)
def _quants_reconcile_negative(self, cr, uid, quants, move, context=None):
if quants[0].location_id.usage != 'internal':
return False
quants_rec = self.search(cr, uid, [('product_id', '=', move.product_id.id), ('qty','<', 0)], limit=1, context=context)
if quants_rec:
for quant in quants:
quant.refresh()
self._quant_reconcile_negative(cr, uid, quant, move, context=context)
def _quant_reconcile_negative(self, cr, uid, quant, move, context=None):
"""
When new quant arrive in a location, try to reconcile it with
negative quants. If it's possible, apply the cost of the new
quant to the conter-part of the negative quant.
"""
if quant.location_id.usage != 'internal':
return False
quants = self.search(cr, uid, [('product_id', '=', quant.product_id.id), ('qty','<', 0)], limit=1, context=context)
if quants:
solving_quant = quant
dom = [('qty', '<', 0)]
if quant.lot_id:

View File

@ -130,6 +130,13 @@ class stock_quant(osv.osv):
self._account_entry_move(cr, uid, quant, move, context=context)
return quant_record
def move_single_quant_tuples(self, cr, uid, quants, move, location_dest_id, context=None):
quant_record = super(stock_quant, self).move_single_quant_tuples(cr, uid, quants, move, location_dest_id, context=context)
if move.product_id.valuation == 'real_time':
for quant in quants:
self._account_entry_move(cr, uid, quant, move, context=context)
return quant_record
def _get_accounting_data_for_valuation(self, cr, uid, move, context=None):
"""