~julie-w/unifield-wm/UTP-925

« back to all changes in this revision

Viewing changes to stock_inventory_type/stock.py

  • Committer: jf
  • Date: 2011-10-07 10:48:42 UTC
  • mfrom: (350.6.7 uf-488)
  • Revision ID: jf@tempo4-20111007104842-wdy7jllpnht7x1aq
UF-488 [MERE] reason types moves

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# -*- encoding: utf-8 -*-
3
 
##############################################################################
4
 
#
5
 
#    OpenERP, Open Source Management Solution
6
 
#    Copyright (C) 2011 TeMPO Consulting, MSF
7
 
#
8
 
#    This program is free software: you can redistribute it and/or modify
9
 
#    it under the terms of the GNU Affero General Public License as
10
 
#    published by the Free Software Foundation, either version 3 of the
11
 
#    License, or (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 Affero General Public License for more details.
17
 
#
18
 
#    You should have received a copy of the GNU Affero General Public License
19
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
#
21
 
##############################################################################
22
 
 
23
 
 
24
 
from osv import osv
25
 
from osv import fields
26
 
 
27
 
from tools.translate import _
28
 
 
29
 
 
30
 
class stock_adjustment_type(osv.osv):
31
 
    _name = 'stock.adjustment.type'
32
 
    _description = 'Inventory/Move Adjustment Types'
33
 
 
34
 
    _columns = {
35
 
        'name': fields.char(size=64, string='Name', required=True),
36
 
    }
37
 
 
38
 
stock_adjustment_type()
39
 
 
40
 
 
41
 
class stock_inventory_line(osv.osv):
42
 
    _name = 'stock.inventory.line'
43
 
    _inherit = 'stock.inventory.line'
44
 
 
45
 
    _columns = {
46
 
        'type_id': fields.many2one('stock.adjustment.type', string='Adjustment type'),
47
 
        'comment': fields.char(size=128, string='Comment'),
48
 
    }
49
 
 
50
 
stock_inventory_line()
51
 
 
52
 
 
53
 
class stock_move(osv.osv):
54
 
    _name = 'stock.move'
55
 
    _inherit = 'stock.move'
56
 
 
57
 
    _columns = {
58
 
        'type_id': fields.many2one('stock.adjustment.type', string='Adjustment type', readonly=True),
59
 
        'comment': fields.char(size=128, string='Comment'),
60
 
    }
61
 
 
62
 
stock_move()
63
 
 
64
 
 
65
 
class stock_inventory(osv.osv):
66
 
    _name = 'stock.inventory'
67
 
    _inherit = 'stock.inventory'
68
 
    
69
 
    # @@@override@ stock.stock_inventory._inventory_line_hook()
70
 
    def _inventory_line_hook(self, cr, uid, inventory_line, move_vals):
71
 
        """ Creates a stock move from an inventory line
72
 
        @param inventory_line:
73
 
        @param move_vals:
74
 
        @return:
75
 
        """
76
 
        location_obj = self.pool.get('stock.location')
77
 
        
78
 
        type_id = inventory_line.type_id and inventory_line.type_id.id or False
79
 
        
80
 
        # Copy the comment
81
 
        move_vals.update({
82
 
            'comment': inventory_line.comment,
83
 
        })
84
 
        
85
 
        location = location_obj.browse(cr, uid, move_vals['location_dest_id'])
86
 
        
87
 
        if type_id:
88
 
            move_vals.update({
89
 
                'type_id': type_id,
90
 
            })
91
 
            
92
 
        if location.usage == 'inventory':
93
 
            reason_type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'reason_types_moves', 'reason_type_loss')[1]
94
 
            move_vals.update({
95
 
                'reason_type_id': reason_type_id,
96
 
            })
97
 
            
98
 
        if location.scrap_location:
99
 
            reason_type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'reason_types_moves', 'reason_type_scrap')[1]
100
 
            move_vals.update({
101
 
                'reason_type_id': reason_type_id,
102
 
            })
103
 
            
104
 
        if inventory_line.type_id and type_id == self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock_inventory_type', 'adjustment_type_expired')[1]:
105
 
            reason_type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'reason_types_moves', 'reason_type_expiry')[1]
106
 
            move_vals.update({
107
 
                'reason_type_id': reason_type_id,
108
 
            })
109
 
            
110
 
        if inventory_line.location_id.id == move_vals.get('location_dest_id'):
111
 
            reason_type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'reason_types_moves', 'reason_type_discrepancy')[1]
112
 
            move_vals.update({
113
 
                'reason_type_id': reason_type_id,
114
 
            })
115
 
        
116
 
        return super(stock_inventory, self)._inventory_line_hook(cr, uid, inventory_line, move_vals) 
117
 
        # @@@end
118
 
 
119
 
stock_inventory()
120
 
 
121
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
122