From: Denis Ledoux Date: Wed, 5 Nov 2014 12:40:30 +0000 (+0100) Subject: [MERGE] forward port of branch saas-3 up to c666030 X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;h=89716cb4d602fdd3379a0310ec0b9a56f9b88226;p=odoo%2Fodoo.git [MERGE] forward port of branch saas-3 up to c666030 --- 89716cb4d602fdd3379a0310ec0b9a56f9b88226 diff --cc addons/mrp/mrp.py index 2a59733,fcaac08..1efefca --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@@ -1048,77 -1000,24 +1048,79 @@@ class mrp_production(osv.osv) 'location_id': source_location_id, 'location_dest_id': destination_location_id, 'move_dest_id': production.move_prod_id.id, - 'state': 'waiting', + 'procurement_id': procurement_id, 'company_id': production.company_id.id, + 'production_id': production.id, + 'origin': production.name, } + if production.move_prod_id: + production.move_prod_id.write({'location_id': destination_location_id}) move_id = stock_move.create(cr, uid, data, context=context) - production.write({'move_created_ids': [(6, 0, [move_id])]}, context=context) - return move_id + #a phantom bom cannot be used in mrp order so it's ok to assume the list returned by action_confirm + #is 1 element long, so we can take the first. + return stock_move.action_confirm(cr, uid, [move_id], context=context)[0] - def _make_production_consume_line(self, cr, uid, production_line, parent_move_id, source_location_id=False, context=None): + def _get_raw_material_procure_method(self, cr, uid, product, context=None): + '''This method returns the procure_method to use when creating the stock move for the production raw materials''' + warehouse_obj = self.pool['stock.warehouse'] + try: + mto_route = warehouse_obj._get_mto_route(cr, uid, context=context) + except: + return "make_to_stock" + routes = product.route_ids + product.categ_id.total_route_ids + if mto_route in [x.id for x in routes]: + return "make_to_order" + return "make_to_stock" + + def _create_previous_move(self, cr, uid, move_id, product, source_location_id, dest_location_id, context=None): + ''' + When the routing gives a different location than the raw material location of the production order, + we should create an extra move from the raw material location to the location of the routing, which + precedes the consumption line (chained). The picking type depends on the warehouse in which this happens + and the type of locations. + ''' + loc_obj = self.pool.get("stock.location") stock_move = self.pool.get('stock.move') - production = production_line.production_id + type_obj = self.pool.get('stock.picking.type') + # Need to search for a picking type + move = stock_move.browse(cr, uid, move_id, context=context) + src_loc = loc_obj.browse(cr, uid, source_location_id, context=context) + dest_loc = loc_obj.browse(cr, uid, dest_location_id, context=context) + code = stock_move.get_code_from_locs(cr, uid, move, src_loc, dest_loc, context=context) + if code == 'outgoing': + check_loc = src_loc + else: + check_loc = dest_loc + wh = loc_obj.get_warehouse(cr, uid, check_loc, context=context) + domain = [('code', '=', code)] + if wh: + domain += [('warehouse_id', '=', wh)] + types = type_obj.search(cr, uid, domain, context=context) + move = stock_move.copy(cr, uid, move_id, default = { + 'location_id': source_location_id, + 'location_dest_id': dest_location_id, + 'procure_method': self._get_raw_material_procure_method(cr, uid, product, context=context), + 'raw_material_production_id': False, + 'move_dest_id': move_id, + 'picking_type_id': types and types[0] or False, + }, context=context) + return move + + def _make_consume_line_from_data(self, cr, uid, production, product, uom_id, qty, uos_id, uos_qty, context=None): + stock_move = self.pool.get('stock.move') + loc_obj = self.pool.get('stock.location') # Internal shipment is created for Stockable and Consumer Products - if production_line.product_id.type not in ('product', 'consu'): + if product.type not in ('product', 'consu'): return False + # Take routing location as a Source Location. + source_location_id = production.location_src_id.id + prod_location_id = source_location_id + prev_move= False + if production.bom_id.routing_id and production.bom_id.routing_id.location_id and production.bom_id.routing_id.location_id.id != source_location_id: + source_location_id = production.bom_id.routing_id.location_id.id + prev_move = True + destination_location_id = production.product_id.property_stock_production.id - if not source_location_id: - source_location_id = production.location_src_id.id move_id = stock_move.create(cr, uid, { 'name': production.name, 'date': production.date_planned,