[WIP] Grouping of stock moves + stock_location should first check must precise procurement rule on _assign

bzr revid: jco@openerp.com-20130710103156-9am4b4dkzr27ukhk
This commit is contained in:
Josse Colpaert
2013-07-10 12:31:56 +02:00
parent 7c60886b4a
commit 9f4d4d28a8
4 changed files with 27 additions and 8 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ class procurement_rule(osv.osv):
_description = "Procurement Rule"
def _get_action(self, cr, uid, context=None):
return [('move', 'Move')]
return []
_columns = {
'name': fields.char('Name', required=True,
+1
View File
@@ -89,6 +89,7 @@ class procurement_order(osv.osv):
return False
move_obj = self.pool.get('stock.move')
move_dict = self._run_move_create(cr, uid, procurement, context=context)
move_id = move_obj.create(cr, uid, move_dict, context=context)
move_obj.action_confirm(cr,uid, [move_id], context=context)
self.write(cr, uid, [procurement.id], {'move_id': move_id}, context=context)
+22 -3
View File
@@ -653,6 +653,9 @@ class stock_picking(osv.osv):
# Used to search a product on pickings
'product_id': fields.related('move_lines', 'product_id', type='many2one', relation='product.product', string='Product'),
'location_id': fields.related('move_lines', 'location_id', type='many2one', relation='stock.location', string='Location'),
'location_dest_id': fields.related('move_lines', 'location_dest_id', type='many2one', relation='stock.location', string='Destination Location'),
'group_id': fields.related('move_lines', 'group_id', type='many2one', relation='procurement.group', string='Procurement Group'),
}
_defaults = {
'name': lambda self, cr, uid, context: '/',
@@ -1668,6 +1671,7 @@ class stock_move(osv.osv):
# FP Note: this should be a function field
'remaining_qty': fields.float('Remaining Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), states={'done': [('readonly', True)]}), # to be used in pick/pack new interface # TODO change this in a functional field to ease the handling
'group_id': fields.many2one('procurement.group', 'Procurement Group'),
}
def _check_location(self, cr, uid, ids, context=None):
@@ -2000,9 +2004,24 @@ class stock_move(osv.osv):
state = 'waiting'
states[state].append(move.id)
if not move.picking_id:
# TODO: Put the move in the right picking according to group_id
pass
if not move.picking_id:
# TODO: Put the move in the right picking according to group_id -> should be more elaborated (draft is nok) and picking should be confirmed
pick_obj = self.pool.get("stock.picking")
picks = pick_obj.search(cr, uid, [('group_id', '=', move.group_id.id), ('location_id', '=', move.location_id.id),
('location_dest_id', '=', move.location_dest_id.id), ('state', 'in', ['confirmed', 'waiting', 'draft'])], context=context)
if picks:
pick=picks[0]
else:
# Create new picking
pick = pick_obj.create(cr, uid, {'origin': move.origin,
'company_id': move.company_id and move.company_id.id or False,
'type': 'internal',
'move_type': 'one',
'partner_id': move.partner_id and move.partner_id.id or False,
#'invoice_state': move.invoice_state
'group_id': move.group_id and move.group_id.id or False,
}, context=context)
move.write({'picking_id': pick})
for state, write_ids in states.items():
if len(write_ids):
+3 -4
View File
@@ -148,10 +148,10 @@ class procurement_order(osv.osv):
def _assign(self, cr, uid, procurement, context=None):
if procurement.location_id:
rule_obj = self.pool.get('procurement.rule')
route_ids =[False] + [x.id for x in procurement.product_id.route_ids]
res = rule_obj.search(cr, uid, [('location_id','=',procurement.location_id.id),('route_id', 'in', route_ids)], context=context)
route_ids = [x.id for x in procurement.product_id.route_ids]
res = rule_obj.search(cr, uid, [('location_id','=',procurement.location_id.id),('route_id', 'in', route_ids),], context=context)
if not res:
return False
return super(procurement_order, self)._assign(cr, uid, procurement, context=context)
return res[0]
return super(procurement_order, self)._assign(cr, uid, procurement, context=context)
@@ -207,7 +207,6 @@ class stock_move(osv.osv):
'cancel_cascade': fields.boolean('Cancel Cascade', help='If checked, when this move is cancelled, cancel the linked move too'),
'putaway_ids': fields.one2many('stock.move.putaway', 'move_id', 'Put Away Suggestions'),
}
# TODO: reimplement this