From b4910caba846eceaf72c25c3719ac96047dcfeaa Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Fri, 26 Apr 2013 15:33:36 +0530 Subject: [PATCH 01/30] [IMP] add new transition in mrp work flow bzr revid: jap@tinyerp.com-20130426100336-g1aavbal40bne1qa --- addons/mrp/mrp_workflow.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/mrp/mrp_workflow.xml b/addons/mrp/mrp_workflow.xml index a0943628fc8..c8102ae2a3a 100644 --- a/addons/mrp/mrp_workflow.xml +++ b/addons/mrp/mrp_workflow.xml @@ -77,6 +77,14 @@ button_produce + + + + + button_produce_done + test_production_done() + + From 0d9dfd54e795c822e4353869a4fd79aeff9d6984 Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Wed, 1 May 2013 19:02:29 +0530 Subject: [PATCH 02/30] [IMP] Improve code in mrp.py for service type product bzr revid: jap@tinyerp.com-20130501133229-1kt9kp9aunm5np9l --- addons/mrp/mrp.py | 4 +++- addons/mrp/mrp_workflow.xml | 7 ------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 44fbaafbcfe..df798762b5a 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -774,8 +774,10 @@ class mrp_production(osv.osv): new_parent_ids.append(final_product.id) for new_parent_id in new_parent_ids: stock_mov_obj.write(cr, uid, [raw_product.id], {'move_history_ids': [(4,new_parent_id)]}) - wf_service = netsvc.LocalService("workflow") + for componant in production.bom_id.bom_lines: + if componant.product_id.type == 'service' and not production.move_lines or not production.move_lines2: + wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce', cr) wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce_done', cr) return True diff --git a/addons/mrp/mrp_workflow.xml b/addons/mrp/mrp_workflow.xml index c8102ae2a3a..1c3e2ac6b1f 100644 --- a/addons/mrp/mrp_workflow.xml +++ b/addons/mrp/mrp_workflow.xml @@ -78,13 +78,6 @@ button_produce - - - - button_produce_done - test_production_done() - - From 4eabc8f1863a255efc439c4bf731da3995cbed61 Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Thu, 2 May 2013 11:55:51 +0530 Subject: [PATCH 03/30] [IMP] Improve code for mrp work flow bzr revid: jap@tinyerp.com-20130502062551-tk4jlx4l61rhhhce --- addons/mrp/mrp.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index df798762b5a..04c567fec90 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -982,6 +982,7 @@ class mrp_production(osv.osv): 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) @@ -996,7 +997,9 @@ class mrp_production(osv.osv): 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) - + for componant in production.bom_id.bom_lines: + if componant.product_id.type == 'service' and not production.move_lines or not production.move_lines2: + wf_service.trg_validate(uid, 'mrp.production', shipment_id, 'button_confirm', cr) wf_service.trg_validate(uid, 'stock.picking', shipment_id, 'button_confirm', cr) production.write({'state':'confirmed'}, context=context) return shipment_id From 07cb4cd08393534067cd16db84afaf6b2cff618a Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Thu, 2 May 2013 11:58:18 +0530 Subject: [PATCH 04/30] [IMP] Remove unwated change bzr revid: jap@tinyerp.com-20130502062818-ghys3kb5mp6rt5af --- addons/mrp/mrp.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 04c567fec90..b1927f80cf2 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -775,9 +775,6 @@ class mrp_production(osv.osv): for new_parent_id in new_parent_ids: stock_mov_obj.write(cr, uid, [raw_product.id], {'move_history_ids': [(4,new_parent_id)]}) wf_service = netsvc.LocalService("workflow") - for componant in production.bom_id.bom_lines: - if componant.product_id.type == 'service' and not production.move_lines or not production.move_lines2: - wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce', cr) wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce_done', cr) return True From df08c2cb70665ee9c4226b156dc1a2adbd099b64 Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Thu, 2 May 2013 19:00:27 +0530 Subject: [PATCH 05/30] [IMP] improve code bzr revid: jap@tinyerp.com-20130502133027-rgu6etatmcaflaeg --- addons/mrp/mrp.py | 11 +++++++---- addons/mrp/stock.py | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index b1927f80cf2..d7d5f0d2c59 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -837,6 +837,9 @@ class mrp_production(osv.osv): if not production.product_lines: if not self.action_compute(cr, uid, [production.id]): res = False + for componant in production.bom_id.bom_lines: + if componant.product_id.type == 'service' and not production.move_lines or not production.move_lines2: + res=False return res def _get_auto_picking(self, cr, uid, production): @@ -983,7 +986,10 @@ class mrp_production(osv.osv): 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) - + for componant in production.bom_id.bom_lines: + if componant.product_id.type == 'service' and not production.move_lines or not production.move_lines2: + wf_service.trg_validate(uid, 'mrp.production', shipment_id, 'button_confirm', cr) + production.write({'state':'confirmed'}, 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: @@ -994,9 +1000,6 @@ class mrp_production(osv.osv): 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) - for componant in production.bom_id.bom_lines: - if componant.product_id.type == 'service' and not production.move_lines or not production.move_lines2: - wf_service.trg_validate(uid, 'mrp.production', shipment_id, 'button_confirm', cr) wf_service.trg_validate(uid, 'stock.picking', shipment_id, 'button_confirm', cr) production.write({'state':'confirmed'}, context=context) return shipment_id diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 60a50c90d1e..a666fe8d4b6 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -182,6 +182,8 @@ class split_in_production_lot(osv.osv_memory): production_obj.write(cr, uid, production_ids, {'move_lines': [(4, m) for m in new_moves]}) return new_moves + + split_in_production_lot() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 5126a05c4adaaddc2929aa67e0382ed6f0563cd6 Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Fri, 3 May 2013 10:42:52 +0530 Subject: [PATCH 06/30] [IMP] remove unwated change bzr revid: jap@tinyerp.com-20130503051252-c8o424i116yqkd14 --- addons/mrp/mrp.py | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index d7d5f0d2c59..4948e7c2f04 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -989,7 +989,6 @@ class mrp_production(osv.osv): for componant in production.bom_id.bom_lines: if componant.product_id.type == 'service' and not production.move_lines or not production.move_lines2: wf_service.trg_validate(uid, 'mrp.production', shipment_id, 'button_confirm', cr) - production.write({'state':'confirmed'}, 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: From 6644af8c8870251a566d0c823d58d34153934b11 Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Fri, 3 May 2013 11:03:37 +0530 Subject: [PATCH 07/30] [IMP] improve code bzr revid: jap@tinyerp.com-20130503053337-9vmq3t903dwwcjkt --- addons/mrp/mrp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 4948e7c2f04..31a86fadf0d 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -987,7 +987,7 @@ class mrp_production(osv.osv): 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) for componant in production.bom_id.bom_lines: - if componant.product_id.type == 'service' and not production.move_lines or not production.move_lines2: + if componant.product_id.type == 'service' and not production.move_lines and not production.move_lines2: wf_service.trg_validate(uid, 'mrp.production', shipment_id, 'button_confirm', cr) # Take routing location as a Source Location. source_location_id = production.location_src_id.id From cdb7c6603edb81b3da8136bd33bf6b8dc1e5905b Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Fri, 3 May 2013 11:09:48 +0530 Subject: [PATCH 08/30] [IMP] bit improve code for yml test bzr revid: jap@tinyerp.com-20130503053948-3hdhmh5vljw43uuh --- addons/mrp/mrp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 31a86fadf0d..0e0feb2f38c 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -838,7 +838,7 @@ class mrp_production(osv.osv): if not self.action_compute(cr, uid, [production.id]): res = False for componant in production.bom_id.bom_lines: - if componant.product_id.type == 'service' and not production.move_lines or not production.move_lines2: + if componant.product_id.type == 'service' and not production.move_lines and not production.move_lines2: res=False return res From 45e461bd645f685a1fb78454b90685a77b3d73f0 Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Fri, 3 May 2013 11:29:34 +0530 Subject: [PATCH 09/30] [IMP] improve code for the button product bzr revid: jap@tinyerp.com-20130503055934-8rrgvydvxkadwwxh --- addons/mrp/mrp.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 0e0feb2f38c..2c52ca87924 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -775,6 +775,9 @@ class mrp_production(osv.osv): for new_parent_id in new_parent_ids: stock_mov_obj.write(cr, uid, [raw_product.id], {'move_history_ids': [(4,new_parent_id)]}) wf_service = netsvc.LocalService("workflow") + for componant in production.bom_id.bom_lines: + if componant.product_id.type == 'service' and not production.move_lines and not production.move_lines2: + wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce', cr) wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce_done', cr) return True From 8e8d370ba9213a74e8acec69d47515e65bc76b13 Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Fri, 3 May 2013 12:47:54 +0530 Subject: [PATCH 10/30] [IMP] improve code and remove unwated change bzr revid: jap@tinyerp.com-20130503071754-vwok8xpjcjo63m9o --- addons/mrp/mrp.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 2c52ca87924..38c564961bd 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -841,8 +841,8 @@ class mrp_production(osv.osv): if not self.action_compute(cr, uid, [production.id]): res = False for componant in production.bom_id.bom_lines: - if componant.product_id.type == 'service' and not production.move_lines and not production.move_lines2: - res=False + if componant.product_id.type == 'service' and not production.move_lines: + res=True return res def _get_auto_picking(self, cr, uid, production): @@ -989,9 +989,6 @@ class mrp_production(osv.osv): 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) - for componant in production.bom_id.bom_lines: - if componant.product_id.type == 'service' and not production.move_lines and not production.move_lines2: - wf_service.trg_validate(uid, 'mrp.production', shipment_id, 'button_confirm', cr) # 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: From 555636280e030dba2592691bed1b69addc2eea2d Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Fri, 3 May 2013 16:20:29 +0530 Subject: [PATCH 11/30] [IMP] improve code in for mrp stock.py bzr revid: jap@tinyerp.com-20130503105029-d9eqs4curvxwuvra --- addons/mrp/mrp.py | 4 ---- addons/mrp/stock.py | 7 +++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 38c564961bd..d15aace7cae 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -840,9 +840,6 @@ class mrp_production(osv.osv): if not production.product_lines: if not self.action_compute(cr, uid, [production.id]): res = False - for componant in production.bom_id.bom_lines: - if componant.product_id.type == 'service' and not production.move_lines: - res=True return res def _get_auto_picking(self, cr, uid, production): @@ -985,7 +982,6 @@ class mrp_production(osv.osv): 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) diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index a666fe8d4b6..79e9b0bcc73 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -164,6 +164,13 @@ class StockPicking(osv.osv): for move in move_obj.browse(cr, uid, move_ids): todo.extend(move_obj._action_explode(cr, uid, move)) return list(set(todo)) + + def test_cancel(self, cr, uid, ids, context=None): + res = super(StockPicking, self).test_cancel(cr, uid, ids, context=context) + for pick in self.browse(cr, uid, ids, context=context): + if not pick.move_lines: + return False + return res StockPicking() From 10e0fb9325fae65c91e37ba7e09ececbc5273c49 Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Fri, 10 May 2013 18:26:47 +0530 Subject: [PATCH 12/30] [IMP] Improve code when do all move done but mo not in done state bzr revid: jap@tinyerp.com-20130510125647-0wgx5ktufaax8lnz --- addons/mrp/stock.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 79e9b0bcc73..59689bcc206 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -147,6 +147,18 @@ class StockMove(osv.osv): production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]}) res.append(new_move) return res + + def action_done(self, cr, uid, ids, context=None): + res = super(StockMove, self).action_done(cr, uid, ids, context=context) + production_obj = self.pool.get('mrp.production') + wf_service = netsvc.LocalService("workflow") + for move in self.browse(cr, uid, ids, context=context): + production_ids = production_obj.search(cr, uid, [('move_created_ids', 'in', [move.id])]) + if production_ids: + product_data = production_obj.browse(cr, uid, production_ids[0]) + if product_data.move_created_ids2 and product_data.move_lines2 and move.state=='done': + wf_service.trg_validate(uid, 'mrp.production', product_data.id, 'button_produce_done', cr) + return res StockMove() From 8f1393f3caf7ffd135cfd2a31488b3c6484c77d7 Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Wed, 15 May 2013 18:27:45 +0530 Subject: [PATCH 13/30] [IMP] Improve code when bom componant is service stock move in available state bzr revid: jap@tinyerp.com-20130515125745-da9sybl7osixzhfm --- addons/mrp/mrp.py | 5 ++--- addons/mrp/mrp_workflow.xml | 8 ++++++++ addons/mrp/stock.py | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index d15aace7cae..91b6a7a0798 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -647,6 +647,8 @@ class mrp_production(osv.osv): for (production_id,name) in self.name_get(cr, uid, ids): production = self.browse(cr, uid, production_id) + if not production.move_prod_id and not production.move_lines: + move_obj.write(cr, uid, [i.id for i in production.move_created_ids], {'state': 'assigned'}) if production.move_prod_id and production.move_prod_id.location_id.id != production.location_dest_id.id: move_obj.write(cr, uid, [production.move_prod_id.id], {'location_id': production.location_dest_id.id}) @@ -775,9 +777,6 @@ class mrp_production(osv.osv): for new_parent_id in new_parent_ids: stock_mov_obj.write(cr, uid, [raw_product.id], {'move_history_ids': [(4,new_parent_id)]}) wf_service = netsvc.LocalService("workflow") - for componant in production.bom_id.bom_lines: - if componant.product_id.type == 'service' and not production.move_lines and not production.move_lines2: - wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce', cr) wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce_done', cr) return True diff --git a/addons/mrp/mrp_workflow.xml b/addons/mrp/mrp_workflow.xml index 1c3e2ac6b1f..b57fe64158e 100644 --- a/addons/mrp/mrp_workflow.xml +++ b/addons/mrp/mrp_workflow.xml @@ -72,6 +72,14 @@ picking_id and picking_id.state=='done' + + + + + button_produce_done + not move_lines and test_production_done() + + diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 59689bcc206..3ae8736641c 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -158,6 +158,8 @@ class StockMove(osv.osv): product_data = production_obj.browse(cr, uid, production_ids[0]) if product_data.move_created_ids2 and product_data.move_lines2 and move.state=='done': wf_service.trg_validate(uid, 'mrp.production', product_data.id, 'button_produce_done', cr) + elif not product_data.move_lines2 and move.state=='done': + wf_service.trg_validate(uid, 'mrp.production', product_data.id, 'button_produce_done', cr) return res StockMove() From 21d80930b00ef237ec2e823cce157b509853cd40 Mon Sep 17 00:00:00 2001 From: Jagdish Panchal Date: Fri, 17 May 2013 12:10:41 +0530 Subject: [PATCH 14/30] [IMP] remove unwanted change bzr revid: jap@tinyerp.com-20130517064041-bf7jq2p04zgp480n --- addons/mrp/mrp.py | 3 +++ addons/mrp/stock.py | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 91b6a7a0798..0d210544356 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -776,6 +776,7 @@ class mrp_production(osv.osv): new_parent_ids.append(final_product.id) for new_parent_id in new_parent_ids: stock_mov_obj.write(cr, uid, [raw_product.id], {'move_history_ids': [(4,new_parent_id)]}) + wf_service = netsvc.LocalService("workflow") wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce_done', cr) return True @@ -984,6 +985,7 @@ class mrp_production(osv.osv): 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: @@ -994,6 +996,7 @@ class mrp_production(osv.osv): 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) return shipment_id diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 3ae8736641c..1404f2bbcb0 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -203,8 +203,6 @@ class split_in_production_lot(osv.osv_memory): production_obj.write(cr, uid, production_ids, {'move_lines': [(4, m) for m in new_moves]}) return new_moves - - split_in_production_lot() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From f630a3a64aa02df339bf4bf856f01357f5086f77 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Mon, 27 May 2013 16:39:01 +0530 Subject: [PATCH 15/30] [IMP] Added context whereever necessary, improved code of action_done and removed unwanted spaces. bzr revid: psa@tinyerp.com-20130527110901-q6717focg99qq46a --- addons/mrp/mrp.py | 6 +++--- addons/mrp/mrp_workflow.xml | 3 +-- addons/mrp/stock.py | 12 +++++------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 0d210544356..ef31f7aaa87 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -776,7 +776,7 @@ class mrp_production(osv.osv): new_parent_ids.append(final_product.id) for new_parent_id in new_parent_ids: stock_mov_obj.write(cr, uid, [raw_product.id], {'move_history_ids': [(4,new_parent_id)]}) - + wf_service = netsvc.LocalService("workflow") wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce_done', cr) return True @@ -985,7 +985,7 @@ class mrp_production(osv.osv): 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: @@ -996,7 +996,7 @@ class mrp_production(osv.osv): 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) return shipment_id diff --git a/addons/mrp/mrp_workflow.xml b/addons/mrp/mrp_workflow.xml index b57fe64158e..93dacc15f3c 100644 --- a/addons/mrp/mrp_workflow.xml +++ b/addons/mrp/mrp_workflow.xml @@ -73,7 +73,7 @@ picking_id and picking_id.state=='done' - + button_produce_done @@ -85,7 +85,6 @@ button_produce - diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 1404f2bbcb0..789ca876242 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -153,14 +153,12 @@ class StockMove(osv.osv): production_obj = self.pool.get('mrp.production') wf_service = netsvc.LocalService("workflow") for move in self.browse(cr, uid, ids, context=context): - production_ids = production_obj.search(cr, uid, [('move_created_ids', 'in', [move.id])]) + production_ids = production_obj.search(cr, uid, [('move_created_ids', 'in', [move.id])], context=context) if production_ids: - product_data = production_obj.browse(cr, uid, production_ids[0]) - if product_data.move_created_ids2 and product_data.move_lines2 and move.state=='done': + product_data = production_obj.browse(cr, uid, production_ids[0], context=context) + if product_data.move_created_ids2 and move.state=='done': wf_service.trg_validate(uid, 'mrp.production', product_data.id, 'button_produce_done', cr) - elif not product_data.move_lines2 and move.state=='done': - wf_service.trg_validate(uid, 'mrp.production', product_data.id, 'button_produce_done', cr) - return res + return res StockMove() @@ -184,7 +182,7 @@ class StockPicking(osv.osv): for pick in self.browse(cr, uid, ids, context=context): if not pick.move_lines: return False - return res + return res StockPicking() From 4708fce25c14e2413b87f1a4a03a59b5871b9090 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Mon, 27 May 2013 17:12:36 +0530 Subject: [PATCH 16/30] Little improvement. bzr revid: psa@tinyerp.com-20130527114236-f1ryogo75y9cnxn7 --- addons/mrp/mrp.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index ef31f7aaa87..caccb846fd2 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -643,15 +643,15 @@ class mrp_production(osv.osv): @return: True """ move_obj = self.pool.get('stock.move') - self.write(cr, uid, ids, {'state': 'ready'}) + self.write(cr, uid, ids, {'state': 'ready'}, context=context) for (production_id,name) in self.name_get(cr, uid, ids): - production = self.browse(cr, uid, production_id) + production = self.browse(cr, uid, production_id, context=context) if not production.move_prod_id and not production.move_lines: - move_obj.write(cr, uid, [i.id for i in production.move_created_ids], {'state': 'assigned'}) + move_obj.write(cr, uid, [i.id for i in production.move_created_ids], {'state': 'assigned'}, context=context) if production.move_prod_id and production.move_prod_id.location_id.id != production.location_dest_id.id: move_obj.write(cr, uid, [production.move_prod_id.id], - {'location_id': production.location_dest_id.id}) + {'location_id': production.location_dest_id.id}, context=context) return True def action_production_end(self, cr, uid, ids, context=None): From 9d6cc517289bb58600d7c5c5f2c61163d436c7be Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 22 Aug 2013 16:38:48 +0530 Subject: [PATCH 17/30] [ADD] Added the test for MRP Issue where producing a BoM with a component of Service type is not possible. bzr revid: psa@tinyerp.com-20130822110848-kg8g2s3gfhbgxsg9 --- addons/mrp/__openerp__.py | 1 + .../test/bom_with_service_type_product.yml | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 addons/mrp/test/bom_with_service_type_product.yml diff --git a/addons/mrp/__openerp__.py b/addons/mrp/__openerp__.py index 6e025ae2d90..d712926879e 100644 --- a/addons/mrp/__openerp__.py +++ b/addons/mrp/__openerp__.py @@ -77,6 +77,7 @@ Dashboard / Reports for MRP will include: #TODO: This yml tests are needed to be completely reviewed again because the product wood panel is removed in product demo as it does not suit for new demo context of computer and consultant company # so the ymls are too complex to change at this stage 'test': [ +# 'test/bom_with_service_type_product.yml', # 'test/order_demo.yml', # 'test/order_process.yml', # 'test/cancel_order.yml', diff --git a/addons/mrp/test/bom_with_service_type_product.yml b/addons/mrp/test/bom_with_service_type_product.yml new file mode 100644 index 00000000000..34c3505a238 --- /dev/null +++ b/addons/mrp/test/bom_with_service_type_product.yml @@ -0,0 +1,60 @@ +- + I create Bill of Materials with one service type product and one consumable product. +- + !record {model: mrp.bom, id: mrp_bom_test1}: + company_id: base.main_company + name: BOM with Service type products + product_id: product.product_product_4 + product_qty: 1.0 + type: normal + bom_lines: + - company_id: base.main_company + name: On Site Assistance + product_id: product.product_product_3 + product_qty: 1.0 + - company_id: base.main_company + name: GrapWorks Software + product_id: product.product_product_45 + product_qty: 1.0 +- + I make the production order for BoM having one service type product and one consumable product. +- + !record {model: mrp.production, id: mrp_production_servicetype_mo1}: + product_id: product.product_product_6 + product_qty: 1.0 + bom_id: mrp_bom_test1 + date_planned: !eval time.strftime('%Y-%m-%d %H:%M:%S') +- + I compute the data of production order. +- + !python {model: mrp.production}: | + self.action_compute(cr, uid, [ref("mrp_production_servicetype_mo1")], {"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"), }) +- + I confirm the production order. +- + !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_servicetype_mo1} +- + I confirm the Consume Products. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_servicetype_mo1")) + assert order.state == 'confirmed', "Production order should be confirmed." + for move_line in order.move_lines: + move_line.action_consume(move_line.product_qty) +- + I processed the Product Entirely. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_servicetype_mo1")) + assert order.state == 'in_production', 'Production order should be in production State.' + for move_created in order.move_created_ids: + move_created.action_done() +- + I check production order after produced. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_servicetype_mo1")) + assert order.state == 'done', "Production order should be closed." + From b4d13e3c3d3ba00dc7547bbf62925f593701d364 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Tue, 27 Aug 2013 11:16:08 +0530 Subject: [PATCH 18/30] [IMP] Improved the product_id in yml. bzr revid: psa@tinyerp.com-20130827054608-ppf03r3xzu9td4db --- addons/mrp/__openerp__.py | 2 +- addons/mrp/test/bom_with_service_type_product.yml | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/addons/mrp/__openerp__.py b/addons/mrp/__openerp__.py index d712926879e..d33fa4d2622 100644 --- a/addons/mrp/__openerp__.py +++ b/addons/mrp/__openerp__.py @@ -77,7 +77,7 @@ Dashboard / Reports for MRP will include: #TODO: This yml tests are needed to be completely reviewed again because the product wood panel is removed in product demo as it does not suit for new demo context of computer and consultant company # so the ymls are too complex to change at this stage 'test': [ -# 'test/bom_with_service_type_product.yml', + 'test/bom_with_service_type_product.yml', # 'test/order_demo.yml', # 'test/order_process.yml', # 'test/cancel_order.yml', diff --git a/addons/mrp/test/bom_with_service_type_product.yml b/addons/mrp/test/bom_with_service_type_product.yml index 34c3505a238..d6fb35127a0 100644 --- a/addons/mrp/test/bom_with_service_type_product.yml +++ b/addons/mrp/test/bom_with_service_type_product.yml @@ -3,24 +3,24 @@ - !record {model: mrp.bom, id: mrp_bom_test1}: company_id: base.main_company - name: BOM with Service type products - product_id: product.product_product_4 + name: PC Assemble SC234 + product_id: product.product_product_3 product_qty: 1.0 type: normal bom_lines: - company_id: base.main_company name: On Site Assistance - product_id: product.product_product_3 + product_id: product.product_product_2 product_qty: 1.0 - company_id: base.main_company name: GrapWorks Software - product_id: product.product_product_45 + product_id: product.product_product_44 product_qty: 1.0 - - I make the production order for BoM having one service type product and one consumable product. + I make the production order using BoM having one service type product and one consumable product. - !record {model: mrp.production, id: mrp_production_servicetype_mo1}: - product_id: product.product_product_6 + product_id: product.product_product_5 product_qty: 1.0 bom_id: mrp_bom_test1 date_planned: !eval time.strftime('%Y-%m-%d %H:%M:%S') @@ -57,4 +57,3 @@ !python {model: mrp.production}: | order = self.browse(cr, uid, ref("mrp_production_servicetype_mo1")) assert order.state == 'done', "Production order should be closed." - From 9adf175561bf1618de1067116c3e4502fcf6aa33 Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Wed, 4 Sep 2013 11:44:51 +0530 Subject: [PATCH 19/30] [IMP] refered sale_line_id of procurement_order from stock_move object bzr revid: bde@tinyerp.com-20130904061451-ouptbee94gb2dsht --- addons/mrp/mrp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index c3e17563ec4..8ad668e14f8 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -879,6 +879,7 @@ class mrp_production(osv.osv): 'procure_method': production_line.product_id.procure_method, 'move_id': shipment_move_id, 'company_id': production.company_id.id, + 'sale_line_id': production.move_prod_id and production.move_prod_id.sale_line_id and production.move_prod_id.sale_line_id.id }) wf_service.trg_validate(uid, procurement_order._name, procurement_id, 'button_confirm', cr) return procurement_id From f716d9bf9c1b683ff5cae1485bbd04a5bb782ba5 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Wed, 11 Sep 2013 18:00:44 +0530 Subject: [PATCH 20/30] [REM] Removed the unwanted code. bzr revid: psa@tinyerp.com-20130911123044-xgw123lfj62cx71x --- addons/mrp/mrp.py | 9 +++------ addons/mrp/mrp_workflow.xml | 8 -------- addons/mrp/stock.py | 19 ------------------- 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 8ad668e14f8..7cdd24a710c 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -657,15 +657,13 @@ class mrp_production(osv.osv): @return: True """ move_obj = self.pool.get('stock.move') - self.write(cr, uid, ids, {'state': 'ready'}, context=context) + self.write(cr, uid, ids, {'state': 'ready'}) for (production_id,name) in self.name_get(cr, uid, ids): - production = self.browse(cr, uid, production_id, context=context) - if not production.move_prod_id and not production.move_lines: - move_obj.write(cr, uid, [i.id for i in production.move_created_ids], {'state': 'assigned'}, context=context) + production = self.browse(cr, uid, production_id) if production.move_prod_id and production.move_prod_id.location_id.id != production.location_dest_id.id: move_obj.write(cr, uid, [production.move_prod_id.id], - {'location_id': production.location_dest_id.id}, context=context) + {'location_id': production.location_dest_id.id}) return True def action_production_end(self, cr, uid, ids, context=None): @@ -879,7 +877,6 @@ class mrp_production(osv.osv): 'procure_method': production_line.product_id.procure_method, 'move_id': shipment_move_id, 'company_id': production.company_id.id, - 'sale_line_id': production.move_prod_id and production.move_prod_id.sale_line_id and production.move_prod_id.sale_line_id.id }) wf_service.trg_validate(uid, procurement_order._name, procurement_id, 'button_confirm', cr) return procurement_id diff --git a/addons/mrp/mrp_workflow.xml b/addons/mrp/mrp_workflow.xml index 93dacc15f3c..a0943628fc8 100644 --- a/addons/mrp/mrp_workflow.xml +++ b/addons/mrp/mrp_workflow.xml @@ -72,14 +72,6 @@ picking_id and picking_id.state=='done' - - - - - button_produce_done - not move_lines and test_production_done() - - diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 789ca876242..60a50c90d1e 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -147,18 +147,6 @@ class StockMove(osv.osv): production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]}) res.append(new_move) return res - - def action_done(self, cr, uid, ids, context=None): - res = super(StockMove, self).action_done(cr, uid, ids, context=context) - production_obj = self.pool.get('mrp.production') - wf_service = netsvc.LocalService("workflow") - for move in self.browse(cr, uid, ids, context=context): - production_ids = production_obj.search(cr, uid, [('move_created_ids', 'in', [move.id])], context=context) - if production_ids: - product_data = production_obj.browse(cr, uid, production_ids[0], context=context) - if product_data.move_created_ids2 and move.state=='done': - wf_service.trg_validate(uid, 'mrp.production', product_data.id, 'button_produce_done', cr) - return res StockMove() @@ -176,13 +164,6 @@ class StockPicking(osv.osv): for move in move_obj.browse(cr, uid, move_ids): todo.extend(move_obj._action_explode(cr, uid, move)) return list(set(todo)) - - def test_cancel(self, cr, uid, ids, context=None): - res = super(StockPicking, self).test_cancel(cr, uid, ids, context=context) - for pick in self.browse(cr, uid, ids, context=context): - if not pick.move_lines: - return False - return res StockPicking() From a3482a990f62c21e1b3612e8dcc3220da9a22a1b Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Wed, 11 Sep 2013 19:41:23 +0530 Subject: [PATCH 21/30] [IMP] Improved code for the BOM with service type product. bzr revid: psa@tinyerp.com-20130911141123-snw3u5mgtf4xv3k6 --- addons/mrp/mrp.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 7cdd24a710c..9b6b3e28d28 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -632,7 +632,7 @@ class mrp_production(osv.osv): for line in results2: line['production_id'] = production.id workcenter_line_obj.create(cr, uid, line) - return len(results) + return results def action_cancel(self, cr, uid, ids, context=None): """ Cancels the production order and related stock moves. @@ -659,6 +659,10 @@ class mrp_production(osv.osv): move_obj = self.pool.get('stock.move') self.write(cr, uid, ids, {'state': 'ready'}) + for production in self.browse(cr, uid, ids, context=context): + if not production.move_created_ids: + produce_move_id = self._make_production_produce_line(cr, uid, production, context=context) + for (production_id,name) in self.name_get(cr, uid, ids): production = self.browse(cr, uid, production_id) if production.move_prod_id and production.move_prod_id.location_id.id != production.location_dest_id.id: @@ -790,6 +794,7 @@ class mrp_production(osv.osv): stock_mov_obj.write(cr, uid, [raw_product.id], {'move_history_ids': [(4,new_parent_id)]}) wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce', cr) wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce_done', cr) return True @@ -849,9 +854,12 @@ class mrp_production(osv.osv): """ res = True for production in self.browse(cr, uid, ids): - if not production.product_lines: - if not self.action_compute(cr, uid, [production.id]): - res = False + boms = self.action_compute(cr, uid, [production.id]) + res = False + for bom in boms: + product = self.pool.get('product.product').browse(cr, uid, bom['product_id']) + if product.type in ('product', 'consu'): + res = True return res def _get_auto_picking(self, cr, uid, production): @@ -1005,11 +1013,13 @@ class mrp_production(osv.osv): 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,\ + if shipment_id: + 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) + 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) + if shipment_id: + wf_service.trg_validate(uid, 'stock.picking', shipment_id, 'button_confirm', cr) production.write({'state':'confirmed'}, context=context) return shipment_id From a0cb8675df27f9517c4c6e0e76a5c21e09b36dbb Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Wed, 11 Sep 2013 20:26:15 +0530 Subject: [PATCH 22/30] [IMP] Improved code bzr revid: psa@tinyerp.com-20130911145615-wzy1kmajr7j1731y --- addons/mrp/mrp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 9b6b3e28d28..377b90c4458 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -662,9 +662,9 @@ class mrp_production(osv.osv): for production in self.browse(cr, uid, ids, context=context): if not production.move_created_ids: produce_move_id = self._make_production_produce_line(cr, uid, production, context=context) - - for (production_id,name) in self.name_get(cr, uid, ids): - production = self.browse(cr, uid, production_id) + for scheduled in production.product_lines: + self._make_production_line_procurement(cr, uid, scheduled, False, context=context) + if production.move_prod_id and production.move_prod_id.location_id.id != production.location_dest_id.id: move_obj.write(cr, uid, [production.move_prod_id.id], {'location_id': production.location_dest_id.id}) From 8985dda5507d5ff371bb4c145d57fed46eccc184 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 12 Sep 2013 14:36:36 +0530 Subject: [PATCH 23/30] [IMP] Improved the test case to make the product produce. bzr revid: psa@tinyerp.com-20130912090636-h28zgcheleg9h9vm --- addons/mrp/test/bom_with_service_type_product.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/addons/mrp/test/bom_with_service_type_product.yml b/addons/mrp/test/bom_with_service_type_product.yml index d6fb35127a0..04e3520f272 100644 --- a/addons/mrp/test/bom_with_service_type_product.yml +++ b/addons/mrp/test/bom_with_service_type_product.yml @@ -51,6 +51,17 @@ assert order.state == 'in_production', 'Production order should be in production State.' for move_created in order.move_created_ids: move_created.action_done() +- + I produce product. +- + !python {model: mrp.product.produce}: | + context.update({'active_id': ref('mrp_production_servicetype_mo1')}) +- + !record {model: mrp.product.produce, id: mrp_product_produce_1}: + mode: 'consume_produce' +- + !python {model: mrp.product.produce}: | + self.do_produce(cr, uid, [ref('mrp_product_produce_1')], context=context) - I check production order after produced. - From 000ca6103da79b9df21701061f5cb3ef975e9355 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 12 Sep 2013 16:34:54 +0530 Subject: [PATCH 24/30] [IMP] Added another testcase for 2 service type product And improved code for bom product with service type product used in SO doesnt link the project perfectly. bzr revid: psa@tinyerp.com-20130912110454-x9tidij14xj09joz --- addons/mrp/mrp.py | 4 ++ .../test/bom_with_service_type_product.yml | 68 ++++++++++++++++++- addons/project_mrp/project_mrp.py | 11 +++ 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 377b90c4458..ff69a05441a 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -864,6 +864,9 @@ class mrp_production(osv.osv): def _get_auto_picking(self, cr, uid, production): return True + + def _hook_create_post_procurement(self, cr, uid, production, procurement_id, context=None): + return True def _make_production_line_procurement(self, cr, uid, production_line, shipment_move_id, context=None): wf_service = netsvc.LocalService("workflow") @@ -886,6 +889,7 @@ class mrp_production(osv.osv): 'move_id': shipment_move_id, 'company_id': production.company_id.id, }) + self._hook_create_post_procurement(cr, uid, production, procurement_id, context=context) wf_service.trg_validate(uid, procurement_order._name, procurement_id, 'button_confirm', cr) return procurement_id diff --git a/addons/mrp/test/bom_with_service_type_product.yml b/addons/mrp/test/bom_with_service_type_product.yml index 04e3520f272..dc434cabf73 100644 --- a/addons/mrp/test/bom_with_service_type_product.yml +++ b/addons/mrp/test/bom_with_service_type_product.yml @@ -28,8 +28,8 @@ I compute the data of production order. - !python {model: mrp.production}: | - self.action_compute(cr, uid, [ref("mrp_production_servicetype_mo1")], {"lang": "en_US", "tz": False, "search_default_Current": - 1, "active_model": "ir.ui.menu", "active_ids": [ref("mrp.menu_mrp_production_action")], + self.action_compute(cr, uid, [ref("mrp_production_servicetype_mo1")], {"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"), }) - I confirm the production order. @@ -68,3 +68,67 @@ !python {model: mrp.production}: | order = self.browse(cr, uid, ref("mrp_production_servicetype_mo1")) assert order.state == 'done', "Production order should be closed." +- + I create Bill of Materials with two service type products. +- + !record {model: mrp.bom, id: mrp_bom_test_2}: + company_id: base.main_company + name: PC Assemble SC234 + product_id: product.product_product_3 + product_qty: 1.0 + type: normal + bom_lines: + - company_id: base.main_company + name: On Site Monitoring + product_id: product.product_product_1 + product_qty: 1.0 + - company_id: base.main_company + name: On Site Assistance + product_id: product.product_product_2 + product_qty: 1.0 +- + I make the production order using BoM having two service type products. +- + !record {model: mrp.production, id: mrp_production_servicetype_2}: + product_id: product.product_product_5 + product_qty: 1.0 + bom_id: mrp_bom_test_2 + date_planned: !eval time.strftime('%Y-%m-%d %H:%M:%S') +- + I compute the data of production order. +- + !python {model: mrp.production}: | + self.action_compute(cr, uid, [ref("mrp_production_servicetype_2")], {"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"), }) +- + I confirm the production order. +- + !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_servicetype_2} +- + Now I start production. +- + !workflow {model: mrp.production, action: button_produce, ref: mrp_production_servicetype_2} +- + I check that production order in production state after start production. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_servicetype_2")) + assert order.state == 'in_production', 'Production order should be in production State.' +- + I produce product. +- + !python {model: mrp.product.produce}: | + context.update({'active_id': ref('mrp_production_servicetype_2')}) +- + !record {model: mrp.product.produce, id: mrp_product_produce_2}: + mode: 'consume_produce' +- + !python {model: mrp.product.produce}: | + self.do_produce(cr, uid, [ref('mrp_product_produce_2')], context=context) +- + I check production order after produced. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_servicetype_2")) + assert order.state == 'done', "Production order should be closed." diff --git a/addons/project_mrp/project_mrp.py b/addons/project_mrp/project_mrp.py index a6f0495a962..843d4649655 100644 --- a/addons/project_mrp/project_mrp.py +++ b/addons/project_mrp/project_mrp.py @@ -109,4 +109,15 @@ class sale_order(osv.osv): } sale_order() + +class mrp_production(osv.osv): + _inherit = 'mrp.production' + + def _hook_create_post_procurement(self, cr, uid, production, procurement_id, context=None): + res = super(mrp_production, self)._hook_create_post_procurement(cr, uid, production, procurement_id, context) + procurement_order = self.pool.get('procurement.order') + procurement_order.write(cr, uid, procurement_id, {'sale_line_id': production.move_prod_id and production.move_prod_id.sale_line_id and production.move_prod_id.sale_line_id.id}) + return procurement_id + +mrp_production() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 387bffe50e75de3b827e081ea3d2badce0086e81 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 12 Sep 2013 17:25:56 +0530 Subject: [PATCH 25/30] [IMP] Divided the action_compute method and improved code according to that. bzr revid: psa@tinyerp.com-20130912115556-9c67dzpr6mao251w --- addons/mrp/mrp.py | 85 ++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index ff69a05441a..c7b4225b2a8 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -591,48 +591,63 @@ class mrp_production(osv.osv): """ self.write(cr, uid, ids, {'state': 'picking_except'}) return True + + def _compute(self, cr, uid, production, properties=None, context=None): + if properties is None: + properties = [] + + bom_obj = self.pool.get('mrp.bom') + uom_obj = self.pool.get('product.uom') + prod_line_obj = self.pool.get('mrp.production.product.line') + workcenter_line_obj = self.pool.get('mrp.production.workcenter.line') + + #unlink product lines + p_ids = map(lambda x:x.id, production.product_lines) + prod_line_obj.unlink(cr, SUPERUSER_ID, p_ids, context=context) + + #unlink workcenter lines + w_ids = map(lambda x:x.id, production.workcenter_lines) + workcenter_line_obj.unlink(cr, SUPERUSER_ID, w_ids, context=context) + + # search BoM structure and route + bom_point = production.bom_id + bom_id = production.bom_id.id + if not bom_point: + bom_id = bom_obj._bom_find(cr, uid, production.product_id.id, production.product_uom.id, properties) + if bom_id: + bom_point = bom_obj.browse(cr, uid, bom_id) + routing_id = bom_point.routing_id.id or False + self.write(cr, uid, [production.id], {'bom_id': bom_id, 'routing_id': routing_id}) + + if not bom_id: + raise osv.except_osv(_('Error!'), _("Cannot find a bill of material for this product.")) + + # get components and workcenter from BoM structure + factor = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, bom_point.product_uom.id) + res = bom_obj._bom_explode(cr, uid, bom_point, factor / bom_point.product_qty, properties, routing_id=production.routing_id.id) + results = res[0] # product lines + results2 = res[1] # workcenters lines + + # reset product lines in production order + for line in results: + line['production_id'] = production.id + prod_line_obj.create(cr, uid, line) + + #reset workcenter lines in production order + for line in results2: + line['production_id'] = production.id + workcenter_line_obj.create(cr, uid, line) + return results def action_compute(self, cr, uid, ids, properties=None, context=None): """ Computes bills of material of a product. @param properties: List containing dictionaries of properties. @return: No. of products. """ - if properties is None: - properties = [] results = [] - bom_obj = self.pool.get('mrp.bom') - uom_obj = self.pool.get('product.uom') - prod_line_obj = self.pool.get('mrp.production.product.line') - workcenter_line_obj = self.pool.get('mrp.production.workcenter.line') for production in self.browse(cr, uid, ids): - - p_ids = prod_line_obj.search(cr, SUPERUSER_ID, [('production_id', '=', production.id)], context=context) - prod_line_obj.unlink(cr, SUPERUSER_ID, p_ids, context=context) - w_ids = workcenter_line_obj.search(cr, SUPERUSER_ID, [('production_id', '=', production.id)], context=context) - workcenter_line_obj.unlink(cr, SUPERUSER_ID, w_ids, context=context) - - bom_point = production.bom_id - bom_id = production.bom_id.id - if not bom_point: - bom_id = bom_obj._bom_find(cr, uid, production.product_id.id, production.product_uom.id, properties) - if bom_id: - bom_point = bom_obj.browse(cr, uid, bom_id) - routing_id = bom_point.routing_id.id or False - self.write(cr, uid, [production.id], {'bom_id': bom_id, 'routing_id': routing_id}) - - if not bom_id: - raise osv.except_osv(_('Error!'), _("Cannot find a bill of material for this product.")) - factor = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, bom_point.product_uom.id) - res = bom_obj._bom_explode(cr, uid, bom_point, factor / bom_point.product_qty, properties, routing_id=production.routing_id.id) - results = res[0] - results2 = res[1] - for line in results: - line['production_id'] = production.id - prod_line_obj.create(cr, uid, line) - for line in results2: - line['production_id'] = production.id - workcenter_line_obj.create(cr, uid, line) - return results + results = self._compute(cr, uid, production, properties=properties, context=context) + return len(results) def action_cancel(self, cr, uid, ids, context=None): """ Cancels the production order and related stock moves. @@ -854,7 +869,7 @@ class mrp_production(osv.osv): """ res = True for production in self.browse(cr, uid, ids): - boms = self.action_compute(cr, uid, [production.id]) + boms = self._compute(cr, uid, production) res = False for bom in boms: product = self.pool.get('product.product').browse(cr, uid, bom['product_id']) From 8825f2070b1c8d9da30814e9496feb938b56350a Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 12 Sep 2013 18:44:34 +0530 Subject: [PATCH 26/30] [IMP] Improved method name and code accordingly. bzr revid: psa@tinyerp.com-20130912131434-99xv1prw3o4dy9ge --- addons/mrp/mrp.py | 95 +++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index c7b4225b2a8..e5f676167f4 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -592,62 +592,69 @@ class mrp_production(osv.osv): self.write(cr, uid, ids, {'state': 'picking_except'}) return True - def _compute(self, cr, uid, production, properties=None, context=None): + def _action_compute_lines(self, cr, uid, ids, properties=None, context=None): + """ Compute product_lines and workcenter_lines from BoM structure + @return dict: product_lines + """ + if properties is None: properties = [] - + res_product_lines = {} bom_obj = self.pool.get('mrp.bom') uom_obj = self.pool.get('product.uom') prod_line_obj = self.pool.get('mrp.production.product.line') workcenter_line_obj = self.pool.get('mrp.production.workcenter.line') - #unlink product lines - p_ids = map(lambda x:x.id, production.product_lines) - prod_line_obj.unlink(cr, SUPERUSER_ID, p_ids, context=context) - - #unlink workcenter lines - w_ids = map(lambda x:x.id, production.workcenter_lines) - workcenter_line_obj.unlink(cr, SUPERUSER_ID, w_ids, context=context) - - # search BoM structure and route - bom_point = production.bom_id - bom_id = production.bom_id.id - if not bom_point: - bom_id = bom_obj._bom_find(cr, uid, production.product_id.id, production.product_uom.id, properties) - if bom_id: - bom_point = bom_obj.browse(cr, uid, bom_id) - routing_id = bom_point.routing_id.id or False - self.write(cr, uid, [production.id], {'bom_id': bom_id, 'routing_id': routing_id}) - - if not bom_id: - raise osv.except_osv(_('Error!'), _("Cannot find a bill of material for this product.")) - - # get components and workcenter from BoM structure - factor = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, bom_point.product_uom.id) - res = bom_obj._bom_explode(cr, uid, bom_point, factor / bom_point.product_qty, properties, routing_id=production.routing_id.id) - results = res[0] # product lines - results2 = res[1] # workcenters lines - - # reset product lines in production order - for line in results: - line['production_id'] = production.id - prod_line_obj.create(cr, uid, line) - - #reset workcenter lines in production order - for line in results2: - line['production_id'] = production.id - workcenter_line_obj.create(cr, uid, line) - return results + for production in self.browse(cr, uid, ids, context=context): + #unlink product_lines + p_ids = map(lambda x:x.id, production.product_lines) + prod_line_obj.unlink(cr, SUPERUSER_ID, p_ids, context=context) + + #unlink workcenter_lines + w_ids = map(lambda x:x.id, production.workcenter_lines) + workcenter_line_obj.unlink(cr, SUPERUSER_ID, w_ids, context=context) + + # search BoM structure and route + bom_point = production.bom_id + bom_id = production.bom_id.id + if not bom_point: + bom_id = bom_obj._bom_find(cr, uid, production.product_id.id, production.product_uom.id, properties) + if bom_id: + bom_point = bom_obj.browse(cr, uid, bom_id) + routing_id = bom_point.routing_id.id or False + self.write(cr, uid, [production.id], {'bom_id': bom_id, 'routing_id': routing_id}) + + if not bom_id: + raise osv.except_osv(_('Error!'), _("Cannot find a bill of material for this product.")) + + # get components and workcenter_lines from BoM structure + factor = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, bom_point.product_uom.id) + res = bom_obj._bom_explode(cr, uid, bom_point, factor / bom_point.product_qty, properties, routing_id=production.routing_id.id) + results = res[0] # product_lines + results2 = res[1] # workcenter_lines + + # reset product_lines in production order + for line in results: + line['production_id'] = production.id + prod_line_obj.create(cr, uid, line) + + #reset workcenter_lines in production order + for line in results2: + line['production_id'] = production.id + workcenter_line_obj.create(cr, uid, line) + res_product_lines[production.id] = results + return res_product_lines def action_compute(self, cr, uid, ids, properties=None, context=None): """ Computes bills of material of a product. @param properties: List containing dictionaries of properties. @return: No. of products. """ - results = [] - for production in self.browse(cr, uid, ids): - results = self._compute(cr, uid, production, properties=properties, context=context) - return len(results) + production_id = ids and ids[0] or False + res = False + if production_id: + res = len(self._action_compute_lines(cr, uid, [production_id], properties=properties, context=context)[production_id]) + return res def action_cancel(self, cr, uid, ids, context=None): """ Cancels the production order and related stock moves. @@ -869,7 +876,7 @@ class mrp_production(osv.osv): """ res = True for production in self.browse(cr, uid, ids): - boms = self._compute(cr, uid, production) + boms = self._action_compute_lines(cr, uid, [production.id])[production.id] res = False for bom in boms: product = self.pool.get('product.product').browse(cr, uid, bom['product_id']) From 2b65bbfa82e1d30c00252963f1d6e6f6d473e739 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 12 Sep 2013 19:24:45 +0530 Subject: [PATCH 27/30] [IMP] Improved code to return product_lines. bzr revid: psa@tinyerp.com-20130912135445-xf0rmbh117fznd5v --- addons/mrp/mrp.py | 19 +++++++------------ addons/project_mrp/project_mrp.py | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index e5f676167f4..0239c30c270 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -594,12 +594,12 @@ class mrp_production(osv.osv): def _action_compute_lines(self, cr, uid, ids, properties=None, context=None): """ Compute product_lines and workcenter_lines from BoM structure - @return dict: product_lines + @return: product_lines """ if properties is None: properties = [] - res_product_lines = {} + results = [] bom_obj = self.pool.get('mrp.bom') uom_obj = self.pool.get('product.uom') prod_line_obj = self.pool.get('mrp.production.product.line') @@ -607,11 +607,11 @@ class mrp_production(osv.osv): for production in self.browse(cr, uid, ids, context=context): #unlink product_lines - p_ids = map(lambda x:x.id, production.product_lines) + p_ids = [line.id for line in production.product_lines] prod_line_obj.unlink(cr, SUPERUSER_ID, p_ids, context=context) #unlink workcenter_lines - w_ids = map(lambda x:x.id, production.workcenter_lines) + w_ids = [line.id for line in production.workcenter_lines] workcenter_line_obj.unlink(cr, SUPERUSER_ID, w_ids, context=context) # search BoM structure and route @@ -642,19 +642,14 @@ class mrp_production(osv.osv): for line in results2: line['production_id'] = production.id workcenter_line_obj.create(cr, uid, line) - res_product_lines[production.id] = results - return res_product_lines + return results def action_compute(self, cr, uid, ids, properties=None, context=None): """ Computes bills of material of a product. @param properties: List containing dictionaries of properties. @return: No. of products. """ - production_id = ids and ids[0] or False - res = False - if production_id: - res = len(self._action_compute_lines(cr, uid, [production_id], properties=properties, context=context)[production_id]) - return res + return len(self._action_compute_lines(cr, uid, ids, properties=properties, context=context)) def action_cancel(self, cr, uid, ids, context=None): """ Cancels the production order and related stock moves. @@ -876,7 +871,7 @@ class mrp_production(osv.osv): """ res = True for production in self.browse(cr, uid, ids): - boms = self._action_compute_lines(cr, uid, [production.id])[production.id] + boms = self._action_compute_lines(cr, uid, [production.id]) res = False for bom in boms: product = self.pool.get('product.product').browse(cr, uid, bom['product_id']) diff --git a/addons/project_mrp/project_mrp.py b/addons/project_mrp/project_mrp.py index 843d4649655..d2da3936a8e 100644 --- a/addons/project_mrp/project_mrp.py +++ b/addons/project_mrp/project_mrp.py @@ -117,7 +117,7 @@ class mrp_production(osv.osv): res = super(mrp_production, self)._hook_create_post_procurement(cr, uid, production, procurement_id, context) procurement_order = self.pool.get('procurement.order') procurement_order.write(cr, uid, procurement_id, {'sale_line_id': production.move_prod_id and production.move_prod_id.sale_line_id and production.move_prod_id.sale_line_id.id}) - return procurement_id + return res mrp_production() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From ba1ee5bc87dcd64de4360e245dbc392f33fabed5 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 13 Sep 2013 19:00:08 +0530 Subject: [PATCH 28/30] [IMP]Improved code for multiple bom. bzr revid: psa@tinyerp.com-20130913133008-z1k76sq6jkvu8e6i --- addons/project_mrp/project_mrp.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/project_mrp/project_mrp.py b/addons/project_mrp/project_mrp.py index d2da3936a8e..85affcb3759 100644 --- a/addons/project_mrp/project_mrp.py +++ b/addons/project_mrp/project_mrp.py @@ -114,9 +114,17 @@ class mrp_production(osv.osv): _inherit = 'mrp.production' def _hook_create_post_procurement(self, cr, uid, production, procurement_id, context=None): + def get_parent_move(move): + if move.move_dest_id: + return get_parent_move(move.move_dest_id) + return move + res = super(mrp_production, self)._hook_create_post_procurement(cr, uid, production, procurement_id, context) procurement_order = self.pool.get('procurement.order') - procurement_order.write(cr, uid, procurement_id, {'sale_line_id': production.move_prod_id and production.move_prod_id.sale_line_id and production.move_prod_id.sale_line_id.id}) + if production.move_prod_id: + parent_move_line = get_parent_move(production.move_prod_id) + if parent_move_line and parent_move_line.sale_line_id: + procurement_order.write(cr, uid, procurement_id, {'sale_line_id': parent_move_line.sale_line_id.id}) return res mrp_production() From 7485ec46d76933084aa50ce4203ace9568c973fc Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 16 Sep 2013 11:46:04 +0200 Subject: [PATCH 29/30] [IMP] mrp: trigger workflow only if no move lines bzr revid: mat@openerp.com-20130916094604-zonoyxeic948mjn2 --- addons/mrp/mrp.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 0239c30c270..dfa01658cd4 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -733,6 +733,10 @@ class mrp_production(osv.osv): stock_mov_obj = self.pool.get('stock.move') production = self.browse(cr, uid, production_id, context=context) + wf_service = netsvc.LocalService("workflow") + if not production.move_lines: + wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce', cr) + produced_qty = 0 for produced_product in production.move_created_ids2: if (produced_product.scrapped) or (produced_product.product_id.id != production.product_id.id): @@ -810,8 +814,6 @@ class mrp_production(osv.osv): for new_parent_id in new_parent_ids: stock_mov_obj.write(cr, uid, [raw_product.id], {'move_history_ids': [(4,new_parent_id)]}) - wf_service = netsvc.LocalService("workflow") - wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce', cr) wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce_done', cr) return True From 503f69cba38f91b7940f1918c7f7f6f394cc1ad9 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 16 Sep 2013 12:01:20 +0200 Subject: [PATCH 30/30] [IMP] project_mrp: cleaning and add condition for triggering signal bzr revid: mat@openerp.com-20130916100120-kuuyofh3o8e3iv8c --- addons/mrp/mrp.py | 3 ++- addons/project_mrp/project_mrp.py | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index dfa01658cd4..3a606405cc4 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -734,7 +734,8 @@ class mrp_production(osv.osv): production = self.browse(cr, uid, production_id, context=context) wf_service = netsvc.LocalService("workflow") - if not production.move_lines: + if not production.move_lines and production.state == 'ready': + # trigger workflow if not products to consume (eg: services) wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce', cr) produced_qty = 0 diff --git a/addons/project_mrp/project_mrp.py b/addons/project_mrp/project_mrp.py index 85affcb3759..39adba6c4c6 100644 --- a/addons/project_mrp/project_mrp.py +++ b/addons/project_mrp/project_mrp.py @@ -120,11 +120,10 @@ class mrp_production(osv.osv): return move res = super(mrp_production, self)._hook_create_post_procurement(cr, uid, production, procurement_id, context) - procurement_order = self.pool.get('procurement.order') if production.move_prod_id: parent_move_line = get_parent_move(production.move_prod_id) if parent_move_line and parent_move_line.sale_line_id: - procurement_order.write(cr, uid, procurement_id, {'sale_line_id': parent_move_line.sale_line_id.id}) + self.pool.get('procurement.order').write(cr, uid, procurement_id, {'sale_line_id': parent_move_line.sale_line_id.id}) return res mrp_production()