From 4ee5b4bedae693d4c9e338b0f9a53b540cff9441 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Wed, 24 Aug 2011 13:31:51 +0530 Subject: [PATCH 1/9] [FIX] mrp_repair:Hardcoded stock name location in mrp_repair are removed lp bug: https://launchpad.net/bugs/831543 fixed bzr revid: aag@tinyerp.com-20110824080151-3hnce2cgz6600gy8 --- addons/mrp_repair/mrp_repair.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/addons/mrp_repair/mrp_repair.py b/addons/mrp_repair/mrp_repair.py index 3a538590d10..548c95ffa1c 100644 --- a/addons/mrp_repair/mrp_repair.py +++ b/addons/mrp_repair/mrp_repair.py @@ -699,7 +699,7 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): } } - product_id = self.pool.get('stock.location').search(cr, uid, [('name','=','Production')])[0] + product_id = self.pool.get('stock.location').search(cr, uid, [('usage','=','production')])[0] if type != 'add': return {'value': { 'to_invoice': False, @@ -707,15 +707,16 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): 'location_dest_id': False } } - - stock_id = self.pool.get('stock.location').search(cr, uid, [('name','=','Stock')])[0] - to_invoice = (guarantee_limit and - datetime.strptime(guarantee_limit, '%Y-%m-%d') < datetime.now()) - return {'value': { - 'to_invoice': to_invoice, - 'location_id': stock_id, - 'location_dest_id': product_id - } + + if ids: + stock_id = self.browse(cr, uid, ids[0]).repair_id.company_id.partner_id.property_stock_customer.id + to_invoice = (guarantee_limit and + datetime.strptime(guarantee_limit, '%Y-%m-%d') < datetime.now()) + return {'value': { + 'to_invoice': to_invoice, + 'location_id': stock_id, + 'location_dest_id': product_id + } } mrp_repair_line() From 873b0b206ecdcda9fdc4b06ea137597989992251 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Mon, 29 Aug 2011 15:03:08 +0530 Subject: [PATCH 2/9] [FIX] mrp_repair:Hardcoded stock name location in mrp_repair are removed lp bug: https://launchpad.net/bugs/831543 fixed bzr revid: aag@tinyerp.com-20110829093308-zy30ntoek58l1oyl --- addons/mrp_repair/mrp_repair.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/mrp_repair/mrp_repair.py b/addons/mrp_repair/mrp_repair.py index 548c95ffa1c..ad7d1f993c5 100644 --- a/addons/mrp_repair/mrp_repair.py +++ b/addons/mrp_repair/mrp_repair.py @@ -692,6 +692,7 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): @param guarantee_limit: Guarantee limit of current record. @return: Dictionary of values. """ + wrehouse_obj = self.pool.get('stock.warehouse') if not type: return {'value': { 'location_id': False, @@ -709,7 +710,8 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): } if ids: - stock_id = self.browse(cr, uid, ids[0]).repair_id.company_id.partner_id.property_stock_customer.id + company_id = self.browse(cr, uid, ids[0]).repair_id.company_id.id + stock_id = wrehouse_obj.browse(cr, uid, company_id).lot_input_id.id to_invoice = (guarantee_limit and datetime.strptime(guarantee_limit, '%Y-%m-%d') < datetime.now()) return {'value': { From fd04c0d7fcdb7e6ab6336d336452fc09b9424362 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Tue, 30 Aug 2011 10:35:19 +0530 Subject: [PATCH 3/9] [IMP] mrp_repair:Rename stock.warehouse object name bzr revid: aag@tinyerp.com-20110830050519-zlmhksehjub57qto --- addons/mrp_repair/mrp_repair.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mrp_repair/mrp_repair.py b/addons/mrp_repair/mrp_repair.py index ad7d1f993c5..6f326a0a483 100644 --- a/addons/mrp_repair/mrp_repair.py +++ b/addons/mrp_repair/mrp_repair.py @@ -692,7 +692,7 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): @param guarantee_limit: Guarantee limit of current record. @return: Dictionary of values. """ - wrehouse_obj = self.pool.get('stock.warehouse') + warehouse_obj = self.pool.get('stock.warehouse') if not type: return {'value': { 'location_id': False, @@ -711,7 +711,7 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): if ids: company_id = self.browse(cr, uid, ids[0]).repair_id.company_id.id - stock_id = wrehouse_obj.browse(cr, uid, company_id).lot_input_id.id + stock_id = warehouse_obj.browse(cr, uid, company_id).lot_input_id.id to_invoice = (guarantee_limit and datetime.strptime(guarantee_limit, '%Y-%m-%d') < datetime.now()) return {'value': { From f6f09e06edb881812ef42eed8007503efa70761c Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Tue, 30 Aug 2011 10:40:58 +0530 Subject: [PATCH 4/9] [IMP] mrp_repair:ADD context in browse method bzr revid: aag@tinyerp.com-20110830051058-4klmhdcsdkucf0aj --- addons/mrp_repair/mrp_repair.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mrp_repair/mrp_repair.py b/addons/mrp_repair/mrp_repair.py index 6f326a0a483..0c8334421da 100644 --- a/addons/mrp_repair/mrp_repair.py +++ b/addons/mrp_repair/mrp_repair.py @@ -710,8 +710,8 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): } if ids: - company_id = self.browse(cr, uid, ids[0]).repair_id.company_id.id - stock_id = warehouse_obj.browse(cr, uid, company_id).lot_input_id.id + company_id = self.browse(cr, uid, ids[0], context=context).repair_id.company_id.id + stock_id = warehouse_obj.browse(cr, uid, company_id, context=context).lot_input_id.id to_invoice = (guarantee_limit and datetime.strptime(guarantee_limit, '%Y-%m-%d') < datetime.now()) return {'value': { From c6fe5c3502e50592dd83290c68431e4f45f3517b Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Tue, 30 Aug 2011 10:43:56 +0530 Subject: [PATCH 5/9] [IMP] mrp_repair:ADD context in method bzr revid: aag@tinyerp.com-20110830051356-vi5icqt04n99mf98 --- addons/mrp_repair/mrp_repair.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/mrp_repair/mrp_repair.py b/addons/mrp_repair/mrp_repair.py index 0c8334421da..c23f868f370 100644 --- a/addons/mrp_repair/mrp_repair.py +++ b/addons/mrp_repair/mrp_repair.py @@ -685,13 +685,15 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): 'product_uom_qty': lambda *a: 1, } - def onchange_operation_type(self, cr, uid, ids, type, guarantee_limit): + def onchange_operation_type(self, cr, uid, ids, type, guarantee_limit, context = None): """ On change of operation type it sets source location, destination location and to invoice field. @param product: Changed operation type. @param guarantee_limit: Guarantee limit of current record. @return: Dictionary of values. """ + if context is None: + context = {} warehouse_obj = self.pool.get('stock.warehouse') if not type: return {'value': { @@ -700,7 +702,7 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): } } - product_id = self.pool.get('stock.location').search(cr, uid, [('usage','=','production')])[0] + product_id = self.pool.get('stock.location').search(cr, uid, [('usage','=','production')], context=context)[0] if type != 'add': return {'value': { 'to_invoice': False, From cf21a70172907eee6adbbfcbfc04526f9f38039c Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Tue, 30 Aug 2011 12:03:50 +0530 Subject: [PATCH 6/9] [IMP] mrp_repair:Find production location company wise bzr revid: aag@tinyerp.com-20110830063350-94xgxlg2znm2lu29 --- addons/mrp_repair/mrp_repair.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/addons/mrp_repair/mrp_repair.py b/addons/mrp_repair/mrp_repair.py index c23f868f370..153f36c32bd 100644 --- a/addons/mrp_repair/mrp_repair.py +++ b/addons/mrp_repair/mrp_repair.py @@ -695,31 +695,33 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): if context is None: context = {} warehouse_obj = self.pool.get('stock.warehouse') + location_obj = self.pool.get('stock.location') if not type: return {'value': { 'location_id': False, 'location_dest_id': False } } - - product_id = self.pool.get('stock.location').search(cr, uid, [('usage','=','production')], context=context)[0] - if type != 'add': - return {'value': { - 'to_invoice': False, - 'location_id': product_id, - 'location_dest_id': False - } - } if ids: company_id = self.browse(cr, uid, ids[0], context=context).repair_id.company_id.id + product_id = location_obj.search(cr, uid, [('usage','=','production'), ('company_id','=',company_id)], context=context) + if not product_id: + product_id = location_obj.search(cr, uid, [('usage','=','production')], context=context) + if type != 'add': + return {'value': { + 'to_invoice': False, + 'location_id': product_id[0], + 'location_dest_id': False + } + } stock_id = warehouse_obj.browse(cr, uid, company_id, context=context).lot_input_id.id to_invoice = (guarantee_limit and datetime.strptime(guarantee_limit, '%Y-%m-%d') < datetime.now()) return {'value': { 'to_invoice': to_invoice, 'location_id': stock_id, - 'location_dest_id': product_id + 'location_dest_id': product_id[0] } } From cc5c8a71330993540d43385dff74e2ce40c6d36f Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Mon, 5 Sep 2011 14:56:44 +0530 Subject: [PATCH 7/9] [IMP] mrp_repair:optimize code bzr revid: aag@tinyerp.com-20110905092644-86ph50nywnv1eoev --- addons/mrp_repair/mrp_repair.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/mrp_repair/mrp_repair.py b/addons/mrp_repair/mrp_repair.py index 153f36c32bd..026ceb51104 100644 --- a/addons/mrp_repair/mrp_repair.py +++ b/addons/mrp_repair/mrp_repair.py @@ -706,12 +706,15 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): if ids: company_id = self.browse(cr, uid, ids[0], context=context).repair_id.company_id.id product_id = location_obj.search(cr, uid, [('usage','=','production'), ('company_id','=',company_id)], context=context) - if not product_id: - product_id = location_obj.search(cr, uid, [('usage','=','production')], context=context) + if product_id: + product_id = product_id[0] + else: + product_id = False + if type != 'add': return {'value': { 'to_invoice': False, - 'location_id': product_id[0], + 'location_id': product_id, 'location_dest_id': False } } @@ -721,7 +724,7 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): return {'value': { 'to_invoice': to_invoice, 'location_id': stock_id, - 'location_dest_id': product_id[0] + 'location_dest_id': product_id } } From e133c408cb2e79e65c3d58cabeb5ea75c6c29f9c Mon Sep 17 00:00:00 2001 From: "Rucha (Open ERP)" Date: Wed, 21 Sep 2011 11:09:53 +0530 Subject: [PATCH 8/9] [FIX, REF]: mrp_repair: Improvement in code and logic of onchange type of repair line to fix the problem of hard coded location name in search bzr revid: rpa@tinyerp.com-20110921053953-gwcq1k72bln0ue7s --- addons/mrp_repair/mrp_repair.py | 53 +++++++++++++++------------------ 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/addons/mrp_repair/mrp_repair.py b/addons/mrp_repair/mrp_repair.py index 026ceb51104..32ea609fd14 100644 --- a/addons/mrp_repair/mrp_repair.py +++ b/addons/mrp_repair/mrp_repair.py @@ -685,48 +685,43 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): 'product_uom_qty': lambda *a: 1, } - def onchange_operation_type(self, cr, uid, ids, type, guarantee_limit, context = None): + def onchange_operation_type(self, cr, uid, ids, type, guarantee_limit, context=None): """ On change of operation type it sets source location, destination location and to invoice field. @param product: Changed operation type. @param guarantee_limit: Guarantee limit of current record. @return: Dictionary of values. """ - if context is None: - context = {} - warehouse_obj = self.pool.get('stock.warehouse') - location_obj = self.pool.get('stock.location') if not type: return {'value': { 'location_id': False, 'location_dest_id': False - } - } - - if ids: - company_id = self.browse(cr, uid, ids[0], context=context).repair_id.company_id.id - product_id = location_obj.search(cr, uid, [('usage','=','production'), ('company_id','=',company_id)], context=context) - if product_id: - product_id = product_id[0] - else: - product_id = False - - if type != 'add': - return {'value': { - 'to_invoice': False, - 'location_id': product_id, - 'location_dest_id': False - } - } - stock_id = warehouse_obj.browse(cr, uid, company_id, context=context).lot_input_id.id - to_invoice = (guarantee_limit and - datetime.strptime(guarantee_limit, '%Y-%m-%d') < datetime.now()) + }} + + warehouse_obj = self.pool.get('stock.warehouse') + location_id = self.pool.get('stock.location').search(cr, uid, [('usage','=','production')], context=context) + location_id = location_id and location_id[0] or False + + if type == 'add': + # TOCHECK: Find stock location for user's company warehouse or + # repair order's company's warehouse (company_id field is added in fix of lp:831583) + company_id = self.pool.get('res.company')._company_default_get(cr, uid, 'mrp.repair', context=context) + warehouse_ids = warehouse_obj.search(cr, uid, [], context=context) + if warehouse_ids: + stock_id = warehouse_obj.browse(cr, uid, warehouse_ids[0], context=context).lot_stock_id.id + to_invoice = (guarantee_limit and datetime.strptime(guarantee_limit, '%Y-%m-%d') < datetime.now()) + return {'value': { 'to_invoice': to_invoice, 'location_id': stock_id, - 'location_dest_id': product_id - } - } + 'location_dest_id': location_id + }} + + return {'value': { + 'to_invoice': False, + 'location_id': location_id, + 'location_dest_id': False + }} mrp_repair_line() From a6074e08d5c047d451d8b865c5b24634376fd122 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Wed, 19 Oct 2011 16:19:57 +0530 Subject: [PATCH 9/9] [IMP] mrp_repair:use company wise warehouse id bzr revid: aag@tinyerp.com-20111019104957-q9mqc8g9bwyve5tw --- addons/mrp_repair/mrp_repair.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/mrp_repair/mrp_repair.py b/addons/mrp_repair/mrp_repair.py index f8d77ea8224..023c91a54b0 100644 --- a/addons/mrp_repair/mrp_repair.py +++ b/addons/mrp_repair/mrp_repair.py @@ -686,11 +686,12 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): # TOCHECK: Find stock location for user's company warehouse or # repair order's company's warehouse (company_id field is added in fix of lp:831583) company_id = self.pool.get('res.company')._company_default_get(cr, uid, 'mrp.repair', context=context) - warehouse_ids = warehouse_obj.search(cr, uid, [], context=context) + warehouse_ids = warehouse_obj.search(cr, uid, [('company_id','=',company_id)], context=context) + stock_id = False if warehouse_ids: stock_id = warehouse_obj.browse(cr, uid, warehouse_ids[0], context=context).lot_stock_id.id to_invoice = (guarantee_limit and datetime.strptime(guarantee_limit, '%Y-%m-%d') < datetime.now()) - + return {'value': { 'to_invoice': to_invoice, 'location_id': stock_id,