From 9f4d4d28a8ec9e9585cac526fe3ce0a9de3978b3 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Wed, 10 Jul 2013 12:31:56 +0200 Subject: [PATCH] [WIP] Grouping of stock moves + stock_location should first check must precise procurement rule on _assign bzr revid: jco@openerp.com-20130710103156-9am4b4dkzr27ukhk --- addons/procurement/procurement.py | 2 +- addons/stock/procurement.py | 1 + addons/stock/stock.py | 25 ++++++++++++++++++++++--- addons/stock_location/stock_location.py | 7 +++---- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/addons/procurement/procurement.py b/addons/procurement/procurement.py index 4a3b0ccd128..282680aff36 100644 --- a/addons/procurement/procurement.py +++ b/addons/procurement/procurement.py @@ -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, diff --git a/addons/stock/procurement.py b/addons/stock/procurement.py index 62a5d04f2bd..ca1f5075ae7 100644 --- a/addons/stock/procurement.py +++ b/addons/stock/procurement.py @@ -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) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index c93d3b7a434..b2ccbe13da2 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -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): diff --git a/addons/stock_location/stock_location.py b/addons/stock_location/stock_location.py index 0f915c506fc..1f5c25e11ca 100644 --- a/addons/stock_location/stock_location.py +++ b/addons/stock_location/stock_location.py @@ -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