1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
22 from osv import fields, osv
23 from tools.translate import _
28 class stock_move_track(osv.osv_memory):
29 _name = "stock.move.track"
30 _description = "Track moves"
33 'tracking_prefix': fields.char('Tracking prefix', size=64),
34 'quantity': fields.float("Quantity per lot")
38 'quantity': lambda *x: 1
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)
49 class stock_move_consume(osv.osv_memory):
50 _name = "stock.move.consume"
51 _description = "Consume Products"
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)
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
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
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
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
77 'product_id': _get_product_id,
78 'product_qty': _get_product_qty,
79 'product_uom': _get_product_uom,
80 'location_id': _get_location_id
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'],
94 class stock_move_scrap(osv.osv_memory):
95 _name = "stock.move.scrap"
96 _description = "Scrap Products"
97 _inherit = "stock.move.consume"
100 'location_id': lambda *x: False
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'],
114 class spilt_in_lot(osv.osv_memory):
115 _name = "spilt.in.lot"
116 _description = "Split in lots"
119 'product_id': fields.many2one('product.product', 'Product', required=True, select=True),
120 'line_ids': fields.one2many('track.lines', 'lot_id', 'Lots Number')
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
128 'product_id': _get_product_id,
131 def split_lot(self, cr, uid, ids, context=None):
132 datas = self.read(cr, uid, ids)[0]
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)
142 class track_lines(osv.osv_memory):
143 _name = "track.lines"
144 _description = "Track lines"
147 'name': fields.char('Tracking serial', size=64),
148 'quantity': fields.integer('Quantity'),
149 'lot_id': fields.many2one('spilt.in.lot', 'Lot')