[IMP]Improved code for the onchange and make it compatible for SAVE and ONCHANGE both.

bzr revid: psa@tinyerp.com-20121207083353-zs9hqz1lrqgeor6b
This commit is contained in:
Paramjit Singh Sahota 2012-12-07 14:03:53 +05:30
parent b858a10f3a
commit 68a1b5c238
1 changed files with 28 additions and 35 deletions

View File

@ -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)