From 1dfef2f2af70c0fe6a76a6692ae4e518dde1f0e0 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 29 Nov 2012 12:18:56 +0530 Subject: [PATCH 01/16] [IMP]Improved code for label, make start date and end date invisible and make size of textbox same as others. bzr revid: psa@tinyerp.com-20121129064856-r1bfgsyevcstcw06 --- addons/mrp/mrp_view.xml | 4 ++-- addons/mrp_operations/mrp_operations_view.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index 2ed442b1831..1969e2ee5e3 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -784,8 +784,8 @@ - - + + diff --git a/addons/mrp_operations/mrp_operations_view.xml b/addons/mrp_operations/mrp_operations_view.xml index a16a9b23f0a..baa1b3bb130 100644 --- a/addons/mrp_operations/mrp_operations_view.xml +++ b/addons/mrp_operations/mrp_operations_view.xml @@ -74,7 +74,7 @@ - + @@ -92,7 +92,7 @@ - + From b4718f0d635e4132f093406e3ac25b9b595170a5 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 29 Nov 2012 14:05:32 +0530 Subject: [PATCH 02/16] [IMP] Changed the label Production Order to Manufacturing Order. bzr revid: psa@tinyerp.com-20121129083532-3dxabfq05x8a1jln --- 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 6a708b7cc64..72ba2dc9c7f 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -1084,7 +1084,7 @@ class mrp_production_workcenter_line(osv.osv): 'cycle': fields.float('Number of Cycles', digits=(16,2)), 'hour': fields.float('Number of Hours', digits=(16,2)), 'sequence': fields.integer('Sequence', required=True, help="Gives the sequence order when displaying a list of work orders."), - 'production_id': fields.many2one('mrp.production', 'Production Order', select=True, ondelete='cascade', required=True), + 'production_id': fields.many2one('mrp.production', 'Manufacturing Order', select=True, ondelete='cascade', required=True), } _defaults = { 'sequence': lambda *a: 1, From 8ad111af910ac8d78ef023e0dcdf86fe2b61bd90 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 29 Nov 2012 14:09:22 +0530 Subject: [PATCH 03/16] [IMP]Improved code for Production Status field should show Draft before saving. bzr revid: psa@tinyerp.com-20121129083922-ptdosthtbrilfunj --- addons/mrp_operations/mrp_operations.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index 4bca93d260f..ef24f6c187f 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -98,7 +98,8 @@ class mrp_production_workcenter_line(osv.osv): _defaults = { 'state': lambda *a: 'draft', - 'delay': lambda *a: 0.0 + 'delay': lambda *a: 0.0, + 'production_state': 'draft' } def modify_production_order_state(self, cr, uid, ids, action): From 852bbeaa01534f740d57599938232f909ae495b7 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 30 Nov 2012 15:04:40 +0530 Subject: [PATCH 04/16] [IMP] Added code for onchange schedule date. bzr revid: psa@tinyerp.com-20121130093440-t8bvs5fl7z7kot10 --- addons/mrp_operations/mrp_operations.py | 12 ++++++++++++ addons/mrp_operations/mrp_operations_view.xml | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index ef24f6c187f..3f71777a66f 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -70,6 +70,18 @@ class mrp_production_workcenter_line(osv.osv): else: res[op.id] = op.date_planned return res + + def onchange_get_date_end(self, cr, uid, ids, date_planned,cycle,hour, context=None): + """ Finds ending date from schedule date's onchange. + """ + date_and_hours_by_cal = [(date_planned,hour, 1)] + intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) + i = intervals.get((date_planned,hour, 1)) + if i: + res = i[-1][1].strftime('%Y-%m-%d %H:%M:%S') + else: + res = date_planned + return {'value':{'date_planned_end': res}} _inherit = 'mrp.production.workcenter.line' _order = "sequence, date_planned" diff --git a/addons/mrp_operations/mrp_operations_view.xml b/addons/mrp_operations/mrp_operations_view.xml index baa1b3bb130..ecd04f13292 100644 --- a/addons/mrp_operations/mrp_operations_view.xml +++ b/addons/mrp_operations/mrp_operations_view.xml @@ -84,7 +84,7 @@ - + From 28a17a63fe530053cef3a812ff3c2b77a37fc6a3 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 30 Nov 2012 16:54:34 +0530 Subject: [PATCH 05/16] [IMP] Added code for the onchange Product to Produce: Product field + Quantity field + Unit of Measure field should be filled automatically via onchange if you created/selected a Manufacturing Order before saving bzr revid: psa@tinyerp.com-20121130112434-ajfuq8h0f5u21qyy --- addons/mrp_operations/mrp_operations.py | 13 +++++++++++++ addons/mrp_operations/mrp_operations_view.xml | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index 3f71777a66f..1facec60a50 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -83,6 +83,19 @@ class mrp_production_workcenter_line(osv.osv): res = date_planned return {'value':{'date_planned_end': res}} + def onchange_production_id(self, cr, uid, ids, production_id, context=None): + """ Finds UoM of changed product. + @param product_id: Id of changed product. + @return: Dictionary of values. + """ + products = self.pool.get('mrp.production').browse(cr, uid, production_id, context=None) + result = { + 'product': products.product_id.id, + 'qty': products.product_qty, + 'uom': products.product_uom.id, + } + return {'value': result} + _inherit = 'mrp.production.workcenter.line' _order = "sequence, date_planned" diff --git a/addons/mrp_operations/mrp_operations_view.xml b/addons/mrp_operations/mrp_operations_view.xml index ecd04f13292..d7752939b75 100644 --- a/addons/mrp_operations/mrp_operations_view.xml +++ b/addons/mrp_operations/mrp_operations_view.xml @@ -76,7 +76,7 @@ - + From 09eeab5cdf77e1ce2605caecd4975b383ae4b306 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Mon, 3 Dec 2012 10:36:07 +0530 Subject: [PATCH 06/16] [IMP] Improved code. bzr revid: psa@tinyerp.com-20121203050607-dvx596nf8qjs3yub --- addons/mrp_operations/mrp_operations.py | 32 +++++++++++++------ addons/mrp_operations/mrp_operations_view.xml | 2 +- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index 1facec60a50..a5f68d4f32b 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -56,8 +56,9 @@ class mrp_production_workcenter_line(osv.osv): @return: Dictionary of values. """ ops = self.browse(cr, uid, ids, context=context) + print "ops????????????/", ops date_and_hours_by_cal = [(op.date_planned, op.hour, op.workcenter_id.calendar_id.id) for op in ops if op.date_planned] - + print "date_and_hours_by_cal>>>>>", date_and_hours_by_cal intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) res = {} @@ -71,19 +72,32 @@ class mrp_production_workcenter_line(osv.osv): res[op.id] = op.date_planned return res - def onchange_get_date_end(self, cr, uid, ids, date_planned,cycle,hour, context=None): + def onchange_get_date_end(self, cr, uid, ids,workcenter_id, date_planned,cycle,hour, context=None): """ Finds ending date from schedule date's onchange. """ - date_and_hours_by_cal = [(date_planned,hour, 1)] +# date_and_hours_by_cal = [(date_planned,hour, 1)] +# intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) +# i = intervals.get((date_planned,hour, 1)) +# if i: +# res = i[-1][1].strftime('%Y-%m-%d %H:%M:%S') +# else: +# res = date_planned + work_ids=self.search(cr,uid,[('workcenter_id','=',workcenter_id)],context=context) + ops = self.browse(cr, uid, work_ids, context=context) + date_and_hours_by_cal = [(op.date_planned, op.hour, op.workcenter_id.calendar_id.id) for op in ops if op.date_planned] intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) - i = intervals.get((date_planned,hour, 1)) - if i: - res = i[-1][1].strftime('%Y-%m-%d %H:%M:%S') - else: - res = date_planned + res = False + for op in ops: + print "op.planned date>>>>>>>>>", op.date_planned + if date_planned: + i = intervals.get((op.date_planned,op.hour, op.workcenter_id.calendar_id.id)) + if i: + res= i[-1][1].strftime('%Y-%m-%d %H:%M:%S') + else: + res = date_planned return {'value':{'date_planned_end': res}} - def onchange_production_id(self, cr, uid, ids, production_id, context=None): + def onchange_production_id(self, cr, uid, production_id, context=None): """ Finds UoM of changed product. @param product_id: Id of changed product. @return: Dictionary of values. diff --git a/addons/mrp_operations/mrp_operations_view.xml b/addons/mrp_operations/mrp_operations_view.xml index d7752939b75..0f754a45a60 100644 --- a/addons/mrp_operations/mrp_operations_view.xml +++ b/addons/mrp_operations/mrp_operations_view.xml @@ -84,7 +84,7 @@ - + From 77a640594e0488674aa4c2418b616717a59c3d75 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Mon, 3 Dec 2012 11:02:38 +0530 Subject: [PATCH 07/16] [IMP] Improved. bzr revid: psa@tinyerp.com-20121203053238-mv0xz9mexf651f87 --- addons/mrp_operations/mrp_operations.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index a5f68d4f32b..8c62d9f3708 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -88,7 +88,6 @@ class mrp_production_workcenter_line(osv.osv): intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) res = False for op in ops: - print "op.planned date>>>>>>>>>", op.date_planned if date_planned: i = intervals.get((op.date_planned,op.hour, op.workcenter_id.calendar_id.id)) if i: @@ -97,7 +96,7 @@ class mrp_production_workcenter_line(osv.osv): res = date_planned return {'value':{'date_planned_end': res}} - def onchange_production_id(self, cr, uid, production_id, context=None): + def onchange_production_id(self, cr, uid, ids, production_id, context=None): """ Finds UoM of changed product. @param product_id: Id of changed product. @return: Dictionary of values. From 4521ee8108c4b2885f8fcf89a6f361829719105b Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Mon, 3 Dec 2012 11:52:09 +0530 Subject: [PATCH 08/16] [IMP] Improved code for the End Date field: which should be updated automatically if you change the Scheduled Date. bzr revid: psa@tinyerp.com-20121203062209-t57bjlhw0vkraeg0 --- addons/mrp_operations/mrp_operations.py | 21 +++---------------- addons/mrp_operations/mrp_operations_view.xml | 4 ++-- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index 8c62d9f3708..982623fd0ef 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -56,9 +56,7 @@ class mrp_production_workcenter_line(osv.osv): @return: Dictionary of values. """ ops = self.browse(cr, uid, ids, context=context) - print "ops????????????/", ops date_and_hours_by_cal = [(op.date_planned, op.hour, op.workcenter_id.calendar_id.id) for op in ops if op.date_planned] - print "date_and_hours_by_cal>>>>>", date_and_hours_by_cal intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) res = {} @@ -72,17 +70,8 @@ class mrp_production_workcenter_line(osv.osv): res[op.id] = op.date_planned return res - def onchange_get_date_end(self, cr, uid, ids,workcenter_id, date_planned,cycle,hour, context=None): - """ Finds ending date from schedule date's onchange. - """ -# date_and_hours_by_cal = [(date_planned,hour, 1)] -# intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) -# i = intervals.get((date_planned,hour, 1)) -# if i: -# res = i[-1][1].strftime('%Y-%m-%d %H:%M:%S') -# else: -# res = date_planned - work_ids=self.search(cr,uid,[('workcenter_id','=',workcenter_id)],context=context) + def onchange_get_date_end(self, cr, uid, ids, workcenter_id, date_planned, cycle, hour, context=None): + work_ids = self.search(cr,uid,[('workcenter_id','=',workcenter_id)],context=context) ops = self.browse(cr, uid, work_ids, context=context) date_and_hours_by_cal = [(op.date_planned, op.hour, op.workcenter_id.calendar_id.id) for op in ops if op.date_planned] intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) @@ -93,14 +82,10 @@ class mrp_production_workcenter_line(osv.osv): if i: res= i[-1][1].strftime('%Y-%m-%d %H:%M:%S') else: - res = date_planned + res = op.date_planned return {'value':{'date_planned_end': res}} def onchange_production_id(self, cr, uid, ids, production_id, context=None): - """ Finds UoM of changed product. - @param product_id: Id of changed product. - @return: Dictionary of values. - """ products = self.pool.get('mrp.production').browse(cr, uid, production_id, context=None) result = { 'product': products.product_id.id, diff --git a/addons/mrp_operations/mrp_operations_view.xml b/addons/mrp_operations/mrp_operations_view.xml index 0f754a45a60..32615bf5742 100644 --- a/addons/mrp_operations/mrp_operations_view.xml +++ b/addons/mrp_operations/mrp_operations_view.xml @@ -75,7 +75,7 @@ - + @@ -84,7 +84,7 @@ - + From 7dd72cb38247b09d34180e413f70ed759a3aade3 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 6 Dec 2012 10:25:29 +0530 Subject: [PATCH 09/16] [IMP] Improved onchange. bzr revid: psa@tinyerp.com-20121206045529-1j686ek9cf3tl1uk --- addons/mrp_operations/mrp_operations.py | 45 ++++++++++++++++++------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index 982623fd0ef..890827c0e07 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -25,6 +25,8 @@ import netsvc import time from datetime import datetime from tools.translate import _ +from datetime import timedelta +from dateutil.relativedelta import relativedelta #---------------------------------------------------------- # Work Centers @@ -70,20 +72,37 @@ class mrp_production_workcenter_line(osv.osv): res[op.id] = op.date_planned return res + # def onchange_get_date_end(self, cr, uid, ids, workcenter_id, date_planned, cycle, hour, context=None): def onchange_get_date_end(self, cr, uid, ids, workcenter_id, date_planned, cycle, hour, context=None): - work_ids = self.search(cr,uid,[('workcenter_id','=',workcenter_id)],context=context) - ops = self.browse(cr, uid, work_ids, context=context) - date_and_hours_by_cal = [(op.date_planned, op.hour, op.workcenter_id.calendar_id.id) for op in ops if op.date_planned] - intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) - res = False - for op in ops: - if date_planned: - i = intervals.get((op.date_planned,op.hour, op.workcenter_id.calendar_id.id)) - if i: - res= i[-1][1].strftime('%Y-%m-%d %H:%M:%S') - else: - res = op.date_planned - return {'value':{'date_planned_end': res}} + res = {'value':{}} + yo = cycle * hour + if date_planned and isinstance(date_planned, str): + date_planned = datetime.strptime(date_planned, "%Y-%m-%d %H:%M:%S") + date_planned_end = date_planned + timedelta(hours=yo) + res['value'] = {'date_planned_end': date_planned_end.strftime("%Y-%m-%d %H:%M:%S")} + return res + +# def onchange_get_date_end(self, cr, uid, ids, date_planned, cycle, hour, context=None): +# #work_ids = self.search(cr,uid,[('workcenter_id','=',workcenter_id)],context=context) +# # ops = self.browse(cr, uid, work_ids, context=context) +# # date_and_hours_by_cal = [(op.date_planned, op.hour, op.workcenter_id.calendar_id.id) for op in ops if op.date_planned] +# # intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) +# print ">>>>>>>>>>>>>>>>", type(cycle * hour), (cycle * hour) +# a = (cycle*hour) +# (datetime.now() + relativedelta(months=+1)).strftime("%Y-%m-%d %H:%M:%S") +# print ">>>>>>>>>date planed>>>>", type(date_planned), date_planned +# date_planned_end = datetime(date_planned) + relativedelta(hours=a) +# print "date_planned>>end>>>>.", date_planned_end +# res = False +# # for op in ops: +# # if date_planned: +# # i = intervals.get((op.date_planned,op.hour, op.workcenter_id.calendar_id.id)) +# # if i: +# # res= i[-1][1].strftime('%Y-%m-%d %H:%M:%S') +# # else: +# # res = op.date_planned +# print "ressssssss", res +# return {'value':{'date_planned_end': res}} def onchange_production_id(self, cr, uid, ids, production_id, context=None): products = self.pool.get('mrp.production').browse(cr, uid, production_id, context=None) From bd8250a3cb616bba8b709ec0bd3f0f94fe483f66 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 6 Dec 2012 14:30:38 +0530 Subject: [PATCH 10/16] [IMP] Improved onchange. bzr revid: psa@tinyerp.com-20121206090038-umqu0sce210mtmpp --- addons/mrp_operations/mrp_operations.py | 12 +++++------- addons/mrp_operations/mrp_operations_view.xml | 8 ++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index 890827c0e07..fe8456ddaa2 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -26,7 +26,6 @@ import time from datetime import datetime from tools.translate import _ from datetime import timedelta -from dateutil.relativedelta import relativedelta #---------------------------------------------------------- # Work Centers @@ -72,14 +71,13 @@ class mrp_production_workcenter_line(osv.osv): res[op.id] = op.date_planned return res - # def onchange_get_date_end(self, cr, uid, ids, workcenter_id, date_planned, cycle, hour, context=None): - def onchange_get_date_end(self, cr, uid, ids, workcenter_id, date_planned, cycle, hour, context=None): + def onchange_get_date_end(self, cr, uid, ids, date_planned, cycle, hour): res = {'value':{}} - yo = cycle * hour - if date_planned and isinstance(date_planned, str): + cycle_per_hour = timedelta(hours=(cycle * hour)) + if date_planned : date_planned = datetime.strptime(date_planned, "%Y-%m-%d %H:%M:%S") - date_planned_end = date_planned + timedelta(hours=yo) - res['value'] = {'date_planned_end': date_planned_end.strftime("%Y-%m-%d %H:%M:%S")} + date_planned_end = date_planned + cycle_per_hour + res['value'] = {'date_planned_end': date_planned_end.strftime("%Y-%m-%d %H:%M:%S")} return res # def onchange_get_date_end(self, cr, uid, ids, date_planned, cycle, hour, context=None): diff --git a/addons/mrp_operations/mrp_operations_view.xml b/addons/mrp_operations/mrp_operations_view.xml index 32615bf5742..1da32d2e90d 100644 --- a/addons/mrp_operations/mrp_operations_view.xml +++ b/addons/mrp_operations/mrp_operations_view.xml @@ -75,7 +75,7 @@ - + @@ -84,13 +84,13 @@ - + - - + + From f0fffad5214f0f7d2816c7514479cff0e28e3ad1 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 6 Dec 2012 15:07:38 +0530 Subject: [PATCH 11/16] [IMP] Removed unwanted code. bzr revid: psa@tinyerp.com-20121206093738-o2ll5bvopyp68nnd --- addons/mrp_operations/mrp_operations.py | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index fe8456ddaa2..dd93c68d061 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -74,34 +74,12 @@ class mrp_production_workcenter_line(osv.osv): def onchange_get_date_end(self, cr, uid, ids, date_planned, cycle, hour): res = {'value':{}} cycle_per_hour = timedelta(hours=(cycle * hour)) - if date_planned : + if date_planned and isinstance(date_planned, str): date_planned = datetime.strptime(date_planned, "%Y-%m-%d %H:%M:%S") date_planned_end = date_planned + cycle_per_hour res['value'] = {'date_planned_end': date_planned_end.strftime("%Y-%m-%d %H:%M:%S")} return res -# def onchange_get_date_end(self, cr, uid, ids, date_planned, cycle, hour, context=None): -# #work_ids = self.search(cr,uid,[('workcenter_id','=',workcenter_id)],context=context) -# # ops = self.browse(cr, uid, work_ids, context=context) -# # date_and_hours_by_cal = [(op.date_planned, op.hour, op.workcenter_id.calendar_id.id) for op in ops if op.date_planned] -# # intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) -# print ">>>>>>>>>>>>>>>>", type(cycle * hour), (cycle * hour) -# a = (cycle*hour) -# (datetime.now() + relativedelta(months=+1)).strftime("%Y-%m-%d %H:%M:%S") -# print ">>>>>>>>>date planed>>>>", type(date_planned), date_planned -# date_planned_end = datetime(date_planned) + relativedelta(hours=a) -# print "date_planned>>end>>>>.", date_planned_end -# res = False -# # for op in ops: -# # if date_planned: -# # i = intervals.get((op.date_planned,op.hour, op.workcenter_id.calendar_id.id)) -# # if i: -# # res= i[-1][1].strftime('%Y-%m-%d %H:%M:%S') -# # else: -# # res = op.date_planned -# print "ressssssss", res -# return {'value':{'date_planned_end': res}} - def onchange_production_id(self, cr, uid, ids, production_id, context=None): products = self.pool.get('mrp.production').browse(cr, uid, production_id, context=None) result = { From 26248d180d9713161bfc873c20578c5c25d70555 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 7 Dec 2012 10:11:29 +0530 Subject: [PATCH 12/16] [IMP] Improved Code. bzr revid: psa@tinyerp.com-20121207044129-7p117rb8mpwfryba --- addons/mrp_operations/mrp_operations.py | 50 +++++++++++++++++-------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index dd93c68d061..198763e3ae1 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -51,33 +51,52 @@ class stock_move(osv.osv): stock_move() class mrp_production_workcenter_line(osv.osv): + + def _calculate_end_date(self, cr, uid, ids, date_planned, cycle, hour, calendar_id): + print "\n >>>>>>>>>>>>>>>> in calculation end date :::::::::" + if not date_planned: + return False + cycle_per_hour = timedelta(hours=(cycle * hour)) + date_planned = datetime.strptime(date_planned, "%Y-%m-%d %H:%M:%S") + print "\n >>>>> date planned ::::",date_planned + date_and_hours_by_cal = [(date_planned, cycle, hour, calendar_id)] + print "\n >>>>>>> date and hours by cal :::::::",date_and_hours_by_cal +# intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) +# if intervals: +# i = intervals.get(date_planned, cycle, hour, calendar_id) +# res = i[-1][1].strftime('%Y-%m-%d %H:%M:%S') +# else: + res = date_planned + cycle_per_hour + print "\n >>>>>>>>>>>>>>>> res ::::::::::::::::::::::",res + return res + def _get_date_end(self, cr, uid, ids, field_name, arg, context=None): """ Finds ending date. @return: Dictionary of values. """ ops = self.browse(cr, uid, ids, context=context) - date_and_hours_by_cal = [(op.date_planned, op.hour, op.workcenter_id.calendar_id.id) for op in ops if op.date_planned] - intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) - res = {} for op in ops: - res[op.id] = False - if op.date_planned: - i = intervals.get((op.date_planned, op.hour, op.workcenter_id.calendar_id.id)) - if i: - res[op.id] = i[-1][1].strftime('%Y-%m-%d %H:%M:%S') - else: - res[op.id] = op.date_planned + res[op.id] = self._calculate_end_date(cr, uid, ids, op.date_planned, op.cycle, op.hour, op.workcenter_id.calendar_id.id) return res - + def onchange_get_date_end(self, cr, uid, ids, date_planned, cycle, hour): res = {'value':{}} - cycle_per_hour = timedelta(hours=(cycle * hour)) + calendar_id = {} + print "\n >>>>>>>>>>>>>>>> onchange get date end call::::::::::::::::date_planned::::",date_planned +# cycle_per_hour = timedelta(hours=(cycle * hour)) + ops = self.browse(cr, uid, ids, context=None) + for op in ops: + calendar_id = op.workcenter_id.calendar_id.id +# res[op.id] = self._calculate_end_date(cr, uid, op.date_planned, op.cycle, op.hour, op.workcenter_id.calendar_id.id) if date_planned and isinstance(date_planned, str): - date_planned = datetime.strptime(date_planned, "%Y-%m-%d %H:%M:%S") - date_planned_end = date_planned + cycle_per_hour - res['value'] = {'date_planned_end': date_planned_end.strftime("%Y-%m-%d %H:%M:%S")} +# date_planned = datetime.strptime(date_planned, "%Y-%m-%d %H:%M:%S") +# date_planned_end = date_planned + cycle_per_hour +# res['value'] = {'date_planned_end': date_planned_end.strftime("%Y-%m-%d %H:%M:%S")} + print "\n :::::::::::: calling calculation fun ::::::" + end_date = self._calculate_end_date(cr, uid, ids, date_planned, cycle, hour, calendar_id) + res['value'] = {'date_planned_end': end_date.strftime("%Y-%m-%d %H:%M:%S")} return res def onchange_production_id(self, cr, uid, ids, production_id, context=None): @@ -161,6 +180,7 @@ class mrp_production_workcenter_line(osv.osv): if prod.production_id.workcenter_lines: dstart = min(vals['date_planned'], prod.production_id.workcenter_lines[0]['date_planned']) prod_obj.write(cr, uid, [prod.production_id.id], {'date_start':dstart}, context=context, mini=False) + print "result>??????", result return result def action_draft(self, cr, uid, ids, context=None): From 68a1b5c238ed7e9ca0173fd018cc39846c574bef Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 7 Dec 2012 14:03:53 +0530 Subject: [PATCH 13/16] [IMP]Improved code for the onchange and make it compatible for SAVE and ONCHANGE both. bzr revid: psa@tinyerp.com-20121207083353-zs9hqz1lrqgeor6b --- addons/mrp_operations/mrp_operations.py | 63 +++++++++++-------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index 198763e3ae1..fecbd2f952f 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -51,26 +51,21 @@ class stock_move(osv.osv): stock_move() class mrp_production_workcenter_line(osv.osv): - - def _calculate_end_date(self, cr, uid, ids, date_planned, cycle, hour, calendar_id): - print "\n >>>>>>>>>>>>>>>> in calculation end date :::::::::" - if not date_planned: - return False - cycle_per_hour = timedelta(hours=(cycle * hour)) - date_planned = datetime.strptime(date_planned, "%Y-%m-%d %H:%M:%S") - print "\n >>>>> date planned ::::",date_planned - date_and_hours_by_cal = [(date_planned, cycle, hour, calendar_id)] - print "\n >>>>>>> date and hours by cal :::::::",date_and_hours_by_cal -# intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) -# if intervals: -# i = intervals.get(date_planned, cycle, hour, calendar_id) -# res = i[-1][1].strftime('%Y-%m-%d %H:%M:%S') -# else: - res = date_planned + cycle_per_hour - print "\n >>>>>>>>>>>>>>>> res ::::::::::::::::::::::",res + + def _calculate_end_date(self, cr, uid, ids, date_planned, cycle, hour, workcenter_id, context=None): + if not date_planned: + return False + ops = self.browse(cr, uid, ids, context=context) + date_and_hours_by_cal =[ (date_planned, hour, workcenter_id)] + intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) + if intervals: + i = intervals.get((date_planned, hour, workcenter_id)) + if i: + res = i[-1][1].strftime('%Y-%m-%d %H:%M:%S') + else: + res = date_planned return res - - + def _get_date_end(self, cr, uid, ids, field_name, arg, context=None): """ Finds ending date. @return: Dictionary of values. @@ -78,26 +73,24 @@ class mrp_production_workcenter_line(osv.osv): ops = self.browse(cr, uid, ids, context=context) res = {} for op in ops: - res[op.id] = self._calculate_end_date(cr, uid, ids, op.date_planned, op.cycle, op.hour, op.workcenter_id.calendar_id.id) + res[op.id] = False + if op.date_planned: + res[op.id] = self._calculate_end_date(cr, uid, ids, op.date_planned, op.cycle, op.hour, op.workcenter_id.calendar_id.id) + else: + res[op.id] = op.date_planned return res - def onchange_get_date_end(self, cr, uid, ids, date_planned, cycle, hour): + def onchange_get_date_end(self, cr, uid, ids, workcenter_id, context=None): res = {'value':{}} - calendar_id = {} - print "\n >>>>>>>>>>>>>>>> onchange get date end call::::::::::::::::date_planned::::",date_planned -# cycle_per_hour = timedelta(hours=(cycle * hour)) - ops = self.browse(cr, uid, ids, context=None) + work_ids = self.search(cr,uid,[('workcenter_id','=',workcenter_id)],context=context) + ops = self.browse(cr, uid, work_ids, context=context) for op in ops: - calendar_id = op.workcenter_id.calendar_id.id -# res[op.id] = self._calculate_end_date(cr, uid, op.date_planned, op.cycle, op.hour, op.workcenter_id.calendar_id.id) - if date_planned and isinstance(date_planned, str): -# date_planned = datetime.strptime(date_planned, "%Y-%m-%d %H:%M:%S") -# date_planned_end = date_planned + cycle_per_hour -# res['value'] = {'date_planned_end': date_planned_end.strftime("%Y-%m-%d %H:%M:%S")} - print "\n :::::::::::: calling calculation fun ::::::" - end_date = self._calculate_end_date(cr, uid, ids, date_planned, cycle, hour, calendar_id) - res['value'] = {'date_planned_end': end_date.strftime("%Y-%m-%d %H:%M:%S")} - return res + res['date_planned_end'] = False + if op.date_planned: + res['date_planned_end'] = self._calculate_end_date(cr, uid, ids, op.date_planned, op.cycle, op.hour, op.workcenter_id.calendar_id.id) + else: + res['date_planned_end'] = op.date_planned + return {'value': res} def onchange_production_id(self, cr, uid, ids, production_id, context=None): products = self.pool.get('mrp.production').browse(cr, uid, production_id, context=None) From a347798d7e27fe790eba14d41623620f4d335e96 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 7 Dec 2012 15:33:29 +0530 Subject: [PATCH 14/16] [IMP]Improved code of onchange. bzr revid: psa@tinyerp.com-20121207100329-te2a7ff8qgnv6xtl --- addons/mrp_operations/mrp_operations.py | 24 +++++++------------ addons/mrp_operations/mrp_operations_view.xml | 8 +++---- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index fecbd2f952f..eaf835e8e91 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -52,14 +52,13 @@ stock_move() class mrp_production_workcenter_line(osv.osv): - def _calculate_end_date(self, cr, uid, ids, date_planned, cycle, hour, workcenter_id, context=None): + def _calculate_end_date(self, cr, uid, date_planned, hour, calendar_id, context=None): if not date_planned: return False - ops = self.browse(cr, uid, ids, context=context) - date_and_hours_by_cal =[ (date_planned, hour, workcenter_id)] + date_and_hours_by_cal =[ (date_planned, hour, calendar_id)] intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) if intervals: - i = intervals.get((date_planned, hour, workcenter_id)) + i = intervals.get((date_planned, hour, calendar_id)) if i: res = i[-1][1].strftime('%Y-%m-%d %H:%M:%S') else: @@ -75,21 +74,16 @@ class mrp_production_workcenter_line(osv.osv): for op in ops: res[op.id] = False if op.date_planned: - res[op.id] = self._calculate_end_date(cr, uid, ids, op.date_planned, op.cycle, op.hour, op.workcenter_id.calendar_id.id) + res[op.id] = self._calculate_end_date(cr, uid, op.date_planned, op.hour, op.workcenter_id.calendar_id.id) else: res[op.id] = op.date_planned return res - def onchange_get_date_end(self, cr, uid, ids, workcenter_id, context=None): - res = {'value':{}} - work_ids = self.search(cr,uid,[('workcenter_id','=',workcenter_id)],context=context) - ops = self.browse(cr, uid, work_ids, context=context) - for op in ops: - res['date_planned_end'] = False - if op.date_planned: - res['date_planned_end'] = self._calculate_end_date(cr, uid, ids, op.date_planned, op.cycle, op.hour, op.workcenter_id.calendar_id.id) - else: - res['date_planned_end'] = op.date_planned + def onchange_date_planned(self, cr, uid, ids, date_planned, hour, workcenter_id, context=None): + res = {} + if workcenter_id: + workcenter = self.pool.get("mrp.workcenter").browse(cr, uid, workcenter_id, context=context) + res['date_planned_end'] = self._calculate_end_date(cr, uid, date_planned, hour, workcenter.calendar_id.id) return {'value': res} def onchange_production_id(self, cr, uid, ids, production_id, context=None): diff --git a/addons/mrp_operations/mrp_operations_view.xml b/addons/mrp_operations/mrp_operations_view.xml index 1da32d2e90d..6d0a451648a 100644 --- a/addons/mrp_operations/mrp_operations_view.xml +++ b/addons/mrp_operations/mrp_operations_view.xml @@ -75,7 +75,7 @@ - + @@ -84,13 +84,13 @@ - + - - + + From c5ef9fa145615125071b9702e55f34c859f928e6 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 7 Dec 2012 18:54:01 +0530 Subject: [PATCH 15/16] [IMP] Removed unwanted code. bzr revid: psa@tinyerp.com-20121207132401-3uqa0or06nynl2hb --- addons/mrp_operations/mrp_operations.py | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index eaf835e8e91..beeb4389e8f 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -167,7 +167,6 @@ class mrp_production_workcenter_line(osv.osv): if prod.production_id.workcenter_lines: dstart = min(vals['date_planned'], prod.production_id.workcenter_lines[0]['date_planned']) prod_obj.write(cr, uid, [prod.production_id.id], {'date_start':dstart}, context=context, mini=False) - print "result>??????", result return result def action_draft(self, cr, uid, ids, context=None): From 4fd400982c88d8e8d6eed3aa3560fb813564e386 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Mon, 10 Dec 2012 10:55:54 +0530 Subject: [PATCH 16/16] [IMP] Reverted the onchange_enddate functions code. And make it as was in previous. bzr revid: psa@tinyerp.com-20121210052554-hw7ep3rvvi3fr7wg --- addons/mrp_operations/mrp_operations.py | 32 ++++++------------- addons/mrp_operations/mrp_operations_view.xml | 6 ++-- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/addons/mrp_operations/mrp_operations.py b/addons/mrp_operations/mrp_operations.py index beeb4389e8f..aaaa14c5309 100644 --- a/addons/mrp_operations/mrp_operations.py +++ b/addons/mrp_operations/mrp_operations.py @@ -52,40 +52,26 @@ stock_move() class mrp_production_workcenter_line(osv.osv): - def _calculate_end_date(self, cr, uid, date_planned, hour, calendar_id, context=None): - if not date_planned: - return False - date_and_hours_by_cal =[ (date_planned, hour, calendar_id)] - intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) - if intervals: - i = intervals.get((date_planned, hour, calendar_id)) - if i: - res = i[-1][1].strftime('%Y-%m-%d %H:%M:%S') - else: - res = date_planned - return res - def _get_date_end(self, cr, uid, ids, field_name, arg, context=None): """ Finds ending date. @return: Dictionary of values. """ ops = self.browse(cr, uid, ids, context=context) + date_and_hours_by_cal = [(op.date_planned, op.hour, op.workcenter_id.calendar_id.id) for op in ops if op.date_planned] + + intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal) + res = {} for op in ops: res[op.id] = False if op.date_planned: - res[op.id] = self._calculate_end_date(cr, uid, op.date_planned, op.hour, op.workcenter_id.calendar_id.id) - else: - res[op.id] = op.date_planned + i = intervals.get((op.date_planned, op.hour, op.workcenter_id.calendar_id.id)) + if i: + res[op.id] = i[-1][1].strftime('%Y-%m-%d %H:%M:%S') + else: + res[op.id] = op.date_planned return res - def onchange_date_planned(self, cr, uid, ids, date_planned, hour, workcenter_id, context=None): - res = {} - if workcenter_id: - workcenter = self.pool.get("mrp.workcenter").browse(cr, uid, workcenter_id, context=context) - res['date_planned_end'] = self._calculate_end_date(cr, uid, date_planned, hour, workcenter.calendar_id.id) - return {'value': res} - def onchange_production_id(self, cr, uid, ids, production_id, context=None): products = self.pool.get('mrp.production').browse(cr, uid, production_id, context=None) result = { diff --git a/addons/mrp_operations/mrp_operations_view.xml b/addons/mrp_operations/mrp_operations_view.xml index 6d0a451648a..dbe5ed83d0d 100644 --- a/addons/mrp_operations/mrp_operations_view.xml +++ b/addons/mrp_operations/mrp_operations_view.xml @@ -75,7 +75,7 @@ - + @@ -84,13 +84,13 @@ - + - +