[WIP] action_confirm of stock.move now creates procurement if the procure_method of stock.move is 'make_to_order'

bzr revid: qdp-launchpad@openerp.com-20130709134121-39fab2lh83us0i87
This commit is contained in:
Quentin (OpenERP) 2013-07-09 15:41:21 +02:00
parent 1523992ce2
commit 1dc0ecf012
2 changed files with 25 additions and 47 deletions

View File

@ -1776,6 +1776,27 @@ class stock_move(osv.osv):
'date_expected': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
}
def _create_procurement(self, cr, uid, move, context=None):
"""
This will create a procurement order
"""
proc_obj = self.pool.get("procurement.order")
origin = _('Procurement created by stock move %s') % move.id
return proc_obj.create(cr, uid, {
'name': _('MTO procurement'),
'origin': origin,
'company_id': move.company_id and move.company_id.id or False,
'date_planned': move.date,
'product_id': move.product_id.id,
'product_qty': move.product_qty,
'product_uom': move.product_uom.id,
'product_uos_qty': (move.product_uos and move.product_uos_qty) or move.product_qty,
'product_uos': (move.product_uos and move.product_uos.id) or move.product_uom.id,
'location_id': move.location_src_id.id,
'procure_method': move.procure_method,
'move_id': move.id,
})
# Check that we do not modify a stock.move which is done
def write(self, cr, uid, ids, vals, context=None):
if isinstance(ids, (int, long)):
@ -1986,6 +2007,10 @@ class stock_move(osv.osv):
for state, write_ids in states.items():
if len(write_ids):
self.write(cr, uid, write_ids, {'state': state})
if state == 'confirmed':
for move in self.browse(cr, uid, write_ids, context=context):
if move.procure_method == 'make_to_order':
self._create_procurement(cr, uid, move, context=context)
return True
def force_assign(self, cr, uid, ids, context=None):

View File

@ -211,53 +211,6 @@ class stock_move(osv.osv):
'Procure Method', required=True, help="'Make to Stock': When needed, take from the stock or wait until re-supplying. 'Make to Order': When needed, purchase or produce for the procurement request."),
}
# def _create_procurement(self, cr, uid, rule, move, context=None):
# """
# This will create a procurement order
# """
# #TODO Create procurement order
# proc_obj = self.pool.get("procurement.order")
# #move_obj = self.pool.get("stock.move")
# procs = proc_obj.search(cr, uid, [('move_dest_id','=', move.id)], context=context)
# if procs and procs[0]:
# proc = procs[0]
# origin = (proc.origin or proc.name or '').split(':')[0] +':'+rule.name
# proc_id = proc_obj.create(cr, uid, {
# 'name': rule.name,
# 'origin': origin,
# 'note': _('Pulled procurement coming from original location %s, pull rule %s, via original Procurement %s (#%d)') % (proc.location_id.name, rule.name, proc.name, proc.id),
# 'company_id': rule.company_id and rule.company_id.id or False,
# 'date_planned': move.date,
# 'product_id': move.product_id.id,
# 'product_qty': move.product_qty,
# 'product_uom': move.product_uom.id,
# 'product_uos_qty': (move.product_uos and move.product_uos_qty)\
# or move.product_qty,
# 'product_uos': (move.product_uos and move.product_uos.id)\
# or move.product_uom.id,
# 'location_id': move.location_src_id.id,
# 'procure_method': move.procure_method,
# 'move_id': move.id,
# })
# else:
# proc_id = proc_obj.create(cr, uid, {
# 'name': rule.name,
# 'origin': 'From stock move',
# 'note': _('Pulled procurement coming from original location %s, pull rule %s, via rule %s (#%d)') % (move.location_id.name, rule.name, rule.name, rule.id),
# 'company_id': move.company_id and move.company_id.id or False,
# 'date_planned': move.date,
# 'product_id': move.product_id.id,
# 'product_qty': move.product_qty,
# 'product_uom': move.product_uom.id,
# 'product_uos_qty': (move.product_uos and move.product_uos_qty)\
# or move.product_qty,
# 'product_uos': (move.product_uos and move.product_uos.id)\
# or move.product_uom.id,
# 'location_id': move.location_src_id.id,
# 'procure_method': move.procure_method,
# 'move_id': move.id,
# })
# proc_obj._assign(cr, uid, proc_obj.browse(cr, uid, proc_id, context=context), context=context)
# TODO: reimplement this