[IMP]: stock, mrp: Changed logic of track lots, Improvement in functions of split...
[odoo/odoo.git] / addons / stock / stock_wizard.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 re
25 import time
26 import tools
27
28 class stock_move_track(osv.osv_memory):
29     _name = "stock.move.track"
30     _description = "Track moves"
31     
32     _columns = {
33         'tracking_prefix': fields.char('Tracking prefix', size=64), 
34         'quantity': fields.float("Quantity per lot")
35               }
36
37     _defaults = {
38         'quantity': lambda *x: 1
39                  }
40     
41     def track_lines(self, cr, uid, ids, context={}):
42         datas = self.read(cr, uid, ids)[0]
43         move_obj = self.pool.get('stock.move')
44         move_obj._track_lines(cr, uid, context['active_id'], datas, context=context)
45         return {}
46
47 stock_move_track()
48
49 class stock_move_consume(osv.osv_memory):
50     _name = "stock.move.consume"
51     _description = "Consume Products"
52     
53     _columns = {
54         'product_id': fields.many2one('product.product', 'Product', required=True, select=True), 
55         'product_qty': fields.float('Quantity', required=True), 
56         'product_uom': fields.many2one('product.uom', 'Product UOM', required=True), 
57         'location_id': fields.many2one('stock.location', 'Source Location', required=True)
58               }
59
60     def _get_product_id(self, cr, uid, context):
61         move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
62         return move.product_id.id
63     
64     def _get_product_qty(self, cr, uid, context):
65         move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
66         return move.product_qty
67     
68     def _get_product_uom(self, cr, uid, context):
69         move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
70         return move.product_uom.id
71     
72     def _get_location_id(self, cr, uid, context):
73         move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
74         return move.location_id.id
75     
76     _defaults = {
77                  'product_id': _get_product_id, 
78                  'product_qty': _get_product_qty, 
79                  'product_uom': _get_product_uom, 
80                  'location_id': _get_location_id
81                  }
82
83     def do_move_consume(self, cr, uid, ids, context={}):
84         datas = self.read(cr, uid, ids)[0]
85         move_obj = self.pool.get('stock.move')
86         move_obj.consume_moves(cr, uid, context['active_id'], 
87                          datas['product_qty'], datas['location_id'], 
88                          context=context)
89         return {}
90
91 stock_move_consume()
92
93
94 class stock_move_scrap(osv.osv_memory):
95     _name = "stock.move.scrap"
96     _description = "Scrap Products"
97     _inherit = "stock.move.consume"
98     
99     _defaults = {
100                  'location_id': lambda *x: False
101                  }
102
103     def move_scrap(self, cr, uid, ids, context={}):
104         datas = self.read(cr, uid, ids)[0]
105         move_obj = self.pool.get('stock.move')
106         move_obj.scrap_moves(cr, uid, context['active_id'], 
107                          datas['product_qty'], datas['location_id'], 
108                          context=context)
109         return {}
110
111 stock_move_scrap()
112
113
114 class spilt_in_lot(osv.osv_memory):
115     _name = "spilt.in.lot"
116     _description = "Split in lots"
117     
118     _columns = {
119         'product_id': fields.many2one('product.product', 'Product', required=True, select=True),
120         'line_ids': fields.one2many('track.lines', 'lot_id', 'Lots Number')
121               }
122     
123     def _get_product_id(self, cr, uid, context):
124         move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
125         return move.product_id.id
126     
127     _defaults = {
128                  'product_id': _get_product_id, 
129                  }
130     
131     def split_lot(self, cr, uid, ids, context=None):
132         datas = self.read(cr, uid, ids)[0]
133         lines = []
134         for line in self.pool.get('track.lines').browse(cr, uid, datas.get('line_ids', [])):
135             lines.append({'tracking_num': line.name, 'quantity': line.quantity})
136         move_obj = self.pool.get('stock.move')
137         move_obj._track_lines(cr, uid, context['active_id'], lines, context=context)
138         return {}
139
140 spilt_in_lot()
141
142 class track_lines(osv.osv_memory):
143     _name = "track.lines"
144     _description = "Track lines"
145     
146     _columns = {
147         'name': fields.char('Tracking serial', size=64), 
148         'quantity': fields.integer('Quantity'), 
149         'lot_id': fields.many2one('spilt.in.lot', 'Lot')
150               }
151
152 track_lines()