diff --git a/addons/mrp/__openerp__.py b/addons/mrp/__openerp__.py index 588ba103f04..b1f5a549c44 100644 --- a/addons/mrp/__openerp__.py +++ b/addons/mrp/__openerp__.py @@ -92,13 +92,9 @@ Dashboard provided by this module: 'mrp_demo.xml', ], 'test': [ - 'test/mrp_procurement.yml', - 'test/mrp_packs.yml', - 'test/mrp_phantom_bom.yml', - 'test/mrp_production_order.yml', - 'test/mrp_production_cancel.yml', - 'test/mrp_report.yml', - + 'test/order_demo.yml', + 'test/order_process.yml', + 'test/cancel_order.yml', ], 'installable': True, 'application': True, diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index dea664f6fd6..c8f0b6b7e21 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -62,8 +62,6 @@ class mrp_workcenter(osv.osv): } def on_change_product_cost(self, cr, uid, ids, product_id, context=None): - if context is None: - context = {} value = {} if product_id: @@ -253,8 +251,7 @@ class mrp_bom(osv.osv): all_prod.append(bom.product_id.id) lines = bom.bom_lines if lines: - newboms = [a for a in lines if a not in boms] - res = res and check_bom(newboms) + res = res and check_bom([bom_id for bom_id in lines if bom_id not in boms]) return res return check_bom(boms) @@ -269,14 +266,9 @@ class mrp_bom(osv.osv): @param product_id: Changed product_id @return: Dictionary of changed values """ - if context is None: - context = {} - context['lang'] = self.pool.get('res.users').browse(cr,uid,uid).context_lang - if product_id: prod = self.pool.get('product.product').browse(cr, uid, product_id, context=context) - v = {'name': prod.name, 'product_uom': prod.uom_id.id} - return {'value': v} + return {'value': {'name': prod.name, 'product_uom': prod.uom_id.id}} return {} def _bom_find(self, cr, uid, product_id, product_uom, properties=[]): @@ -320,6 +312,7 @@ class mrp_bom(osv.osv): phantom = False if bom.type == 'phantom' and not bom.bom_lines: newbom = self._bom_find(cr, uid, bom.product_id.id, bom.product_uom.id, properties) + if newbom: res = self._bom_explode(cr, uid, self.browse(cr, uid, [newbom])[0], factor*bom.product_qty, properties, addthis=True, level=level+10) result = result + res[0] @@ -361,8 +354,6 @@ class mrp_bom(osv.osv): def copy_data(self, cr, uid, id, default=None, context=None): if default is None: default = {} - if context is None: - context = {} bom_data = self.read(cr, uid, id, [], context=context) default.update({'name': bom_data['name'] + ' ' + _('Copy'), 'bom_id':False}) return super(mrp_bom, self).copy_data(cr, uid, id, default, context=context) @@ -497,8 +488,7 @@ class mrp_production(osv.osv): _order = 'priority desc, date_planned asc'; def _check_qty(self, cr, uid, ids, context=None): - orders = self.browse(cr, uid, ids, context=context) - for order in orders: + for order in self.browse(cr, uid, ids, context=context): if order.product_qty <= 0: return False return True @@ -508,14 +498,10 @@ class mrp_production(osv.osv): ] def unlink(self, cr, uid, ids, context=None): - productions = self.read(cr, uid, ids, ['state']) - unlink_ids = [] - for s in productions: - if s['state'] in ['draft','cancel']: - unlink_ids.append(s['id']) - else: - raise osv.except_osv(_('Invalid action !'), _('Cannot delete a manufacturing order in the state \'%s\'!') % s['state']) - return osv.osv.unlink(self, cr, uid, unlink_ids, context=context) + for production in self.browse(cr, uid, ids, context=context): + if production.state not in ('draft', 'cancel'): + raise osv.except_osv(_('Invalid action !'), _('Cannot delete a manufacturing order in state \'%s\'') % production.state) + return super(mrp_production, self).unlink(cr, uid, ids, context=context) def copy(self, cr, uid, id, default=None, context=None): if default is None: @@ -577,8 +563,7 @@ class mrp_production(osv.osv): return {'value': { 'routing_id': False }} - bom_pool = self.pool.get('mrp.bom') - bom_point = bom_pool.browse(cr, uid, bom_id, context=context) + bom_point = self.pool.get('mrp.bom').browse(cr, uid, bom_id, context=context) routing_id = bom_point.routing_id.id or False result = { 'routing_id': routing_id @@ -592,7 +577,7 @@ class mrp_production(osv.osv): self.write(cr, uid, ids, {'state': 'picking_except'}) return True - def action_compute(self, cr, uid, ids, properties=[]): + def action_compute(self, cr, uid, ids, properties=[], context=None): """ Computes bills of material of a product. @param properties: List containing dictionaries of properties. @return: No. of products. @@ -747,7 +732,7 @@ class mrp_production(osv.osv): # if qtys we have to consume is more than qtys available to consume prod_name = scheduled.product_id.name_get()[0][1] raise osv.except_osv(_('Warning!'), _('You are going to consume total %s quantities of "%s".\nBut you can consume upto total %s quantities.' % (qty, prod_name, qty_avail))) - if qty < 0.0: + if qty <= 0.0: # we already have more qtys consumed than we need continue @@ -855,119 +840,169 @@ class mrp_production(osv.osv): def _get_auto_picking(self, cr, uid, production): return True - def action_confirm(self, cr, uid, ids): - """ Confirms production order. - @return: Newly generated picking Id. - """ - picking_id = False - proc_ids = [] - seq_obj = self.pool.get('ir.sequence') - pick_obj = self.pool.get('stock.picking') - move_obj = self.pool.get('stock.move') - proc_obj = self.pool.get('procurement.order') + def _make_production_line_procurement(self, cr, uid, production_line, shipment_move_id, context=None): wf_service = netsvc.LocalService("workflow") - for production in self.browse(cr, uid, ids): - if not production.product_lines: - self.action_compute(cr, uid, [production.id]) - production = self.browse(cr, uid, [production.id])[0] - routing_loc = None - pick_type = 'internal' - address_id = False - if production.bom_id.routing_id and production.bom_id.routing_id.location_id: - routing_loc = production.bom_id.routing_id.location_id - if routing_loc.usage <> 'internal': - pick_type = 'out' - address_id = routing_loc.address_id and routing_loc.address_id.id or False - routing_loc = routing_loc.id - pick_name = seq_obj.get(cr, uid, 'stock.picking.' + pick_type) - picking_id = pick_obj.create(cr, uid, { - 'name': pick_name, - 'origin': (production.origin or '').split(':')[0] + ':' + production.name, - 'type': pick_type, - 'move_type': 'one', - 'state': 'auto', - 'address_id': address_id, - 'auto_picking': self._get_auto_picking(cr, uid, production), - 'company_id': production.company_id.id, - }) - - source = production.product_id.product_tmpl_id.property_stock_production.id - data = { - 'name':'PROD:' + production.name, - 'date': production.date_planned, - 'product_id': production.product_id.id, - 'product_qty': production.product_qty, - 'product_uom': production.product_uom.id, - 'product_uos_qty': production.product_uos and production.product_uos_qty or False, - 'product_uos': production.product_uos and production.product_uos.id or False, - 'location_id': source, - 'location_dest_id': production.location_dest_id.id, - 'move_dest_id': production.move_prod_id.id, - 'state': 'waiting', - 'company_id': production.company_id.id, - } - res_final_id = move_obj.create(cr, uid, data) - - self.write(cr, uid, [production.id], {'move_created_ids': [(6, 0, [res_final_id])]}) - moves = [] - for line in production.product_lines: - move_id = False - newdate = production.date_planned - if line.product_id.type in ('product', 'consu'): - res_dest_id = move_obj.create(cr, uid, { - 'name':'PROD:' + production.name, - 'date': production.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 and line.product_uos_qty or False, - 'product_uos': line.product_uos and line.product_uos.id or False, - 'location_id': routing_loc or production.location_src_id.id, - 'location_dest_id': source, - 'move_dest_id': res_final_id, - 'state': 'waiting', - 'company_id': production.company_id.id, - }) - moves.append(res_dest_id) - move_id = move_obj.create(cr, uid, { - 'name':'PROD:' + production.name, - 'picking_id':picking_id, - 'product_id': line.product_id.id, - 'product_qty': line.product_qty, - 'product_uom': line.product_uom.id, - 'product_uos_qty': line.product_uos and line.product_uos_qty or False, - 'product_uos': line.product_uos and line.product_uos.id or False, - 'date': newdate, - 'move_dest_id': res_dest_id, - 'location_id': production.location_src_id.id, - 'location_dest_id': routing_loc or production.location_src_id.id, - 'state': 'waiting', - 'company_id': production.company_id.id, - }) - proc_id = proc_obj.create(cr, uid, { - 'name': (production.origin or '').split(':')[0] + ':' + production.name, - 'origin': (production.origin or '').split(':')[0] + ':' + production.name, - 'date_planned': newdate, - 'product_id': line.product_id.id, - 'product_qty': line.product_qty, - 'product_uom': line.product_uom.id, - 'product_uos_qty': line.product_uos and line.product_qty or False, - 'product_uos': line.product_uos and line.product_uos.id or False, - 'location_id': production.location_src_id.id, - 'procure_method': line.product_id.procure_method, - 'move_id': move_id, + procurement_order = self.pool.get('procurement.order') + production = production_line.production_id + location_id = production.location_src_id.id + date_planned = production.date_planned + procurement_name = (production.origin or '').split(':')[0] + ':' + production.name + procurement_id = procurement_order.create(cr, uid, { + 'name': procurement_name, + 'origin': procurement_name, + 'date_planned': date_planned, + 'product_id': production_line.product_id.id, + 'product_qty': production_line.product_qty, + 'product_uom': production_line.product_uom.id, + 'product_uos_qty': production_line.product_uos and production_line.product_qty or False, + 'product_uos': production_line.product_uos and production_line.product_uos.id or False, + 'location_id': location_id, + 'procure_method': production_line.product_id.procure_method, + 'move_id': shipment_move_id, 'company_id': production.company_id.id, }) - wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr) - proc_ids.append(proc_id) - wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) - self.write(cr, uid, [production.id], {'picking_id': picking_id, 'move_lines': [(6,0,moves)], 'state':'confirmed'}) + wf_service.trg_validate(uid, procurement_order._name, procurement_id, 'button_confirm', cr) + return procurement_id + + def _make_production_internal_shipment_line(self, cr, uid, production_line, shipment_id, parent_move_id, destination_location_id=False, context=None): + stock_move = self.pool.get('stock.move') + production = production_line.production_id + date_planned = production.date_planned + # Internal shipment is created for Stockable and Consumer Products + if production_line.product_id.type not in ('product', 'consu'): + return False + move_name = _('PROD: %s') % production.name + source_location_id = production.location_src_id.id + if not destination_location_id: + destination_location_id = source_location_id + return stock_move.create(cr, uid, { + 'name': move_name, + 'picking_id': shipment_id, + 'product_id': production_line.product_id.id, + 'product_qty': production_line.product_qty, + 'product_uom': production_line.product_uom.id, + 'product_uos_qty': production_line.product_uos and production_line.product_uos_qty or False, + 'product_uos': production_line.product_uos and production_line.product_uos.id or False, + 'date': date_planned, + 'move_dest_id': parent_move_id, + 'location_id': source_location_id, + 'location_dest_id': destination_location_id, + 'state': 'waiting', + 'company_id': production.company_id.id, + }) + + def _make_production_internal_shipment(self, cr, uid, production, context=None): + ir_sequence = self.pool.get('ir.sequence') + stock_picking = self.pool.get('stock.picking') + routing_loc = None + pick_type = 'internal' + address_id = False + + # Take routing address as a Shipment Address. + # If usage of routing location is a internal, make outgoing shipment otherwise internal shipment + if production.bom_id.routing_id and production.bom_id.routing_id.location_id: + routing_loc = production.bom_id.routing_id.location_id + if routing_loc.usage <> 'internal': + pick_type = 'out' + address_id = routing_loc.address_id and routing_loc.address_id.id or False + + # Take next Sequence number of shipment base on type + pick_name = ir_sequence.get(cr, uid, 'stock.picking.' + pick_type) + + picking_id = stock_picking.create(cr, uid, { + 'name': pick_name, + 'origin': (production.origin or '').split(':')[0] + ':' + production.name, + 'type': pick_type, + 'move_type': 'one', + 'state': 'auto', + 'address_id': address_id, + 'auto_picking': self._get_auto_picking(cr, uid, production), + 'company_id': production.company_id.id, + }) + production.write({'picking_id': picking_id}, context=context) + return picking_id + + def _make_production_produce_line(self, cr, uid, production, context=None): + stock_move = self.pool.get('stock.move') + source_location_id = production.product_id.product_tmpl_id.property_stock_production.id + destination_location_id = production.location_dest_id.id + move_name = _('PROD: %s') + production.name + data = { + 'name': move_name, + 'date': production.date_planned, + 'product_id': production.product_id.id, + 'product_qty': production.product_qty, + 'product_uom': production.product_uom.id, + 'product_uos_qty': production.product_uos and production.product_uos_qty or False, + 'product_uos': production.product_uos and production.product_uos.id or False, + 'location_id': source_location_id, + 'location_dest_id': destination_location_id, + 'move_dest_id': production.move_prod_id.id, + 'state': 'waiting', + 'company_id': production.company_id.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 + + def _make_production_consume_line(self, cr, uid, production_line, parent_move_id, source_location_id=False, context=None): + stock_move = self.pool.get('stock.move') + production = production_line.production_id + # Internal shipment is created for Stockable and Consumer Products + if production_line.product_id.type not in ('product', 'consu'): + return False + move_name = _('PROD: %s') % production.name + destination_location_id = production.product_id.product_tmpl_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': move_name, + 'date': production.date_planned, + 'product_id': production_line.product_id.id, + 'product_qty': production_line.product_qty, + 'product_uom': production_line.product_uom.id, + 'product_uos_qty': production_line.product_uos and production_line.product_uos_qty or False, + 'product_uos': production_line.product_uos and production_line.product_uos.id or False, + 'location_id': source_location_id, + 'location_dest_id': destination_location_id, + 'move_dest_id': parent_move_id, + 'state': 'waiting', + 'company_id': production.company_id.id, + }) + production.write({'move_lines': [(4, move_id)]}, context=context) + return move_id + + def action_confirm(self, cr, uid, ids, context=None): + """ Confirms production order. + @return: Newly generated Shipment Id. + """ + shipment_id = False + wf_service = netsvc.LocalService("workflow") + uncompute_ids = filter(lambda x:x, [not x.product_lines and x.id or False for x in self.browse(cr, uid, ids, context=context)]) + self.action_compute(cr, uid, uncompute_ids, context=context) + for production in self.browse(cr, uid, ids, context=context): + shipment_id = self._make_production_internal_shipment(cr, uid, production, context=context) + produce_move_id = self._make_production_produce_line(cr, uid, production, context=context) + + # Take routing location as a Source Location. + source_location_id = production.location_src_id.id + if production.bom_id.routing_id and production.bom_id.routing_id.location_id: + source_location_id = production.bom_id.routing_id.location_id.id + + for line in production.product_lines: + consume_move_id = self._make_production_consume_line(cr, uid, line, produce_move_id, source_location_id=source_location_id, context=context) + shipment_move_id = self._make_production_internal_shipment_line(cr, uid, line, shipment_id, consume_move_id,\ + destination_location_id=source_location_id, context=context) + self._make_production_line_procurement(cr, uid, line, shipment_move_id, context=context) + + wf_service.trg_validate(uid, 'stock.picking', shipment_id, 'button_confirm', cr) + production.write({'state':'confirmed'}, context=context) message = _("Manufacturing order '%s' is scheduled for the %s.") % ( production.name, datetime.strptime(production.date_planned,'%Y-%m-%d %H:%M:%S').strftime('%m/%d/%Y'), ) self.log(cr, uid, production.id, message) - return picking_id + return shipment_id def force_production(self, cr, uid, ids, *args): """ Assigns products. diff --git a/addons/mrp/mrp_demo.xml b/addons/mrp/mrp_demo.xml index d19a99a12ca..547bf298315 100644 --- a/addons/mrp/mrp_demo.xml +++ b/addons/mrp/mrp_demo.xml @@ -5,6 +5,32 @@ + + + normal + ASML - HOUR + Costing Account For Hours of Assembly. + + + + normal + ASML - Cycle + Costing Account For Cycle of Assembly. + + + + + Assembly Service + + + + 0.1 + + + service + Assembly Service Cost + + - [1] Assembly Line 1 - [2] Custom Assembly Line - [3] Component Manufacturing @@ -154,18 +192,38 @@ Short time assembly 2 + 5 long time assembly 5 + 2 + 15 + + + + Testing + 1 + 10 + + + + + + Packing + 0.5 + 5 + + 0.5 3 + 5 assembly main + processor + fan @@ -214,7 +272,7 @@ - RAM on demand + RAM512 on demand 18 1.0 @@ -254,12 +312,12 @@ - RAM on demand + RAM256 on demand 36 1.0 phantom - + @@ -267,42 +325,28 @@ 38 1.0 + - + KIT - Kit Mouse + Kit Keyboard + Mouse 40 1.0 - normal + phantom - - - - Keyboard - 42 - - 1.0 - - - - - Mouse - 44 - - 1.0 - - + + Moon PC 45 1.0 - + Mainboard ASUStek A7N8X @@ -502,6 +546,35 @@ + + + KIT + 15 + Kit Keyboard + Mouse + + 1.0 + normal + + + + + Mouse + 121 + + 1.0 + + + + + + Keyboard + 123 + + 1.0 + + + + Regular processor config 111 @@ -536,176 +609,496 @@ Kit Keyboard + Mouse 1.0 - normal + phantom - - Mouse - 121 - - 1.0 - - - - - Keyboard - 123 - - 1.0 - - - - + + Default BOM for Shelf of 100cm SHE100 - 129 + 10 - 1.0 + 1.0 + + + + + + + Side Panel + 101 + + + 2.0 + Assembly Section - 123 + 102 - 4.0 - - - - - Side Panel - 125 - - - 2.0 - - - - - Metal Cleats - 127 - - - 12.0 - + 4.0 + + phantom - 131 + 103 - 1.0 + 1.0 Rear panel SHE100 + phantom - 133 + 104 - 3.0 - Shelf 100 + 3.0 + RCK100 + phantom + + + + + 133 + + + 1.0 + RCK100 + + + 1331 + + + + 1.0 + phantom + SPAN100 + + + 1332 + + + + 4.0 + METC000 + + + + 135 + + + 1.0 + SPAN100 + + + 1351 + + + + 0.083 + WOOD010 + + + + Assembly Section + 123 + + + 1.0 + + - 135 + 1231 - - 1.0 - - Wood Lintel 4m + 0.25 + + Wood Lintel 0.25m + + + 131 + + + 1.0 + Rear panel SHE100 + + + + 1311 + + + + 0.25 + WOOD002 0.25m + + Default BOM for Shelf of 200cm SHE200 - 137 - + 137 + - 1.0 - - - - Default BOM for KIT Shelf of 100cm - SHE100KIT - 139 - - - 1.0 - phantom - - - - Assembly Section - 143 - - - 4.0 - - - - - Side Panel - 145 - - - 2.0 - + 1.0 + - 147 - + 147 + - 1.0 + 1.0 Rear panel SHE200 Assembly Section - 149 + 149 - 4.0 + 4.0 Side Panel - 151 + 151 - 2.0 + 2.0 - 153 + 153 - 3.0 + 3.0 Shelf 200 Metal Cleats - 155 + 155 - 12.0 + 12.0 + + + Default BOM for KIT Shelf of 100cm + SHE100KIT + 139 + + + 1.0 + phantom + + + + + + Assembly Section + 143 + + + 4.0 + + + + + Side Panel + 145 + + + 2.0 + + + + + + + Dozen + + bigger + + + + + + + 3 + + + + + + + + + Fluid + + + Litre + + 1.0 + + + + Orange Juice + make_to_order + produce + product + + + + + + Orange + make_to_stock + buy + product + + + + + + + 1.0 + + + + + Sugar + make_to_stock + buy + product + + + + + + + + 2.0 + + + + Water + make_to_order + buy + consu + + + + + + + + 2.0 + + + + 200 + + + 1.0 + Orange Juice + phantom + + + + 201 + + + 0.5 + Orange + normal + + + + 202 + + + 0.02 + Sugar + normal + + + + 203 + + + 0.80 + Water + normal + + + + + + 10.0 + 5.0 + 1 + + + + + + + + 4.0 + 2.0 + 1 + max + + + + + + + + + + 100.00 + + + + + Shirt + make_to_stock + produce + product + + + + + + Cloth + make_to_order + buy + product + + + + + + + + 300.0 + + + + Shirt Buttons + make_to_stock + buy + product + + + + + + + + 100.0 + + + 300 + + + 1.0 + Shirt + + + + 301 + + + 1.0 + Cloth + normal + + + + 302 + + + 8.0 + Shirt Buttons + normal + + + + + + + 50.0 + 10.0 + 1 + max + + + + + + + + + + @@ -714,11 +1107,9 @@ - - diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index eb1070ac941..080456d17e8 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -317,7 +317,7 @@
- + diff --git a/addons/mrp/product.py b/addons/mrp/product.py index c3f9ee855df..1bc3bb749ce 100644 --- a/addons/mrp/product.py +++ b/addons/mrp/product.py @@ -25,37 +25,9 @@ from tools.translate import _ class product_product(osv.osv): _inherit = "product.product" - - def get_product_accounts(self, cr, uid, product_id, context=None): - """ To get the stock input account, stock output account and stock journal related to product. - @param product_id: product id - @return: dictionary which contains information regarding stock input account, stock output account and stock journal - """ - product_obj = self.pool.get('product.product').browse(cr, uid, product_id, False) - res = super(product_product,self).get_product_accounts(cr, uid, product_id, context=context) - stock_input_acc = product_obj.property_stock_account_input and product_obj.property_stock_account_input.id or False - if not stock_input_acc: - stock_input_acc = product_obj.categ_id.property_stock_account_input_categ and product_obj.categ_id.property_stock_account_input_categ.id or False - - stock_output_acc = product_obj.property_stock_account_output and product_obj.property_stock_account_output.id or False - if not stock_output_acc: - stock_output_acc = product_obj.categ_id.property_stock_account_output_categ and product_obj.categ_id.property_stock_account_output_categ.id or False - - journal_id = product_obj.categ_id.property_stock_journal and product_obj.categ_id.property_stock_journal.id or False - - res.update({'stock_account_input': stock_input_acc}) - res.update({'stock_account_output': stock_output_acc}) - res.update({'stock_journal': journal_id}) - - return res - - _columns = { "bom_ids": fields.one2many('mrp.bom', 'product_id','Bill of Materials'), } - -# Removed do_change_standard_price for the fix of lp:747056 - def copy(self, cr, uid, id, default=None, context=None): if not default: default = {} diff --git a/addons/mrp/test/cancel_order.yml b/addons/mrp/test/cancel_order.yml new file mode 100644 index 00000000000..d10b8c1780b --- /dev/null +++ b/addons/mrp/test/cancel_order.yml @@ -0,0 +1,25 @@ +- + I first confirm order for shirt. +- + !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_shirt} +- + In order to cancel the production order, I first cancel its picking. +- + !function {model: stock.picking, name: action_cancel}: + - model: mrp.production + eval: "[obj(ref('mrp_production_shirt')).picking_id.id]" +- + Now I cancel the production order. +- + !workflow {model: mrp.production, action: button_cancel, ref: mrp_production_shirt} +- + Now I check that the production order is cancelled. +- + !assert {model: mrp.production, id: mrp_production_shirt}: + - state == 'cancel' +- + I remove cancelled production order. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_shirt"), context=context) + self.unlink(cr, uid, [order.id]) diff --git a/addons/mrp/test/mrp_packs.yml b/addons/mrp/test/mrp_packs.yml deleted file mode 100644 index 800d4f56476..00000000000 --- a/addons/mrp/test/mrp_packs.yml +++ /dev/null @@ -1,103 +0,0 @@ -- - In order to test the Packs in OpenERP, we will try to sell a "Pack of 24 - beers" which is composed of 24 "Beers" and a "Beers Pack". -- - I start by creating the Beers product. -- - !record {model: product.product, id: product_product_beers0}: - categ_id: product.cat1 - name: Beers - procure_method: make_to_stock - seller_ids: - - delay: 1 - name: base.res_partner_agrolait - min_qty: 2.0 - supply_method: buy - type: product - uom_id: product.product_uom_unit - uom_po_id: product.product_uom_unit -- - I create the "Beers Pack" product. -- - !record {model: product.product, id: product_product_beerspack0}: - categ_id: product.cat1 - name: Beers Pack - procure_method: make_to_stock - seller_ids: - - delay: 1 - name: base.res_partner_asus - min_qty: 2.0 - supply_method: buy - type: product - uom_id: product.product_uom_unit - uom_po_id: product.product_uom_unit -- - I create the "Pack of 24 beers" product -- - !record {model: product.product, id: product_product_packofbeers0}: - categ_id: product.cat1 - name: Pack of 24 Beers - procure_method: make_to_order - supply_method: produce - type: product - uom_id: product.product_uom_unit - uom_po_id: product.product_uom_unit -- - I define the Phantom Bill of Material for the "Pack of 24 beers" -- - !record {model: mrp.bom, id: mrp_bom_packofbeers0}: - bom_lines: - - company_id: base.main_company - name: Beers - product_id: product_product_beers0 - product_qty: 24.0 - product_uom: product.product_uom_unit - type: normal - - company_id: base.main_company - name: Beers Pack - product_id: product_product_beerspack0 - product_qty: 1.0 - product_uom: product.product_uom_unit - type: normal - name: Pack of 24 Beers - product_id: product_product_packofbeers0 - product_qty: 1.0 - product_uom: product.product_uom_unit - type: phantom -- - As all my data are created, I will create an outgoing order picking for a - "Pack of 24 Beers" -- - !record {model: stock.picking, id: picking_out}: - address_id: base.res_partner_address_tang - company_id: base.main_company - invoice_state: none - move_lines: - - company_id: base.main_company - location_dest_id: stock.stock_location_customers - location_id: stock.stock_location_stock - name: Pack of 24 Beers - product_id: product_product_packofbeers0 - product_qty: 2.0 - product_uom: product.product_uom_unit - move_type: direct - type: out -- - I validate the newly created picking. -- - !python {model: stock.picking}: | - self.draft_validate(cr, uid, [ref("picking_out")], { - "active_ids": [ref("stock.menu_action_picking_tree")], - "active_id": ref("stock.menu_action_picking_tree"), } - ) -- - I check that my Picking of a "Pack of 24 beers" has been automatically - converted to a picking of 24 beers and a pack of beer, so that my - stock of beers remains exact. -- - !assert {model: stock.picking, id: picking_out, string: pack_of_beer_splitted}: - - len(move_lines) >= 2 - - move_lines[0].product_id.id <> move_lines[1].product_id.id - - move_lines[0].product_id.id in (ref('product_product_beers0'), ref('product_product_beerspack0')) - - move_lines[1].product_id.id in (ref('product_product_beers0'), ref('product_product_beerspack0')) - diff --git a/addons/mrp/test/mrp_phantom_bom.yml b/addons/mrp/test/mrp_phantom_bom.yml deleted file mode 100644 index ca29b24ea23..00000000000 --- a/addons/mrp/test/mrp_phantom_bom.yml +++ /dev/null @@ -1,273 +0,0 @@ -- - In order to test the mrp phantom bom type in OpenERP, I will create products - and then I will create Phantom bom structure for those products. -- - I create BOM category fluid for Orange Juice -- - !record {model: product.uom.categ, id: product_uom_categ_fluid}: - name: Fluid -- - I create the products required to produce some orange juices with Oranges, Sugar and Water. -- - !record {model: product.uom, id: product_uom_litre0}: - category_id: product_uom_categ_fluid - factor: 1.0 - name: Litre - rounding: 0.01 -- - I create record for product Orange Juice. -- - !record {model: product.product, id: product_product_orangejuice0}: - categ_id: product.cat1 - name: Orange Juice - procure_method: make_to_order - supply_method: produce - type: product - uom_id: product_uom_litre0 - uom_po_id: product_uom_litre0 - property_stock_inventory: stock.location_inventory - property_stock_procurement: stock.location_procurement - property_stock_production: stock.location_production -- - I create record for product Orange. -- - !record {model: product.product, id: product_product_orange0}: - categ_id: product.cat1 - name: Orange - procure_method: make_to_stock - seller_ids: - - delay: 1 - name: base.res_partner_asus - min_qty: 1.0 - product_uom: product.product_uom_kgm - supply_method: buy - type: product - uom_id: product.product_uom_kgm - uom_po_id: product.product_uom_kgm - property_stock_inventory: stock.location_inventory - property_stock_procurement: stock.location_procurement - property_stock_production: stock.location_production -- - I create record for product Sugar. -- - !record {model: product.product, id: product_product_sugar0}: - categ_id: product.cat1 - name: Sugar - procure_method: make_to_stock - seller_ids: - - delay: 1 - name: base.res_partner_desertic_hispafuentes - min_qty: 2.0 - product_uom: product.product_uom_kgm - supply_method: buy - type: product - uom_id: product.product_uom_kgm - uom_po_id: product.product_uom_kgm - property_stock_inventory: stock.location_inventory - property_stock_procurement: stock.location_procurement - property_stock_production: stock.location_production -- - I create record for product Water. -- - !record {model: product.product, id: product_product_water0}: - categ_id: product.cat1 - name: Water - procure_method: make_to_order - seller_ids: - - delay: 1 - name: base.res_partner_agrolait - product_uom: product_uom_litre0 - min_qty: 2.0 - supply_method: buy - type: consu - uom_id: product_uom_litre0 - uom_po_id: product_uom_litre0 - property_stock_inventory: stock.location_inventory - property_stock_procurement: stock.location_procurement - property_stock_production: stock.location_production -- - I define the BoM to produce an orange juice. -- - !record {model: mrp.bom, id: mrp_bom_orangejuice0}: - company_id: base.main_company - name: Orange Juice - product_efficiency: 1.0 - product_id: product_product_orangejuice0 - product_qty: 1.0 - product_uom: product_uom_litre0 - type: phantom -- - changes UOM and name if product change. -- - !python {model: mrp.bom}: | - production_id = self.browse(cr, uid, [ref('mrp_bom_orangejuice0')], context=context)[0] - self.onchange_product_id(cr, uid, [ref('mrp_bom_orangejuice0')], production_id.product_id.id, False) -- - I create bom lines for BoM for Orange Juice. -- - !record {model: mrp.bom, id: mrp_bom_orangejuice0}: - bom_lines: - - bom_id: mrp_bom_orangejuice0 - company_id: base.main_company - name: Orange - product_efficiency: 1.0 - product_id: product_product_orange0 - product_qty: 0.5 - product_uom: product.product_uom_kgm - type: normal - - bom_id: mrp_bom_orangejuice0 - company_id: base.main_company - name: Sugar - product_efficiency: 1.0 - product_id: product_product_sugar0 - product_qty: 0.02 - product_uom: product.product_uom_kgm - type: normal - - bom_id: mrp_bom_orangejuice0 - company_id: base.main_company - name: Water - product_efficiency: 1.0 - product_id: product_product_water0 - product_qty: 0.80000000000000004 - product_uom: product_uom_litre0 - type: normal -- - I define Minimum stock rules for my stockable product "Orange". -- - !record {model: stock.warehouse.orderpoint, id: stock_warehouse_orderpoint_op0}: - company_id: base.main_company - location_id: stock.stock_location_stock - logic: max - name: OP/00002 - product_id: product_product_orange0 - product_max_qty: 10.0 - product_min_qty: 5.0 - product_uom: product.product_uom_kgm - qty_multiple: 1 - warehouse_id: stock.warehouse0 -- - I define Minimum stock rules for my stockable product "Sugar". -- - !record {model: stock.warehouse.orderpoint, id: stock_warehouse_orderpoint_op1}: - company_id: base.main_company - location_id: stock.stock_location_stock - logic: max - name: OP/00003 - product_id: product_product_sugar0 - product_max_qty: 4.0 - product_min_qty: 2.0 - product_uom: product.product_uom_kgm - qty_multiple: 1 - warehouse_id: stock.warehouse0 -- - I want to produce 100 litres of Orange juice. I am creating a manufacturing order for this. - I want to see how much quantities of sub products I need, to produce the Orange juice. -- - I compute the data. I get the bill of material of Orange juice and list of - scheduled products according to my bom. -- - !record {model: mrp.production, id: mrp_production_mo0}: - company_id: base.main_company - date_planned: !eval datetime.today().strftime("%Y-%m-%d %H:%M:%S") - location_dest_id: stock.stock_location_output - location_src_id: stock.stock_location_stock - product_id: product_product_orangejuice0 - product_qty: 100.0 - product_uom: product_uom_litre0 -- - Creating an mrp.production record. Computing Bills of materials. -- - !record {model: mrp.production, id: mrp_production_mo0}: - bom_id: mrp.mrp_bom_orangejuice0 - date_planned: !eval datetime.today().strftime("%Y-%m-%d %H:%M:%S") - location_dest_id: stock.stock_location_output - location_src_id: stock.stock_location_stock - product_id: mrp.product_product_orangejuice0 - product_lines: - - name: Orange - product_id: mrp.product_product_orange0 - product_qty: 50.0 - product_uom: product.product_uom_kgm - production_id: mrp_production_mo0 - - name: Sugar - product_id: mrp.product_product_sugar0 - product_qty: 2.0 - product_uom: product.product_uom_kgm - production_id: mrp_production_mo0 - - name: Water - product_id: mrp.product_product_water0 - product_qty: 80.0 - product_uom: mrp.product_uom_litre0 - production_id: mrp_production_mo0 - product_qty: 100.0 - product_uom: mrp.product_uom_litre0 -- - I confirm the order. -- - !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_mo0} -- - I am checking Procurement orders. There are 3 orders generated for Oranges, Sugar and Water. -- - !python {model: procurement.order}: | - proc_ids = self.search(cr, uid, [('product_id','in',[ref('product_product_orange0'),ref('product_product_sugar0'),ref('product_product_water0')])]) - assert proc_ids, 'No Procurements!' -- - The scheduler runs. -- - !function {model: procurement.order, name: run_scheduler}: - - model: procurement.order - search: "[]" -- - I am checking Internal picking. I see one picking for Orange juice and its - stock moves for Oranges, Sugar and Water made correctly. -- - !python {model: stock.picking}: | - pick_ids = self.search(cr, uid, [('type','=','internal')]) - assert pick_ids, 'No Internal Pickings!' -- - According to minimum stock rules. I have 2 purchase orders for - Sugar with 6 Kg from Axelor and Orange 60 Kg from ASUStek. -- - I confirm the purchase order of Sugar and Orange. -- - !python {model: purchase.order}: | - import netsvc - purch_ids = self.search(cr, uid, [('state','=','draft')]) - assert purch_ids, 'No Purchase Orders were made!' - wf_service = netsvc.LocalService("workflow") - for p_id in purch_ids: - wf_service.trg_validate(uid, 'purchase.order', p_id, 'purchase_confirm', cr) -- - I see two incoming pickings for Orange and Sugar, and receive them. -- - !python {model: stock.picking}: | - pick_ids = self.search(cr, uid, [('type','=','in')]) - assert pick_ids, 'No Incoming Shipments found!' - stock_partial_picking = self.pool.get('stock.partial.picking') - for pick_id in pick_ids: - partial_id = stock_partial_picking.create(cr, uid, {}, - context={'active_model': 'stock.picking', - 'active_ids': [pick_id]}) - stock_partial_picking.do_partial(cr, uid, [partial_id]) -- - Again the scheduler runs. -- - !function {model: procurement.order, name: run_scheduler}: - - model: procurement.order - search: "[]" -- - I check my internal picking of "Orange Juice" is done. -- - !python {model: stock.picking}: | - pick_ids = self.search(cr, uid, [('type','=','internal'),('state','=','done')]) - assert pick_ids, 'Internal Picking is not done yet!' -- - I check my manufacturing order for "Orange Juice" is ready or not. -- - !python {model: mrp.production}: | - prod_ids = self.search(cr, uid, [('state','=','ready'),('id','=',ref('mrp_production_mo0'))]) - assert prod_ids, 'Manufacturing order is not ready!' -- - I start the production order. -- - !workflow {model: mrp.production, action: button_produce, ref: mrp_production_mo0} diff --git a/addons/mrp/test/mrp_procurement.yml b/addons/mrp/test/mrp_procurement.yml deleted file mode 100644 index f5bcf4f767a..00000000000 --- a/addons/mrp/test/mrp_procurement.yml +++ /dev/null @@ -1,278 +0,0 @@ -- - In order to test the flow of procurement orders. I will put some orders with - different procurement methods. I have installed sale, mrp and purchase modules. -- - I am creating products. -- - I create record for product Shirt. -- - !record {model: product.product, id: product_product_shirt0}: - categ_id: product.cat1 - cost_method: standard - list_price: 350.0 - mes_type: fixed - name: Shirt - procure_method: make_to_stock - property_stock_inventory: stock.location_inventory - property_stock_procurement: stock.location_procurement - property_stock_production: stock.location_production - seller_delay: '1' - standard_price: 300.0 - supply_method: produce - type: product - uom_id: product.product_uom_unit - uom_po_id: product.product_uom_unit - volume: 0.0 - warranty: 0.0 - weight: 0.0 - weight_net: 0.0 -- - I create record for product Cloth. -- - !record {model: product.product, id: product_product_cloth0}: - categ_id: product.cat1 - cost_method: standard - mes_type: fixed - name: Cloth - procure_method: make_to_order - property_stock_inventory: stock.location_inventory - property_stock_procurement: stock.location_procurement - property_stock_production: stock.location_production - seller_delay: '1' - seller_ids: - - delay: 1 - name: base.res_partner_maxtor - product_uom: product.product_uom_unit - min_qty: 300.0 - standard_price: 1.0 - supply_method: buy - type: product - uom_id: product.product_uom_unit - uom_po_id: product.product_uom_unit - volume: 0.0 - warranty: 0.0 - weight: 0.0 - weight_net: 0.0 -- - I create record for product Buttons. -- - !record {model: product.product, id: product_product_buttons0}: - categ_id: product.cat1 - cost_method: standard - mes_type: fixed - name: Buttons - procure_method: make_to_stock - property_stock_inventory: stock.location_inventory - property_stock_procurement: stock.location_procurement - property_stock_production: stock.location_production - seller_delay: '1' - seller_ids: - - delay: 1 - name: base.res_partner_asus - product_uom: product.product_uom_kgm - min_qty: 100.0 - standard_price: 1.0 - supply_method: buy - type: product - uom_id: product.product_uom_kgm - uom_po_id: product.product_uom_kgm - volume: 0.0 - warranty: 0.0 - weight: 0.0 - weight_net: 0.0 -- - I am creating bills of material for 'Shirt'. -- - I create bills of material for Shirt. -- - !record {model: mrp.bom, id: mrp_bom_shirt0}: - bom_lines: - - company_id: base.main_company - name: Cloth - product_efficiency: 1.0 - product_id: product_product_cloth0 - product_qty: 1.0 - product_uom: product.product_uom_unit - product_uos_qty: 0.0 - sequence: 0.0 - type: normal - - company_id: base.main_company - name: Buttons - product_efficiency: 1.0 - product_id: product_product_buttons0 - product_qty: 8.0 - product_uom: product.product_uom_kgm - product_uos_qty: 0.0 - sequence: 0.0 - type: normal - company_id: base.main_company - name: Shirt - product_efficiency: 1.0 - product_id: product_product_shirt0 - product_qty: 1.0 - product_uom: product.product_uom_unit - product_uos_qty: 0.0 - sequence: 0.0 - type: normal -- - I create minimum stock rule for product Buttons -- - !record {model: stock.warehouse.orderpoint, id: stock_warehouse_orderpoint_op0}: - company_id: base.main_company - location_id: stock.stock_location_stock - logic: max - name: OP/00007 - product_id: mrp.product_product_buttons0 - product_max_qty: 50.0 - product_min_qty: 10.0 - product_uom: product.product_uom_kgm - qty_multiple: 1 - warehouse_id: stock.warehouse0 -- - I create a procurement order for product Shirt. -- - !record {model: procurement.order, id: procurement_order_shirt0}: - name: 'PROC: Shirt' - product_id: product_product_shirt0 - product_qty: 5.00 - location_id: stock.stock_location_stock - product_uom: product.product_uom_unit -- - I confirm the procurement order. -- - !workflow {model: procurement.order, action: button_confirm, ref: procurement_order_shirt0} -- - I run the procurement. -- - !workflow {model: procurement.order, action: button_check, ref: procurement_order_shirt0} -- - I see that there is a manufacturing order for Shirt. -- - !python {model: mrp.production}: | - from tools.translate import _ - order_ids = self.search(cr, uid, [('product_id','=',ref('product_product_shirt0'))]) - assert order_ids, 'No Manufacturing Order.' -- - I also check that there are two more procurement orders for sub products Cloth and Buttons. -- - !python {model: procurement.order}: | - from tools.translate import _ - proc_ids = self.search(cr, uid, [('product_id','in',[ref('product_product_cloth0'),ref('product_product_buttons0')])]) - assert proc_ids, 'No Procurements.' -- - The scheduler runs. -- - !function {model: procurement.order, name: run_scheduler}: - - model: procurement.order - search: "[]" -- - I check that there is one purchase order for Cloth. -- - !python {model: purchase.order}: | - purch_ids = self.search(cr, uid, [('partner_id.name','=','Maxtor')]) - assert purch_ids, 'No Purchase Orders.' -- - I confirm purchase order for Cloth. -- - !python {model: purchase.order}: | - import netsvc - purch_ids = self.search(cr, uid, [('partner_id.name','=','Maxtor')]) - wf_service = netsvc.LocalService("workflow") - for p_id in purch_ids: - wf_service.trg_validate(uid, 'purchase.order', p_id, 'purchase_confirm', cr) - -- - I confirm purchase order for Buttons. -- - !python {model: purchase.order}: | - import netsvc - purch_ids = self.search(cr, uid, [('partner_id.name','=','ASUStek')]) - wf_service = netsvc.LocalService("workflow") - for p_id in purch_ids: - wf_service.trg_validate(uid, 'purchase.order', p_id, 'purchase_confirm', cr) - -- - I Check incoming shipments for cloth. And receive products. -- - !python {model: stock.picking}: | - pick_ids = self.search(cr, uid, [('address_id.name','=','Wong'),('state','=','assigned')]) - assert pick_ids, 'No Incoming Shipments found!' - stock_partial_picking = self.pool.get('stock.partial.picking') - for pick_id in pick_ids: - partial_id = stock_partial_picking.create(cr, uid, {}, - context={'active_model': 'stock.picking', - 'active_ids': [pick_id]}) - stock_partial_picking.do_partial(cr, uid, [partial_id]) -- - I Check incoming shipments for buttons and receive products. -- - !python {model: stock.picking}: | - pick_ids = self.search(cr, uid, [('address_id.name','=','Tang'),('state','=','assigned')]) - assert pick_ids, 'No Incoming Shipments found!' - stock_partial_picking = self.pool.get('stock.partial.picking') - for pick_id in pick_ids: - partial_id = stock_partial_picking.create(cr, uid, {}, - context={'active_model': 'stock.picking', - 'active_ids': [pick_id]}) - stock_partial_picking.do_partial(cr, uid, [partial_id]) -- - Run scheduler again. -- - !function {model: procurement.order, name: run_scheduler}: - - model: procurement.order - search: "[]" -- - Check state of manufacturing order for Shirt. -- - !python {model: mrp.production}: | - from tools.translate import _ - order_ids = self.search(cr, uid, [('product_id','=',ref('product_product_shirt0')),('state','=','ready')]) - assert order_ids, 'No Manufacturing Order in Ready state.' -- - I start production order for Shirt. -- - !python {model: mrp.production}: | - from tools.translate import _ - import netsvc - prod_ids = self.search(cr, uid, [('state','=','ready')]) - assert prod_ids, _('No Ready Manufacturing Orders found!') - wf_service = netsvc.LocalService("workflow") - for p_id in prod_ids: - wf_service.trg_validate(uid, 'mrp.production', p_id, 'button_produce', cr) -- - I create record for producing products with quantity 5.00. -- - !record {model: mrp.product.produce, id: mrp_product_produce0}: - product_qty: 2.00 - mode: 'consume_produce' -- - I produce 2 products with 5.00 quantities each. -- - !python {model: mrp.product.produce}: | - prod_obj = self.pool.get('mrp.production') - prod_ids = prod_obj.search(cr, uid, [('product_id.name','=','Shirt')]) - self.do_produce(cr, uid, [ref('mrp_product_produce0')], context={'active_ids': prod_ids}) -- - I create record for remaining products with quantity 35.00. -- - !record {model: stock.move.consume, id: stock_move_consume0}: - product_id: product_product_buttons0 - product_qty: 35.00 - product_uom: product.product_uom_unit - location_id: stock.stock_location_stock -- - I produce remaining product Buttons with 35.00 quantity. -- - !python {model: stock.move.consume}: | - from tools.translate import _ - stock_obj = self.pool.get('stock.move') - stock_ids = stock_obj.search(cr, uid, [('product_id.name','=','Buttons')]) - self.do_move_consume(cr, uid, [ref('stock_move_consume0')], context={'active_ids': stock_ids}) -- - And finally production order is done. -- - !python {model: mrp.product.produce}: | - prod_obj = self.pool.get('mrp.production') - prod_ids = prod_obj.search(cr, uid, [('product_id.name','=','Shirt')]) - self.do_produce(cr, uid, [ref('mrp_product_produce0')], context={'active_ids': prod_ids}) - diff --git a/addons/mrp/test/mrp_production_cancel.yml b/addons/mrp/test/mrp_production_cancel.yml deleted file mode 100644 index 1dc20a215d1..00000000000 --- a/addons/mrp/test/mrp_production_cancel.yml +++ /dev/null @@ -1,29 +0,0 @@ -- - In order to test the manufacturing order in Openerp, - I am creating one manufacturing order -- - !record {model: mrp.production, id: mrp_production_mo1}: - company_id: base.main_company - date_planned: !eval datetime.today().strftime("%Y-%m-%d %H:%M:%S") - location_dest_id: stock.stock_location_stock - location_src_id: stock.stock_location_stock - product_id: product.product_product_pc1 - name: MO/01234 - product_qty: 5.0 - product_uom: product.product_uom_unit - product_uos_qty: 0.0 -- - I confirm the order. -- - !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_mo1} -- - In order to cancel the MO, I first cancel its picking. -- - !python {model: stock.picking}: | - mrp_obj = self.pool.get('mrp.production') - mo = mrp_obj.browse(cr, uid, ref("mrp_production_mo1")) - self.action_cancel(cr, uid, [mo.picking_id.id], context=None) -- - Then I Cancel the production order and related stock moves. -- - !workflow {model: mrp.production, action: button_cancel, ref: mrp_production_mo1} \ No newline at end of file diff --git a/addons/mrp/test/mrp_production_order.yml b/addons/mrp/test/mrp_production_order.yml deleted file mode 100644 index 57d75e1c1a5..00000000000 --- a/addons/mrp/test/mrp_production_order.yml +++ /dev/null @@ -1,119 +0,0 @@ -- - In order to test the manufacturing order working with procurements I will use - some products with different supply method and procurement method, also check - the bills of material for the products. -- - I am creating one manufacturing order. -- - !record {model: mrp.production, id: mrp_production_mo1}: - company_id: base.main_company - date_planned: !eval datetime.today().strftime("%Y-%m-%d %H:%M:%S") - location_dest_id: stock.stock_location_stock - location_src_id: stock.stock_location_stock - product_id: product.product_product_pc1 - name: MO/0123 - product_qty: 5.0 - product_uom: product.product_uom_unit - product_uos_qty: 0.0 -- - I compute the data. -- - !python {model: mrp.production}: | - self.action_compute(cr, uid, [ref("mrp_production_mo1")]) -- - I confirm the order. -- - !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_mo1} -- - I create record for changing production quantity to 6.00 -- - !record {model: change.production.qty, id: mrp_production_qty}: - product_qty: 6.0 -- - Changes the Quantity of Product. -- - !python {model: change.production.qty}: | - context = {"lang": 'en_US', "active_model":"mrp.production", "active_ids": [ref("mrp_production_mo1")], "tz": False, "active_id":ref('mrp_production_mo1')} - self.default_get(cr, uid, ["product_qty"], context) - self.change_prod_qty(cr, uid, [ref("mrp_production_qty")], context=context) -- - I check now quantity of the production order is 6 or not. -- - !assert {model: mrp.production, id: mrp_production_mo1}: - - product_qty == 6 -- - I am checking Procurement orders for components of PC1. -- - !python {model: procurement.order}: | - from tools.translate import _ - production_obj = self.pool.get('mrp.production') - production = production_obj.browse(cr, uid, ref('mrp_production_mo1')) - product_ids = map(lambda x:x.product_id.id, production.move_lines) - proc_ids = self.search(cr, uid, [('product_id','in',product_ids)]) - assert proc_ids, _('No Procurements!') -- - The scheduler runs. -- - !function {model: procurement.order, name: run_scheduler}: - - model: procurement.order - search: "[]" -- - I am checking Internal picking. -- - !python {model: stock.picking}: | - from tools.translate import _ - pick_ids = self.search(cr, uid, [('type','=','internal')]) - assert pick_ids, _('No Internal Pickings!') -- - I see that there is a manufacturing order for the sub product CPU_GEN with ready state and I start production of it. -- - !python {model: mrp.production}: | - from tools.translate import _ - order_ids = self.search(cr, uid, [('state','=','ready'), ('product_id', '=', ref('product.product_product_cpu_gen'))]) - assert order_ids, _('No manufacturing order in Ready state!') - import netsvc - wf_service = netsvc.LocalService("workflow") - for order in order_ids: - wf_service.trg_validate(uid, 'mrp.production', order, 'button_produce', cr) -- - I create record for producing products with quantity 1.00. -- - !record {model: mrp.product.produce, id: mrp_product_produce0}: - product_qty: 1.00 - mode: 'consume_produce' -- - I produce the product. -- - !python {model: mrp.product.produce}: | - prod_obj = self.pool.get('mrp.production') - prod_ids = prod_obj.search(cr, uid, [('state','=','in_production'), ('product_id', '=', ref('product.product_product_cpu_gen'))]) - self.do_produce(cr, uid, [ref('mrp_product_produce0')], context={'active_ids': prod_ids}) -- - Now the manufacturing order for subproduct CPU_GEN is done and manufacturing - order for PC1 is in ready state. -- - !python {model: mrp.production}: | - from tools.translate import _ - prod_ids = self.search(cr, uid, [('state','=','done'), ('product_id', '=', ref('product.product_product_cpu_gen'))]) - assert prod_ids, _('Manufacturing order for CPU_GEN is yet not done!') -- - I start producing the product PC1. -- - !workflow {model: mrp.production, action: button_produce, ref: mrp_production_mo1} -- - I create record for producing products with quantity 6.00. -- - !record {model: mrp.product.produce, id: mrp_product_produce1}: - product_qty: 6.00 - mode: 'consume_produce' -- - Finally my production order is done. -- - !python {model: mrp.product.produce}: | - context = {"lang": 'en_US', "active_model":"mrp.production", "active_ids": [ref("mrp_production_mo1")], "tz": False, "active_id":ref('mrp_production_mo1')} - self.do_produce(cr, uid, [ref('mrp_product_produce1')], context=context) -- - I check now the production order for PC1 is done. -- - !assert {model: mrp.production, id: mrp_production_mo1}: - - state == 'done' diff --git a/addons/mrp/test/mrp_report.yml b/addons/mrp/test/mrp_report.yml deleted file mode 100644 index 48126b5edcd..00000000000 --- a/addons/mrp/test/mrp_report.yml +++ /dev/null @@ -1,38 +0,0 @@ -- - In order to test the PDF reports defined on a MRP, we will print a BOM Structure Report -- - !python {model: mrp.bom}: | - import netsvc, tools, os - (data, format) = netsvc.LocalService('report.bom.structure').create(cr, uid, [ref('mrp.mrp_bom_0'),ref('mrp.mrp_bom_1'),ref('mrp.mrp_bom_2'),ref('mrp.mrp_bom_23'),ref('mrp.mrp_bom_1901'),ref('mrp.mrp_bom_assemblysection0'),ref('mrp.mrp_bom_sidepanel0'),ref('mrp.mrp_bom_defaultbomforshelfofcm1'),ref('mrp.mrp_bom_sidepanel3')], {}, {}) - if tools.config['test_report_directory']: - file(os.path.join(tools.config['test_report_directory'], 'mrp-bom_structure_report.'+format), 'wb+').write(data) - -- - In order to test the PDF reports defined on a MRP, we will print Production Order Report -- - !python {model: mrp.production}: | - import netsvc, tools, os - (data, format) = netsvc.LocalService('report.mrp.production.order').create(cr, uid, [ref('mrp.mrp_production_mo1')], {}, {}) - if tools.config['test_report_directory']: - file(os.path.join(tools.config['test_report_directory'], 'mrp-production_order_report.'+format), 'wb+').write(data) - -- - Print Product Price Report through the wizard -- - !python {model: product.product}: | - ctx={} - ctx.update({'model': 'product.product','active_ids': [1,2,3,5]}) - data_dict = {'number': 1} - from tools import test_reports - test_reports.try_report_action(cr, uid, 'action_view_mrp_product_price_wizard',wiz_data=data_dict, context=ctx, our_module='mrp') - -- - Print Work Center Load Report through the wizard -- - !python {model: mrp.workcenter}: | - ctx={} - ctx.update({'model': 'mrp.workcenter','active_ids': [ref('mrp_workcenter_0'),ref('mrp_workcenter_1')]}) - data_dict = {'time_unit': 'day', 'measure_unit': 'hours'} - from tools import test_reports - test_reports.try_report_action(cr, uid, 'action_mrp_workcenter_load_wizard',wiz_data=data_dict, context=ctx, our_module='mrp') - diff --git a/addons/mrp/test/order_demo.yml b/addons/mrp/test/order_demo.yml new file mode 100644 index 00000000000..9c7b8720904 --- /dev/null +++ b/addons/mrp/test/order_demo.yml @@ -0,0 +1,27 @@ +- + In order to test process of production order, I create Bill of material of Shelf 100cm. +- + !record {model: mrp.bom, id: mrp_bom_defaultbomforshelfofcm0}: + product_id: product.product_product_shelfofcm0 +- + !record {model: mrp.bom, id: mrp_bom_assemblysection1}: + routing_id: mrp.mrp_routing_0 +- + !record {model: mrp.bom, id: mrp_bom_rearpanelarm1}: + routing_id: mrp.mrp_routing_0 +- + I create Production Order of Shelf 100cm to produce 5.0 Dozen PCE. +- + !record {model: mrp.production, id: mrp_production_shelf100cm}: + location_src_id: stock.stock_location_stock + location_dest_id: stock.stock_location_output + product_id: product.product_product_shelfofcm0 + bom_id: mrp_bom_defaultbomforshelfofcm0 + routing_id: mrp.mrp_routing_1 + product_uom: product.product_uom_dozen + product_qty: 5.0 +- + !record {model: mrp.workcenter, id: mrp_workcenter_0}: + product_id: product.product_assembly + + diff --git a/addons/mrp/test/order_process.yml b/addons/mrp/test/order_process.yml new file mode 100644 index 00000000000..0c970d7d196 --- /dev/null +++ b/addons/mrp/test/order_process.yml @@ -0,0 +1,309 @@ +- + I compute the production order. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_shelf100cm"), context=context) + order.action_compute(context=context) +- + I check production lines after compute. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_shelf100cm"), context=context) + assert len(order.product_lines) == 5, "Production lines are not generated proper." + factor = 12.0*5.0 + sidepanel = False + woodlintelm = False + woodmm0 = False + woodmm10 = False + metalcleats = False + for line in order.product_lines: + if line.product_id.id == ref('product.product_product_sidepanel0'): #SIDEPAN 2 PCE + assert not sidepanel, "Production line is already generated for SIDEPAN." + assert line.product_qty == (2.0*factor), "Qty is not correspond." + assert line.product_uom.id == ref('product.product_uom_unit'), "UOM is not correspond" + sidepanel = True + elif line.product_id.id == ref('product.product_product_woodlintelm0'): #LIN40 4*0.25 Meter + assert not woodlintelm, "Production line is already generated for LIN40." + assert line.product_qty == (4*0.25*factor), "Qty is not correspond." + assert line.product_uom.id == ref('product.product_uom_meter'), "UOM is not correspond" + woodlintelm = True + elif line.product_id.id == ref('product.product_product_woodmm0'): #WOOD002 0.25 m + assert not woodmm0, "Production line is already generated for WOOD002." + assert line.product_qty == (0.25*factor), "Qty is not correspond." + assert line.product_uom.id == ref('product.product_uom_meter'), "UOM is not correspond" + woodmm0 = True + elif line.product_id.id == ref('product.product_product_metalcleats0'): #METC000 4*3 PCE + assert not metalcleats, "Production line is already generated for METC000." + assert line.product_qty == (4*3*factor), "Qty is not correspond." + assert line.product_uom.id == ref('product.product_uom_unit'), "UOM is not correspond" + metalcleats = True + elif line.product_id.id == ref('product.product_product_woodmm10'): #WOOD010 0.083*3 m + assert not woodmm10, "Production line is already generated for WOOD010." + assert line.product_qty == (0.083*3*factor), "Qty is not correspond." + assert line.product_uom.id == ref('product.product_uom_meter'), "UOM is not correspond" + woodmm10 = True + else: + raise AssertionError('unknown order line: %s' % line) + assert sidepanel, "Production line is not generated for SIDEPAN." + assert woodlintelm, "Production line is not generated for LIN40." + assert woodmm0, "Production line is not generated for WOOD002." + assert metalcleats, "Production line is not generated for METC000." + assert woodmm10, "Production line is not generated for WOOD010." + +- + Now I check workcenter lines. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_shelf100cm"), context=context) + assert len(order.workcenter_lines), "Workcenter lines are not generated proper." + for line in order.workcenter_lines: + wc = line.workcenter_id + hours = ((wc.time_start or 0.0)+(wc.time_stop or 0.0)+line.cycle*(wc.time_cycle or 0.0)) * (wc.time_efficiency or 1.0) + factor = 5*12 + d, m = divmod(factor, wc.capacity_per_cycle) + cycle = (d + (m and 1.0 or 0.0)) + if line.name == "Short time assembly - Assembly Section": + assert line.sequence, "Sequence is not correspond: %s" % (line.name) + assert line.cycle == (4*cycle), "Cycle is not correspond: %s" % (line.name) + assert line.hour == (2*cycle*4 + hours), "Hours is not correspond: %s"% (line.name) + elif line.name == "Short time assembly - Rear Panel SHE100": + assert line.sequence, "Sequence is not correspond: %s" % (line.name) + assert line.cycle == (1*cycle), "Cycle is not correspond: %s" % (line.name) + assert line.hour == (2*cycle + hours), "Hours is not correspond: %s"% (line.name) + elif line.name == "long time assembly - Shelf of 100cm": + assert line.sequence, "Sequence is not correspond: %s" % (line.name) + assert line.cycle == (2*cycle), "Cycle is not correspond: %s" % (line.name) + assert line.hour == (5*cycle + hours), "Hours is not correspond: %s"% (line.name) + elif line.name == "Testing - Shelf of 100cm": + assert line.sequence, "Sequence is not correspond: %s" % (line.name) + assert line.cycle == (1*cycle), "Cycle is not correspond: %s" % (line.name) + assert line.hour == (1*cycle + hours), "Hours is not correspond: %s"% (line.name) + elif line.name == "Packing - Shelf of 100cm": + assert line.sequence, "Sequence is not correspond: %s" % (line.name) + assert line.cycle == (1*cycle), "Cycle is not correspond: %s" % (line.name) + assert line.hour == (0.5*cycle + hours), "Hours is not correspond: %s"% (line.name) + else: + raise AssertionError('unknown workcenter line: %s' % line) +- + I confirm the Production Order. +- + !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_shelf100cm} +- + I check details of Produce Move of Production Order to trace Final Product. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_shelf100cm")) + assert order.state == 'confirmed', "Production order should be confirmed." + assert order.move_created_ids, "Trace Record is not created for Final Product." + move = order.move_created_ids[0] + source_location_id = order.product_id.product_tmpl_id.property_stock_production.id + assert move.date == order.date_planned, "Planned date is not correspond." + assert move.product_id.id == order.product_id.id, "Product is not correspond." + assert move.product_uom.id == order.product_uom.id, "UOM is not correspond." + assert move.product_qty == order.product_qty, "Qty is not correspond." + assert move.product_uos_qty == order.product_uos and order.product_uos_qty or order.product_qty, "UOS qty is not correspond." + if order.product_uos: + assert move.product_uos.id == order.product_uos.id, "UOS is not correspond." + assert move.location_id.id == source_location_id, "Source Location is not correspond." + assert move.location_dest_id.id == order.location_dest_id.id, "Destination Location is not correspond." + routing_loc = None + if order.bom_id.routing_id and order.bom_id.routing_id.location_id: + routing_loc = order.bom_id.routing_id.location_id.id + date_planned = order.date_planned + for move_line in order.move_lines: + for order_line in order.product_lines: + if move_line.product_id.type not in ('product', 'consu'): + continue + if move_line.product_id.id == order_line.product_id.id: + assert move_line.date == date_planned, "Planned date is not correspond in 'To consume line'." + assert move_line.product_qty == order_line.product_qty, "Qty is not correspond in 'To consume line'." + assert move_line.product_uom.id == order_line.product_uom.id, "UOM is not correspond in 'To consume line'." + assert move_line.product_uos_qty == order_line.product_uos and order_line.product_uos_qty or order_line.product_qty, "UOS qty is not correspond in 'To consume line'." + if order_line.product_uos: + assert move_line.product_uos.id == order_line.product_uos.id, "UOS is not correspond in 'To consume line'." + assert move_line.location_id.id == routing_loc or order.location_src_id.id, "Source location is not correspond in 'To consume line'." + assert move_line.location_dest_id.id == source_location_id, "Destination Location is not correspond in 'To consume line'." + +- + I check details of an Internal Shipment after confirmed production order to bring components in Raw Materials Location. +- + !python {model: mrp.production}: | + procurement = self.pool.get('procurement.order') + order = self.browse(cr, uid, ref("mrp_production_shelf100cm")) + assert order.picking_id, 'Internal Shipment should be created!' + + routing_loc = None + pick_type = 'internal' + address_id = False + if order.bom_id.routing_id and order.bom_id.routing_id.location_id: + routing_loc = order.bom_id.routing_id.location_id + if routing_loc.usage <> 'internal': + pick_type = 'out' + address_id = routing_loc.address_id and routing_loc.address_id.id or False + routing_loc = routing_loc.id + assert order.picking_id.type == pick_type, "Shipment should be Internal." + assert order.picking_id.address_id.id == address_id, "Shipment Address is not correspond with Adderss of Routing Location." + date_planned = order.date_planned + for move_line in order.picking_id.move_lines: + for order_line in order.product_lines: + if move_line.product_id.type not in ('product', 'consu'): + continue + if move_line.product_id.id == order_line.product_id.id: + assert move_line.date == date_planned, "Planned date is not correspond." + assert move_line.product_qty == order_line.product_qty, "Qty is not correspond." + assert move_line.product_uom.id == order_line.product_uom.id, "UOM is not correspond." + assert move_line.product_uos_qty == order_line.product_uos and order_line.product_uos_qty or order_line.product_qty, "UOS qty is not correspond." + if order_line.product_uos: + assert move_line.product_uos.id == order_line.product_uos.id, "UOS is not correspond." + assert move_line.location_id.id == order.location_src_id.id, "Source location is not correspond." + assert move_line.location_dest_id.id == routing_loc or order.location_src_id.id, "Destination Location is not correspond." + procurement_ids = procurement.search(cr, uid, [('move_id','=',move_line.id)]) + assert procurement_ids, "Procurement should be created for shipment line of raw materials." + shipment_procurement = procurement.browse(cr, uid, procurement_ids[0], context=context) + assert shipment_procurement.date_planned == date_planned, "Planned date is not correspond in procurement." + assert shipment_procurement.product_id.id == order_line.product_id.id, "Product is not correspond in procurement." + assert shipment_procurement.product_qty == order_line.product_qty, "Qty is not correspond in procurement." + assert shipment_procurement.product_uom.id == order_line.product_uom.id, "UOM is not correspond in procurement." + assert shipment_procurement.product_uos_qty == order_line.product_uos and order_line.product_uos_qty or order_line.product_qty, "UOS qty is not correspond in procurement." + if order_line.product_uos: + assert shipment_procurement.product_uos.id == order_line.product_uos.id, "UOS is not correspond in procurement." + assert shipment_procurement.location_id.id == order.location_src_id.id, "Location is not correspond in procurement." + assert shipment_procurement.procure_method == order_line.product_id.procure_method, "Procure method is not correspond in procurement." + +- + I change production qty with 3 Dozen Shelf 100cm. +- + !python {model: change.production.qty}: | + context.update({'active_id': ref('mrp_production_shelf100cm')}) +- + !record {model: change.production.qty, id: mrp_production_qty}: + product_qty: 3.0 +- + !python {model: change.production.qty}: | + self.change_prod_qty(cr, uid, [ref("mrp_production_qty")], context=context) +- + I check qty after changed in production order. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_shelf100cm")) + assert order.product_qty == 3, "Qty is not changed in order." + move = order.move_created_ids[0] + assert move.product_qty == order.product_qty, "Qty is not changed in move line." +- + I run scheduler. +- + !python {model: procurement.order}: | + self.run_scheduler(cr, uid) +- + The production order is Waiting Goods, I forcefully done internal shipment. +- + !python {model: mrp.production}: | + self.force_production(cr, uid, [ref("mrp_production_shelf100cm")]) +- + I check that production order in ready state after forcefully done internal shipment. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_shelf100cm")) + assert order.state == 'ready', 'Production order should be in Ready State.' + assert order.picking_id.state == 'done', 'Internal shipment should be done.' +- + Now I start production. +- + !workflow {model: mrp.production, action: button_produce, ref: mrp_production_shelf100cm} +- + I check that production order in production state after start production. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_shelf100cm")) + assert order.state == 'in_production', 'Production order should be in production State.' +- + I consume raw materials and put one material in scrap location due to waste it. +- + !python {model: mrp.production}: | + scrap_location_ids = self.pool.get('stock.location').search(cr, uid, [('scrap_location','=',True)]) + scrap_location_id = scrap_location_ids[0] + order = self.browse(cr, uid, ref("mrp_production_shelf100cm")) + for move in order.move_lines: + move.action_consume(move.product_qty) + if move.product_id.id == ref("product.product_product_metalcleats0"): + move.action_scrap(5.0, scrap_location_id) +- + I produce product. +- + !python {model: mrp.product.produce}: | + context.update({'active_id': ref('mrp_production_shelf100cm')}) +- + !record {model: mrp.product.produce, id: mrp_product_produce1}: + mode: 'consume_produce' +- + !python {model: mrp.product.produce}: | + self.do_produce(cr, uid, [ref('mrp_product_produce1')], context=context) +- + I check production order after produced. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_shelf100cm")) + assert order.state == 'done', "Production order should be closed." +- + I check Total Costs at End of Production. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_shelf100cm")) + account_analytic_line = self.pool.get('account.analytic.line') + def rounding(f, r): + import math + if not r: + return f + return math.ceil(f / r) * r + + for wc_line in order.workcenter_lines: + wc = wc_line.workcenter_id + accounts = [wc.costs_hour_account_id, wc.costs_cycle_account_id] + cost_per_cyle = wc_line.cycle * wc.costs_cycle + cost_per_hours = wc_line.hour * wc.costs_hour + if accounts and wc.costs_journal_id and wc.costs_general_account_id and (cost_per_cyle or cost_per_hours): + line_ids = account_analytic_line.search(cr, uid, [('name','ilike',wc_line.name)]) + assert line_ids, 'Costs lines are not generated.' + for line in account_analytic_line.browse(cr, uid, line_ids, context=context): + if wc.costs_hour_account_id and line.account_id.id == wc.costs_hour_account_id.id: + assert rounding(line.unit_amount, 3) == rounding(wc_line.hour, 3), "Cost Unit Amount is not correspond." + assert rounding(line.amount, 3) == rounding(cost_per_hours, 3), "Cost amount is not correspond." + elif wc.costs_cycle_account_id and line.account_id.id == wc.costs_cycle_account_id.id: + assert rounding(line.unit_amount, 3) == rounding(wc_line.cycle, 3), "Cost Unit Amount is not correspond." + assert rounding(line.amount, 3) == rounding(cost_per_cyle, 3), "Cost Amount is not correspond." + else: + raise AssertionError('unknown cost line: %s' % line) + assert line.general_account_id.id == wc.costs_general_account_id.id, "General Account is not correspond." + assert line.journal_id.id == wc.costs_journal_id.id, "Account Journal is not correspond." + assert line.product_id.id == wc.product_id.id, "Product is not correspond." + assert line.product_uom_id.id == wc.product_id.uom_id.id, "UOM is not correspond." + +- + I print a "BOM Structure". +- + !python {model: mrp.production}: | + import netsvc, tools, os + order = self.browse(cr, uid, ref("mrp_production_shelf100cm")) + (data, format) = netsvc.LocalService('report.bom.structure').create(cr, uid, [order.bom_id.id], {}, {}) + if tools.config['test_report_directory']: + file(os.path.join(tools.config['test_report_directory'], 'mrp-bom_structure_report.'+format), 'wb+').write(data) + +- + I print "Production Order". +- + !python {model: mrp.production}: | + import netsvc, tools, os + (data, format) = netsvc.LocalService('report.mrp.production.order').create(cr, uid, [ref("mrp_production_shelf100cm")], {}, {}) + if tools.config['test_report_directory']: + file(os.path.join(tools.config['test_report_directory'], 'mrp-production_order_report.'+format), 'wb+').write(data) + +- + I print "Work Center Load Report". +- + !python {model: mrp.workcenter}: | + ctx = context.copy() + ctx.update({'model': 'mrp.workcenter','active_ids': [ref('mrp_workcenter_0'),ref('mrp_workcenter_1')]}) + data_dict = {'time_unit': 'day', 'measure_unit': 'hours'} + from tools import test_reports + test_reports.try_report_action(cr, uid, 'action_mrp_workcenter_load_wizard',wiz_data=data_dict, context=ctx, our_module='mrp') + diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py index dc9a235ff63..db4d6e77691 100644 --- a/addons/mrp/wizard/mrp_product_produce.py +++ b/addons/mrp/wizard/mrp_product_produce.py @@ -60,22 +60,11 @@ class mrp_product_produce(osv.osv_memory): } def do_produce(self, cr, uid, ids, context=None): - """ To check the product type - @param self: The object pointer. - @param cr: A database cursor - @param uid: ID of the user currently logged in - @param ids: the ID or list of IDs if we want more than one - @param context: A standard dictionary - @return: - """ - if context is None: - context = {} - prod_obj = self.pool.get('mrp.production') - move_ids = context.get('active_ids', []) - for data in self.browse(cr, uid, ids, context=context): - for move_id in move_ids: - prod_obj.action_produce(cr, uid, move_id, - data.product_qty, data.mode, context=context) + production_id = context.get('active_id', False) + assert production_id, "Production Id should be specified in context as a Active ID" + data = self.browse(cr, uid, ids[0], context=context) + self.pool.get('mrp.production').action_produce(cr, uid, production_id, + data.product_qty, data.mode, context=context) return {} mrp_product_produce() diff --git a/addons/mrp_operations/__openerp__.py b/addons/mrp_operations/__openerp__.py index caa33cc6556..10d82cfb8c4 100644 --- a/addons/mrp_operations/__openerp__.py +++ b/addons/mrp_operations/__openerp__.py @@ -65,8 +65,11 @@ So that we can compare the theoretic delay and real delay. 'process/mrp_operation_process.xml', 'mrp_operations_workflow_instance.xml' ], - 'demo_xml': ['mrp_operation_data.xml'], - 'test': ['test/mrp_operations.yml', 'test/mrp_operations_report.yml','test/mrp_operation_test.yml'], + 'demo_xml': ['mrp_operation_data.xml', + 'mrp_operations_demo.yml'], + 'test': [ + 'test/workcenter_operations.yml', + ], 'installable': True, 'active': False, 'certificate': '0056233813133', diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index e6f5aa00f28..7bdb883e98e 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -350,6 +350,7 @@ class mrp_production(osv.osv): if l.production_id and (l.production_id.date_start < po.date_finished): self.write(cr, uid, [l.production_id.id], {'date_start': po.date_finished}) break + return True def write(self, cr, uid, ids, vals, context=None, update=True, mini=True): @@ -371,13 +372,13 @@ class mrp_production(osv.osv): pass return result - def action_compute(self, cr, uid, ids, properties=[]): + def action_compute(self, cr, uid, ids, properties=[], context=None): """ Computes bills of material of a product and planned date of work order. @param properties: List containing dictionaries of properties. @return: No. of products. """ - result = super(mrp_production, self).action_compute(cr, uid, ids, properties=properties) - self._compute_planned_workcenter(cr, uid, ids, context={}) + result = super(mrp_production, self).action_compute(cr, uid, ids, properties=properties, context=context) + self._compute_planned_workcenter(cr, uid, ids, context=context) return result mrp_production() diff --git a/addons/mrp_operations/mrp_operations_demo.yml b/addons/mrp_operations/mrp_operations_demo.yml new file mode 100644 index 00000000000..7bfef8a4c7b --- /dev/null +++ b/addons/mrp_operations/mrp_operations_demo.yml @@ -0,0 +1,24 @@ +- + !record {model: mrp.production, id: mrp_production_op}: + location_src_id: stock.stock_location_stock + product_id: product.product_product_cpu3 + product_qty: 5.0 + allow_reorder: True +- + !record {model: mrp.production, id: mrp_production_op1}: + location_src_id: stock.stock_location_stock + product_id: product.product_product_cpu3 + product_qty: 2.0 +- + !function {model: mrp.production, name: action_compute, id: mrp_production_op1}: + - model: mrp.production + eval: "[obj(ref('mrp_production_op1')).id]" +- + !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_op1} +- + !record {model: mrp.production, id: mrp_production_mo1}: + location_src_id: stock.stock_location_stock + product_id: product.product_product_cpu_gen + product_qty: 5.0 +- + !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_mo1} diff --git a/addons/mrp_operations/test/mrp_operation_test.yml b/addons/mrp_operations/test/mrp_operation_test.yml deleted file mode 100644 index 9cb81abebde..00000000000 --- a/addons/mrp_operations/test/mrp_operation_test.yml +++ /dev/null @@ -1,56 +0,0 @@ -- - In order to test mrp_operations module in OpenERP, - I create a production order. -- - !record {model: mrp.production, id: mrp_production_mo1}: - company_id: base.main_company - date_planned: !eval datetime.today().strftime("%Y-%m-%d %H:%M:%S") - location_dest_id: stock.stock_location_stock - location_src_id: stock.stock_location_stock - name: MO/01234567 - product_id: product.product_product_pc1 - product_qty: 5.0 - product_uom: product.product_uom_unit - product_uos_qty: 5.0 -- - Now I confirm the production order. -- - !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_mo1} -- - I check that there is one Work order generated related to the production order. -- - !python {model: mrp.production.workcenter.line}: | - from tools.translate import _ - order_id = self.search(cr, uid, [('production_id','=', ref('mrp_production_mo1')),('state','=','draft')]) - assert order_id, _('No work order defined for this production order!') -- - The scheduler runs. -- - !function {model: procurement.order, name: run_scheduler}: - - model: procurement.order - search: "[('state','=','confirmed')]" -- - I am checking Internal picking. -- - !python {model: mrp.production}: | - from tools.translate import _ - pick_ids = self.browse(cr, uid, ref("mrp_production_mo1")) - assert pick_ids.picking_id.id, _('No Internal Picking generated!') -- - In order to cancel the MO, first cancel its picking -- - !python {model: stock.picking}: | - mrp_obj = self.pool.get('mrp.production') - mo = mrp_obj.browse(cr, uid, ref("mrp_production_mo1")) - self.action_cancel(cr, uid, [mo.picking_id.id], context=None) -- - Then cancel The Manufacturing order. -- - !workflow {model: mrp.production, action: button_cancel, ref: mrp_production_mo1} -- - I check that there is one Work order generated related to the production order that is cancelled or not. -- - !python {model: mrp.production.workcenter.line}: | - from tools.translate import _ - order_id = self.search(cr, uid, [('production_id','=', ref('mrp_production_mo1')),('state','=','cancel')]) - assert order_id, _('Work order is not cancelled for this production order!') diff --git a/addons/mrp_operations/test/mrp_operations.yml b/addons/mrp_operations/test/mrp_operations.yml deleted file mode 100644 index ce6aac5cdbf..00000000000 --- a/addons/mrp_operations/test/mrp_operations.yml +++ /dev/null @@ -1,158 +0,0 @@ -- - In order to test mrp_operations module in OpenERP I will put a Production order - and check its effects on Work orders. -- - I create a production order. -- - !record {model: mrp.production, id: mrp_production_mo0}: - company_id: base.main_company - date_planned: !eval datetime.today().strftime("%Y-%m-%d %H:%M:%S") - location_dest_id: stock.stock_location_stock - location_src_id: stock.stock_location_stock - name: MO/0123456 - product_id: product.product_product_pc1 - product_qty: 5.0 - product_uom: product.product_uom_unit - product_uos_qty: 5.0 - allow_reorder: True -- - I am computing the data. -- - !python {model: mrp.production}: | - self.action_compute(cr, uid, [ref("mrp_production_mo0")], {"lang": "en_US", "tz": - False, "search_default_current": 1, "active_model": "ir.ui.menu", "active_ids": - [ref("mrp.menu_mrp_production_action")], "active_id": ref("mrp.menu_mrp_production_action"), - }) -- - Now I confirm my production order. -- - !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_mo0} -- - I check that there is one Work order generated related to my production order. -- - !python {model: mrp.production.workcenter.line}: | - from tools.translate import _ - order_id = self.search(cr, uid, [('production_id','=', ref('mrp_production_mo0')),('state','=','draft')]) - assert order_id, _('No Work order define for this production order!') -- - The scheduler runs. -- - !function {model: procurement.order, name: run_scheduler}: - - model: procurement.order - search: "[('state','=','confirmed')]" -- - I am checking Internal picking. -- - !python {model: stock.picking}: | - from tools.translate import _ - pick_ids = self.search(cr, uid, [('state','!=','done'),('type','=','internal')]) - assert pick_ids, _('No Internal Pickings!') -- - I see that there is a manufacturing order for the sub product CPU_GEN of PC1 with ready state. -- - !python {model: mrp.production}: | - from tools.translate import _ - order_ids = self.search(cr, uid, [('state','=','ready'),('origin','like','%MO/0123456')]) - assert order_ids, _('No new manufacturing order!') -- - I check that there one more work order created for new production order. -- - !python {model: mrp.production.workcenter.line}: | - from tools.translate import _ - prod_obj = self.pool.get('mrp.production') - prod_order_ids = prod_obj.search(cr, uid, [('state','=','ready'),('origin','like','%MO/0123456')]) - workorder_id = self.search(cr, uid, [('production_id','=', prod_order_ids[0]),('state','=','draft')]) - assert workorder_id, _('No Work order define for this production order!') -- - I start the second production order of the CPU_GEN product. -- - !python {model: mrp.production}: | - import netsvc - wf_service = netsvc.LocalService("workflow") - prod_order_ids = self.search(cr, uid, [('state','=','ready'),('origin','like','%MO/0123456')]) - for po in prod_order_ids: - wf_service.trg_validate(uid, 'mrp.production', po, 'button_produce', cr) -- - I am creating a mrp.product.produce record -- - !record {model: mrp.product.produce, id: mrp_product_produce_0}: - mode: consume_produce - product_qty: 5.0 -- - I produce the product CPU_GEN. -- - !python {model: mrp.product.produce}: | - prod_obj = self.pool.get('mrp.production') - prod_order_ids = prod_obj.search(cr, uid, [('origin','like','%MO/0123456')]) - self.do_produce(cr, uid, [ref("mrp_product_produce_0")], {"lang": "en_US", "tz": - False, "search_default_current": 1, "active_model": "mrp.production", "active_ids": - prod_order_ids, "active_id": prod_order_ids[0], }) -- - I check that my production order and its related work order is in done state. -- - !python {model: mrp.production.workcenter.line}: | - from tools.translate import _ - prod_obj = self.pool.get('mrp.production') - prod_order_ids = prod_obj.search(cr, uid, [('origin','like','%MO/0123456')]) - assert prod_order_ids, _('Workorder not found') - workorder_id = self.search(cr, uid, [('production_id','=', prod_order_ids[0])]) - workorder_bro = self.browse(cr, uid, workorder_id[0]) - assert workorder_bro.state == 'done', _('Work order is not done! It is %s') % workorder_bro.state -- - Now I check my original production order is now ready. -- - !python {model: mrp.production}: | - from tools.translate import _ - prod_ids = self.search(cr, uid, [('id','=',ref('mrp_production_mo0')),('state','=','ready')]) - assert prod_ids, _('Production order is not ready!') -- - I check that both internal pickings are done. -- - !python {model: stock.picking}: | - from tools.translate import _ - pick_ids = self.search(cr, uid, [('state','=','done'),('type','=','internal')]) - assert pick_ids, _('Internal pickings are not done!') -- - Now I start my first production order. -- - !workflow {model: mrp.production, action: button_produce, ref: mrp_production_mo0} -- - I check that the related work order is in progress state. -- - !python {model: mrp.production.workcenter.line}: | - from tools.translate import _ - order_id = self.search(cr, uid, [('production_id','=', ref('mrp_production_mo0')),('state','=','startworking')]) - assert order_id, _('Work order not started yet!') -- - I am creating a mrp.product.produce record. -- - !record {model: mrp.product.produce, id: mrp_product_produce_0}: - mode: consume_produce - product_qty: 5.0 -- - I produce the product PC1. -- - !python {model: mrp.product.produce}: | - prod_obj = self.pool.get('mrp.production') - prod_order_ids = prod_obj.search(cr, uid, [('state','=','in_production')]) - self.do_produce(cr, uid, [ref("mrp_product_produce_0")], {"lang": "en_US", "tz": - False, "search_default_current": 1, "active_model": "mrp.production", "active_ids": - [ref("mrp_production_mo0")], "active_id": ref("mrp_production_mo0"), }) -- - I check the related work order is done. -- - !python {model: mrp.production.workcenter.line}: | - from tools.translate import _ - order_id = self.search(cr, uid, [('production_id','=', ref('mrp_production_mo0')),('state','=','done')]) - assert order_id, _('Work order not done yet!') -- - Calculates start date for stock moves finding interval from resource calendar. -- - !python {model: mrp.production}: | - self._move_pass(cr, uid, [ref('mrp_production_mo0')], context=None) -- - Calculates planned end date of production order. -- - !python {model: mrp.production}: | - mo = self.browse(cr, uid, ref("mrp_production_mo0")) - self._production_date_end(cr, uid, [ref("mrp_production_mo0")], mo.date_planned, False, context=None) diff --git a/addons/mrp_operations/test/mrp_operations_report.yml b/addons/mrp_operations/test/mrp_operations_report.yml deleted file mode 100644 index f0a646adf4e..00000000000 --- a/addons/mrp_operations/test/mrp_operations_report.yml +++ /dev/null @@ -1,17 +0,0 @@ -- - In order to test the PDF reports defined on a MRP Operations, we will print a Barcode Report -- - !python {model: mrp_operations.operation.code}: | - import netsvc, tools, os - (data, format) = netsvc.LocalService('report.mrp.code.barcode').create(cr, uid, [ref('mrp_operations.mrp_op_1'),ref('mrp_operations.mrp_op_2'),ref('mrp_operations.mrp_op_3'),ref('mrp_operations.mrp_op_4'),ref('mrp_operations.mrp_op_5')], {}, {}) - if tools.config['test_report_directory']: - file(os.path.join(tools.config['test_report_directory'], 'mrp_operations-barcode_report.'+format), 'wb+').write(data) - -- - In order to test the PDF reports defined on a MRP Operations, we will print Workcenter's Barcode Report -- - !python {model: mrp.workcenter}: | - import netsvc, tools, os - (data, format) = netsvc.LocalService('report.mrp.wc.barcode').create(cr, uid, [ref('mrp.mrp_workcenter_0'),ref('mrp.mrp_workcenter_1')], {}, {}) - if tools.config['test_report_directory']: - file(os.path.join(tools.config['test_report_directory'], 'mrp_operations-workcenter_barcode_report.'+format), 'wb+').write(data) diff --git a/addons/mrp_operations/test/workcenter_operations.yml b/addons/mrp_operations/test/workcenter_operations.yml new file mode 100644 index 00000000000..23fbe15c37d --- /dev/null +++ b/addons/mrp_operations/test/workcenter_operations.yml @@ -0,0 +1,120 @@ +- + I compute the production order. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp.mrp_production_shelf100cm"), context=context) + order.action_compute(context=context) +- + I check planned date in workcenter lines of production order. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp.mrp_production_shelf100cm"), context=context) + for line in order.workcenter_lines: + #TODO: to check start date of next line should be end of date of previous line. + assert line.date_planned, "Planned Start date is not computed: %s" %(line) + assert line.date_planned_end, "Planned End date is not computed: %s" %(line) + +- + I confirm the Production Order. +- + !workflow {model: mrp.production, action: button_confirm, ref: mrp.mrp_production_shelf100cm} +- + I run scheduler. +- + !python {model: procurement.order}: | + self.run_scheduler(cr, uid) +- + I forcefully close internal shipment. +- + !python {model: mrp.production}: | + self.force_production(cr, uid, [ref("mrp.mrp_production_shelf100cm")]) +- + I start production. +- + !workflow {model: mrp.production, action: button_produce, ref: mrp.mrp_production_shelf100cm} +- + Production start on first work center, so I start work operation on first work center. +- + !python {model: mrp.production}: | + import netsvc + order = self.browse(cr, uid, ref("mrp.mrp_production_shelf100cm"), context=context) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'mrp.production.workcenter.line', order.workcenter_lines[0].id, 'button_start_working', cr) +- + Now I pause first work operation due to technical fault of work center. +- + !python {model: mrp.production}: | + import netsvc + order = self.browse(cr, uid, ref("mrp.mrp_production_shelf100cm"), context=context) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'mrp.production.workcenter.line', order.workcenter_lines[0].id, 'button_pause', cr) + wf_service.trg_validate(uid, 'mrp.production.workcenter.line', order.workcenter_lines[0].id, 'button_resume', cr) +- + I resume first work operation. +- + !python {model: mrp.production}: | + import netsvc + order = self.browse(cr, uid, ref("mrp.mrp_production_shelf100cm"), context=context) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'mrp.production.workcenter.line', order.workcenter_lines[0].id, 'button_resume', cr) + +- + I cancel first work operation. +- + !python {model: mrp.production}: | + import netsvc + order = self.browse(cr, uid, ref("mrp.mrp_production_shelf100cm"), context=context) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'mrp.production.workcenter.line', order.workcenter_lines[0].id, 'button_cancel', cr) +- + I reset first work operation and start after resolve techninal fault of work center. +- + !python {model: mrp.production}: | + import netsvc + order = self.browse(cr, uid, ref("mrp.mrp_production_shelf100cm"), context=context) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'mrp.production.workcenter.line', order.workcenter_lines[0].id, 'button_draft', cr) + wf_service.trg_validate(uid, 'mrp.production.workcenter.line', order.workcenter_lines[0].id, 'button_start_working', cr) +- + Now Finished work of first work operation so I close that operation. +- + !python {model: mrp.production}: | + import netsvc + order = self.browse(cr, uid, ref("mrp.mrp_production_shelf100cm"), context=context) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'mrp.production.workcenter.line', order.workcenter_lines[0].id, 'button_done', cr) +- + Now I close other operations after start one by one. +- + !python {model: mrp.production}: | + import netsvc + order = self.browse(cr, uid, ref("mrp.mrp_production_shelf100cm"), context=context) + wf_service = netsvc.LocalService("workflow") + for work_line in order.workcenter_lines[1:]: + wf_service.trg_validate(uid, 'mrp.production.workcenter.line', work_line.id, 'button_start_working', cr) + wf_service.trg_validate(uid, 'mrp.production.workcenter.line', work_line.id, 'button_done', cr) + +- + I check that the production order is now done. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp.mrp_production_shelf100cm"), context=context) + print order.state + assert order.state == 'done', "Production should be closed after finished all operations." +- + I print a Barcode Report of Operation line. +- + !python {model: mrp_operations.operation.code}: | + import netsvc, tools, os + (data, format) = netsvc.LocalService('report.mrp.code.barcode').create(cr, uid, [ref('mrp_operations.mrp_op_1'),ref('mrp_operations.mrp_op_2'),ref('mrp_operations.mrp_op_3'),ref('mrp_operations.mrp_op_4'),ref('mrp_operations.mrp_op_5')], {}, {}) + if tools.config['test_report_directory']: + file(os.path.join(tools.config['test_report_directory'], 'mrp_operations-barcode_report.'+format), 'wb+').write(data) + +- + I print Workcenter's Barcode Report. +- + !python {model: mrp.workcenter}: | + import netsvc, tools, os + (data, format) = netsvc.LocalService('report.mrp.wc.barcode').create(cr, uid, [ref('mrp.mrp_workcenter_0'),ref('mrp.mrp_workcenter_1')], {}, {}) + if tools.config['test_report_directory']: + file(os.path.join(tools.config['test_report_directory'], 'mrp_operations-workcenter_barcode_report.'+format), 'wb+').write(data) diff --git a/addons/product/product_demo.xml b/addons/product/product_demo.xml index 3aebec13715..99347667f80 100644 --- a/addons/product/product_demo.xml +++ b/addons/product/product_demo.xml @@ -442,6 +442,16 @@ product + + SPAN100 + produce + + + + Shelf Panel + product + + WOOD002 buy @@ -455,6 +465,19 @@ + + WOOD010 + buy + 7.0 + + + Wood 10mm + + + product + + + PROJ produce @@ -509,7 +532,7 @@ RPAN100 - buy + produce 10.0 @@ -548,7 +571,7 @@ RCK100 - buy + produce 5.0