~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to stock_override/wizard/stock_partial_picking.py

  • Committer: chloups208
  • Date: 2011-05-03 13:42:32 UTC
  • mto: (140.1.1 unifield-wm)
  • mto: This revision was merged to the branch mainline in revision 142.
  • Revision ID: chloups208@chloups208-laptop-20110503134232-omqmqbkrr8f3detr
[UF-33] correction of asset which is now linked to stock.move in a wizard when processing the stock.picking

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2011 TeMPO Consulting, MSF
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
from osv import fields, osv
 
23
from tools.translate import _
 
24
import time
 
25
 
 
26
class stock_partial_picking(osv.osv_memory):
 
27
    _inherit = "stock.partial.picking"
 
28
    _description = "Partial Picking with hook"
 
29
    
 
30
    
 
31
    def do_partial_hook(self, cr, uid, context, *args, **kwargs):
 
32
        '''
 
33
        add hook to do_partial
 
34
        '''
 
35
        partial_datas = kwargs.get('partial_datas')
 
36
        assert partial_datas, 'partial_datas missing'
 
37
        
 
38
        return partial_datas
 
39
    
 
40
 
 
41
    # @@@override stock>wizard>stock_partial_picking.py>stock_partial_picking
 
42
    def do_partial(self, cr, uid, ids, context=None):
 
43
        """ Makes partial moves and pickings done.
 
44
        @param self: The object pointer.
 
45
        @param cr: A database cursor
 
46
        @param uid: ID of the user currently logged in
 
47
        @param fields: List of fields for which we want default values
 
48
        @param context: A standard dictionary
 
49
        @return: A dictionary which of fields with values.
 
50
        """
 
51
        pick_obj = self.pool.get('stock.picking')
 
52
        
 
53
        picking_ids = context.get('active_ids', False)
 
54
        partial = self.browse(cr, uid, ids[0], context=context)
 
55
        partial_datas = {
 
56
            'delivery_date' : partial.date
 
57
        }
 
58
 
 
59
        for pick in pick_obj.browse(cr, uid, picking_ids, context=context):
 
60
            picking_type = self.get_picking_type(cr, uid, pick, context=context)
 
61
            moves_list = picking_type == 'in' and partial.product_moves_in or partial.product_moves_out
 
62
 
 
63
            for move in moves_list:
 
64
                partial_datas['move%s' % (move.move_id.id)] = {
 
65
                    'product_id': move.id, 
 
66
                    'product_qty': move.quantity, 
 
67
                    'product_uom': move.product_uom.id, 
 
68
                    'prodlot_id': move.prodlot_id.id, 
 
69
                }
 
70
                if (picking_type == 'in') and (move.product_id.cost_method == 'average'):
 
71
                    partial_datas['move%s' % (move.move_id.id)].update({
 
72
                                                    'product_price' : move.cost, 
 
73
                                                    'product_currency': move.currency.id, 
 
74
                                                    })
 
75
                    
 
76
                # override : add hook call
 
77
                partial_datas = self.do_partial_hook(cr, uid, context, move=move, partial_datas=partial_datas)
 
78
            
 
79
            
 
80
        pick_obj.do_partial(cr, uid, picking_ids, partial_datas, context=context)
 
81
        return {'type': 'ir.actions.act_window_close'}
 
82
    #@@@override end
 
83
 
 
84
stock_partial_picking()