~pexego/openobject-addons/6.1-pexego-new-addons

« back to all changes in this revision

Viewing changes to product_lifo_price/wizard/wizard_partial_picking.py

  • Committer: Omar (pexego)
  • Date: 2012-07-27 08:40:22 UTC
  • Revision ID: omar@pexego.es-20120727084022-qp3ludpr3vsuyuf6
[ADD] Traceability modules ported to 6.1

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) 2004-2011 Pexego (<www.pexego.es>). All Rights Reserved
 
6
#    $Omar Castiñeira Saavedra$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from osv import osv
 
24
 
 
25
class partial_picking(osv.osv_memory):
 
26
 
 
27
    _inherit = 'stock.partial.picking'
 
28
 
 
29
    def get_picking_type(self, cr, uid, picking, context=None):
 
30
        if context is None: context = {}
 
31
        picking_type = picking.type
 
32
 
 
33
        if picking_type != "in":
 
34
            for move in picking.move_lines:
 
35
                if picking.type == 'in' and move.product_id.cost_method == 'lifo':
 
36
                    picking_type = 'in'
 
37
                    break
 
38
        return picking_type
 
39
 
 
40
    def do_partial(self, cr, uid, ids, context=None):
 
41
        """ Makes partial moves and pickings done.
 
42
        @param self: The object pointer.
 
43
        @param cr: A database cursor
 
44
        @param uid: ID of the user currently logged in
 
45
        @param fields: List of fields for which we want default values
 
46
        @param context: A standard dictionary
 
47
        @return: A dictionary which of fields with values.
 
48
        """
 
49
        if context is None: context = {}
 
50
        res = super(partial_picking, self).do_partial(cr, uid, ids, context=context)
 
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
 
 
56
        for pick in pick_obj.browse(cr, uid, picking_ids, context=context):
 
57
            picking_type = self.get_picking_type(cr, uid, pick, context=context)
 
58
            moves_list = picking_type == 'in' and partial.move_ids or []
 
59
 
 
60
            for move in moves_list:
 
61
                if move.product_id.cost_method == 'lifo':
 
62
                    self.pool.get('product.product').write(cr, uid, [move.product_id.id],  {'standard_price': move.cost})
 
63
 
 
64
        return res
 
65
 
 
66
partial_picking()
 
 
b'\\ No newline at end of file'