2010-02-24 08:17:06 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
2010-08-13 12:20:05 +00:00
|
|
|
#
|
2010-02-24 08:17:06 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-08-13 12:20:05 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-02-24 08:17:06 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.osv import fields, osv
|
2012-12-17 15:23:03 +00:00
|
|
|
import openerp.addons.decimal_precision as dp
|
2010-02-24 08:17:06 +00:00
|
|
|
|
2014-01-16 17:48:00 +00:00
|
|
|
|
|
|
|
class mrp_product_produce_line(osv.osv_memory):
|
|
|
|
_name="mrp.product.produce.line"
|
|
|
|
_description = "Product Produce Consume lines"
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
'product_id': fields.many2one('product.product', 'Product'),
|
2014-04-23 15:05:03 +00:00
|
|
|
'product_qty': fields.float('Quantity (in default UoM)'),
|
2014-01-16 17:48:00 +00:00
|
|
|
'lot_id': fields.many2one('stock.production.lot', 'Lot'),
|
2014-01-17 16:42:32 +00:00
|
|
|
'produce_id': fields.many2one('mrp.product.produce'),
|
|
|
|
'track_production': fields.related('product_id', 'track_production', type='boolean')
|
2014-01-16 17:48:00 +00:00
|
|
|
}
|
|
|
|
|
2010-02-24 08:17:06 +00:00
|
|
|
class mrp_product_produce(osv.osv_memory):
|
|
|
|
_name = "mrp.product.produce"
|
|
|
|
_description = "Product Produce"
|
2010-08-13 12:20:05 +00:00
|
|
|
|
2010-02-24 08:17:06 +00:00
|
|
|
_columns = {
|
2014-01-17 16:42:32 +00:00
|
|
|
'product_id': fields.many2one('product.product', type='many2one'),
|
2012-04-25 08:54:15 +00:00
|
|
|
'product_qty': fields.float('Select Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), required=True),
|
2010-08-13 12:20:05 +00:00
|
|
|
'mode': fields.selection([('consume_produce', 'Consume & Produce'),
|
2010-07-27 09:13:15 +00:00
|
|
|
('consume', 'Consume Only')], 'Mode', required=True,
|
|
|
|
help="'Consume only' mode will only consume the products with the quantity selected.\n"
|
|
|
|
"'Consume & Produce' mode will consume as well as produce the products with the quantity selected "
|
|
|
|
"and it will finish the production order when total ordered quantities are produced."),
|
2014-01-16 17:48:00 +00:00
|
|
|
'lot_id': fields.many2one('stock.production.lot', 'Lot'), #Should only be visible when it is consume and produce mode
|
|
|
|
'consume_lines': fields.one2many('mrp.product.produce.line', 'produce_id', 'Products Consumed'),
|
2014-01-17 16:42:32 +00:00
|
|
|
'track_production': fields.boolean('Track production'),
|
2010-02-24 08:17:06 +00:00
|
|
|
}
|
2014-02-05 09:34:11 +00:00
|
|
|
|
2014-01-16 17:48:00 +00:00
|
|
|
def on_change_qty(self, cr, uid, ids, product_qty, consume_lines, context=None):
|
2014-01-21 13:39:09 +00:00
|
|
|
"""
|
|
|
|
When changing the quantity of products to be produced it will
|
|
|
|
recalculate the number of raw materials needed according
|
|
|
|
to the scheduled products and the already consumed/produced products
|
|
|
|
It will return the consume lines needed for the products to be produced
|
|
|
|
which the user can still adapt
|
2014-01-16 17:48:00 +00:00
|
|
|
"""
|
|
|
|
prod_obj = self.pool.get("mrp.production")
|
|
|
|
production = prod_obj.browse(cr, uid, context['active_id'], context=context)
|
2014-02-05 09:34:11 +00:00
|
|
|
consume_lines = []
|
|
|
|
new_consume_lines = []
|
2014-01-21 13:39:09 +00:00
|
|
|
if product_qty > 0.0:
|
2014-02-05 09:34:11 +00:00
|
|
|
consume_lines = prod_obj._calculate_qty(cr, uid, production, product_qty=product_qty, context=context)
|
2014-01-16 17:48:00 +00:00
|
|
|
|
2014-01-21 13:39:09 +00:00
|
|
|
for consume in consume_lines:
|
2014-01-22 09:29:21 +00:00
|
|
|
new_consume_lines.append([0, False, consume])
|
2014-01-16 17:48:00 +00:00
|
|
|
return {'value': {'consume_lines': new_consume_lines}}
|
|
|
|
|
2010-02-24 08:17:06 +00:00
|
|
|
|
2010-11-19 13:48:01 +00:00
|
|
|
def _get_product_qty(self, cr, uid, context=None):
|
2010-04-05 12:28:03 +00:00
|
|
|
""" To obtain product quantity
|
|
|
|
@param self: The object pointer.
|
|
|
|
@param cr: A database cursor
|
|
|
|
@param uid: ID of the user currently logged in
|
|
|
|
@param context: A standard dictionary
|
2010-08-13 12:20:05 +00:00
|
|
|
@return: Quantity
|
|
|
|
"""
|
2010-11-23 07:05:05 +00:00
|
|
|
if context is None:
|
2010-11-19 13:48:01 +00:00
|
|
|
context = {}
|
2010-08-13 12:20:05 +00:00
|
|
|
prod = self.pool.get('mrp.production').browse(cr, uid,
|
2010-02-24 08:17:06 +00:00
|
|
|
context['active_id'], context=context)
|
|
|
|
done = 0.0
|
|
|
|
for move in prod.move_created_ids2:
|
2011-08-17 09:18:26 +00:00
|
|
|
if move.product_id == prod.product_id:
|
|
|
|
if not move.scrapped:
|
|
|
|
done += move.product_qty
|
2010-02-24 08:17:06 +00:00
|
|
|
return (prod.product_qty - done) or prod.product_qty
|
2010-08-13 12:20:05 +00:00
|
|
|
|
2014-01-17 16:42:32 +00:00
|
|
|
def _get_product_id(self, cr, uid, context=None):
|
|
|
|
""" To obtain product id
|
|
|
|
@return: id
|
|
|
|
"""
|
|
|
|
prod=False
|
|
|
|
if context and context.get("active_id"):
|
|
|
|
prod = self.pool.get('mrp.production').browse(cr, uid,
|
|
|
|
context['active_id'], context=context)
|
|
|
|
return prod and prod.product_id.id or False
|
|
|
|
|
|
|
|
def _get_track(self, cr, uid, context=None):
|
|
|
|
prod = self._get_product_id(cr, uid, context=context)
|
|
|
|
prod_obj = self.pool.get("product.product")
|
|
|
|
return prod and prod_obj.browse(cr, uid, prod, context=context).track_production or False
|
|
|
|
|
2010-02-24 08:17:06 +00:00
|
|
|
_defaults = {
|
2010-08-13 12:20:05 +00:00
|
|
|
'product_qty': _get_product_qty,
|
2014-01-17 16:42:32 +00:00
|
|
|
'mode': lambda *x: 'consume_produce',
|
|
|
|
'product_id': _get_product_id,
|
|
|
|
'track_production': _get_track,
|
2010-08-13 12:20:05 +00:00
|
|
|
}
|
2010-02-24 08:17:06 +00:00
|
|
|
|
2010-11-19 13:48:01 +00:00
|
|
|
def do_produce(self, cr, uid, ids, context=None):
|
2011-12-09 11:21:31 +00:00
|
|
|
production_id = context.get('active_id', False)
|
2012-07-25 09:25:48 +00:00
|
|
|
assert production_id, "Production Id should be specified in context as a Active ID."
|
2011-12-09 11:21:31 +00:00
|
|
|
data = self.browse(cr, uid, ids[0], context=context)
|
|
|
|
self.pool.get('mrp.production').action_produce(cr, uid, production_id,
|
2014-01-16 17:48:00 +00:00
|
|
|
data.product_qty, data.mode, data, context=context)
|
2010-02-24 08:17:06 +00:00
|
|
|
return {}
|
|
|
|
|
|
|
|
|
2010-08-05 10:20:52 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|