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 openerp.osv import fields, osv
23 import openerp.addons.decimal_precision as dp
25 class mrp_product_produce(osv.osv_memory):
26 _name = "mrp.product.produce"
27 _description = "Product Produce"
30 'product_qty': fields.float('Select Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), required=True),
31 'mode': fields.selection([('consume_produce', 'Consume & Produce'),
32 ('consume', 'Consume Only')], 'Mode', required=True,
33 help="'Consume only' mode will only consume the products with the quantity selected.\n"
34 "'Consume & Produce' mode will consume as well as produce the products with the quantity selected "
35 "and it will finish the production order when total ordered quantities are produced."),
38 def _get_product_qty(self, cr, uid, context=None):
39 """ To obtain product quantity
40 @param self: The object pointer.
41 @param cr: A database cursor
42 @param uid: ID of the user currently logged in
43 @param context: A standard dictionary
48 prod = self.pool.get('mrp.production').browse(cr, uid,
49 context['active_id'], context=context)
51 for move in prod.move_created_ids2:
52 if move.product_id == prod.product_id:
54 done += move.product_qty
55 return (prod.product_qty - done) or prod.product_qty
58 'product_qty': _get_product_qty,
59 'mode': lambda *x: 'consume_produce'
62 def do_produce(self, cr, uid, ids, context=None):
63 production_id = context.get('active_id', False)
64 assert production_id, "Production Id should be specified in context as a Active ID."
65 data = self.browse(cr, uid, ids[0], context=context)
66 self.pool.get('mrp.production').action_produce(cr, uid, production_id,
67 data.product_qty, data.mode, context=context)
71 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: