From d90d20851b9d4f13cbe0dfc08cd68ee98b1b3f71 Mon Sep 17 00:00:00 2001 From: "ronald@therp.nl" Date: Wed, 18 Jun 2014 12:20:27 +0000 Subject: [PATCH] [FIX] stock: Expected date on stock.picking will change, if Expected date on stock.move changes. This fixes bug lp1266480. https://launchpad.net/bugs/914670 --- addons/stock/stock.py | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index b1ae930dadcb3..26647d8118a82 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -629,6 +629,16 @@ def get_min_max_date(self, cr, uid, ids, field_name, arg, context=None): res[pick]['min_date'] = dt1 res[pick]['max_date'] = dt2 return res + + def _get_stock_move_changes(self, cr, uid, ids, context=None): + '''Return the ids of pickings that should change, due to changes + in stock moves.''' + move_pool = self.pool['stock.move'] + picking_ids = set() + for move_obj in move_pool.browse(cr, uid, ids, context=context): + if move_obj.picking_id: + picking_ids.add(move_obj.picking_id.id) + return list(picking_ids) def create(self, cr, user, vals, context=None): if ('name' not in vals) or (vals.get('name')=='/'): @@ -664,12 +674,31 @@ def create(self, cr, user, vals, context=None): * Transferred: has been processed, can't be modified or cancelled anymore\n * Cancelled: has been cancelled, can't be confirmed anymore""" ), - 'min_date': fields.function(get_min_max_date, fnct_inv=_set_minimum_date, multi="min_max_date", - store=True, type='datetime', string='Scheduled Time', select=1, help="Scheduled time for the shipment to be processed"), + 'min_date': fields.function( + get_min_max_date, + fnct_inv=_set_minimum_date, multi='min_max_date', + store={ + 'stock.move': ( + _get_stock_move_changes, + ['date_expected'], 10, + ) + }, + type='datetime', string='Scheduled Time', select=True, + help="Scheduled time for the shipment to be processed" + ), 'date': fields.datetime('Creation Date', help="Creation date, usually the time of the order.", select=True, states={'done':[('readonly', True)], 'cancel':[('readonly',True)]}), 'date_done': fields.datetime('Date of Transfer', help="Date of Completion", states={'done':[('readonly', True)], 'cancel':[('readonly',True)]}), - 'max_date': fields.function(get_min_max_date, fnct_inv=_set_maximum_date, multi="min_max_date", - store=True, type='datetime', string='Max. Expected Date', select=2), + 'max_date': fields.function( + get_min_max_date, + fnct_inv=_set_maximum_date, multi='min_max_date', + store={ + 'stock.move': ( + _get_stock_move_changes, + ['date_expected'], 10, + ) + }, + type='datetime', string='Max. Expected Date', select=True + ), 'move_lines': fields.one2many('stock.move', 'picking_id', 'Internal Moves', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}), 'product_id': fields.related('move_lines', 'product_id', type='many2one', relation='product.product', string='Product'), 'auto_picking': fields.boolean('Auto-Picking', states={'done':[('readonly', True)], 'cancel':[('readonly',True)]}),