diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 2ede7b27b9d..2beed43af2e 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -198,9 +198,9 @@ class mrp_bom(osv.osv): 'type': fields.selection([('normal', 'Normal'), ('phantom', 'Set')], 'BoM Type', required=True, help= "Set: When processing a sales order for this product, the delivery order will contain the raw materials, instead of the finished product."), 'position': fields.char('Internal Reference', help="Reference to a position in an external plan."), - 'product_tmpl_id': fields.many2one('product.template', 'Product', required=True), + 'product_tmpl_id': fields.many2one('product.template', 'Product', domain="[('type', '!=', 'service')]", required=True), 'product_id': fields.many2one('product.product', 'Product Variant', - domain="[('product_tmpl_id','=',product_tmpl_id)]", + domain="['&', ('product_tmpl_id','=',product_tmpl_id), ('type','!=', 'service')]", help="If a product variant is defined the BOM is available only for this product."), 'bom_line_ids': fields.one2many('mrp.bom.line', 'bom_id', 'BoM Lines', copy=True), 'product_qty': fields.float('Product Quantity', required=True, digits_compute=dp.get_precision('Product Unit of Measure')), @@ -509,7 +509,7 @@ class mrp_production(osv.osv): for production in self.browse(cr, uid, ids, context=context): res[production.id] = True states = [x.state != 'assigned' for x in production.move_lines if x] - if any(states) or len(states) == 0: + if any(states) or len(states) == 0: #When no moves, ready_production will be False, but test_ready will pass res[production.id] = False return res @@ -527,7 +527,8 @@ class mrp_production(osv.osv): 'priority': fields.selection([('0', 'Not urgent'), ('1', 'Normal'), ('2', 'Urgent'), ('3', 'Very Urgent')], 'Priority', select=True, readonly=True, states=dict.fromkeys(['draft', 'confirmed'], [('readonly', False)])), - 'product_id': fields.many2one('product.product', 'Product', required=True, readonly=True, states={'draft': [('readonly', False)]}), + 'product_id': fields.many2one('product.product', 'Product', required=True, readonly=True, states={'draft': [('readonly', False)]}, + domain=[('type','!=','service')]), 'product_qty': fields.float('Product Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), required=True, readonly=True, states={'draft': [('readonly', False)]}), 'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True, readonly=True, states={'draft': [('readonly', False)]}), 'product_uos_qty': fields.float('Product UoS Quantity', readonly=True, states={'draft': [('readonly', False)]}), @@ -831,6 +832,8 @@ class mrp_production(osv.osv): dicts = {} # Find product qty to be consumed and consume it for scheduled in production.product_lines: + if scheduled.product_id.type == 'service': + continue product_id = scheduled.product_id.id consumed_qty = consumed_data.get(product_id, 0.0) @@ -1018,11 +1021,12 @@ class mrp_production(osv.osv): return res def test_ready(self, cr, uid, ids): - res = False + res = True for production in self.browse(cr, uid, ids): - if production.ready_production: - res = True + if production.move_lines and not production.ready_production: + res = False return res + def _make_production_produce_line(self, cr, uid, production, context=None): @@ -1115,6 +1119,26 @@ class mrp_production(osv.osv): def _make_production_consume_line(self, cr, uid, line, context=None): return self._make_consume_line_from_data(cr, uid, line.production_id, line.product_id, line.product_uom.id, line.product_qty, line.product_uos.id, line.product_uos_qty, context=context) + + def _make_service_procurement(self, cr, uid, line, context=None): + prod_obj = self.pool.get('product.product') + if prod_obj.need_procurement(cr, uid, [line.product_id.id], context=context): + vals = { + 'name': line.production_id.name, + 'origin': line.production_id.name, + 'company_id': line.production_id.company_id.id, + 'date_planned': line.production_id.date_planned, + 'product_id': line.product_id.id, + 'product_qty': line.product_qty, + 'product_uom': line.product_uom.id, + 'product_uos_qty': line.product_uos_qty, + 'product_uos': line.product_uos.id, + } + proc_obj = self.pool.get("procurement.order") + proc = proc_obj.create(cr, uid, vals, context=context) + proc_obj.run(cr, uid, [proc], context=context) + + def action_confirm(self, cr, uid, ids, context=None): """ Confirms production order. @return: Newly generated Shipment Id. @@ -1126,9 +1150,11 @@ class mrp_production(osv.osv): stock_moves = [] for line in production.product_lines: - stock_move_id = self._make_production_consume_line(cr, uid, line, context=context) - if stock_move_id: + if line.product_id.type != 'service': + stock_move_id = self._make_production_consume_line(cr, uid, line, context=context) stock_moves.append(stock_move_id) + else: + self._make_service_procurement(cr, uid, line, context=context) if stock_moves: self.pool.get('stock.move').action_confirm(cr, uid, stock_moves, context=context) production.write({'state': 'confirmed'}, context=context) @@ -1138,9 +1164,12 @@ class mrp_production(osv.osv): """ Checks the availability on the consume lines of the production order """ + from openerp import workflow move_obj = self.pool.get("stock.move") for production in self.browse(cr, uid, ids, context=context): move_obj.action_assign(cr, uid, [x.id for x in production.move_lines], context=context) + if self.pool.get('mrp.production').test_ready(cr, uid, [production.id]): + workflow.trg_validate(uid, 'mrp.production', production.id, 'moves_ready', cr) def force_production(self, cr, uid, ids, *args): @@ -1148,9 +1177,12 @@ class mrp_production(osv.osv): @param *args: Arguments @return: True """ + from openerp import workflow move_obj = self.pool.get('stock.move') for order in self.browse(cr, uid, ids): move_obj.force_assign(cr, uid, [x.id for x in order.move_lines]) + if self.pool.get('mrp.production').test_ready(cr, uid, [order.id]): + workflow.trg_validate(uid, 'mrp.production', order.id, 'moves_ready', cr) return True diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index bd622cb4a99..9bf317885d3 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -349,7 +349,6 @@ - - + 2 @@ -688,7 +688,7 @@ Weight: 1.1 ounces - +