def onchange_date(self, cr, uid, ids, field_name, adjust_time, time, date, context=None): if adjust_time: format = tools.DEFAULT_SERVER_DATETIME_FORMAT tz = context['tz'] date_local = tools.server_to_local_timestamp( date, format, format, tz) date_local_new = date_local[0:10] + ' ' + time server_tz = tools.get_server_timezone() if server_tz != 'UTC': raise osv.except_osv( _('Error'), _('Only UTC server time is currently supported')) # convet to UTC utc = pytz.utc local_tz = pytz.timezone(tz) fmt = '%Y-%m-%d %H:%M:%S' dt = datetime.strptime(date_local_new, fmt) local_dt = local_tz.localize(dt) date_r = utc.normalize(local_dt.astimezone(utc)).strftime(fmt) else: date_r = date result = {'value': {field_name: date_r}} return result
def format_date_tz(date, tz=None): if not date: return 'n/a' format = tools.DEFAULT_SERVER_DATETIME_FORMAT return tools.server_to_local_timestamp(date, format, format, tz)
def format_date_tz(date, tz_user): dt_format = tools.DEFAULT_SERVER_DATETIME_FORMAT return date and tools.server_to_local_timestamp(date, dt_format, dt_format, tz_user) or 'n/a'
def action_open(self, cr, uid, ids, context=None): self._logger.debug('FGF stock_location_product ids %s' % ids) self._logger.debug('FGF stock_location_product context %s' % context) if context is None: context = {} res = super(stock_location_product, self).action_open_window(cr, uid, ids, context) if context.get('open') == 'report': mod_obj = self.pool.get('ir.model.data') rep_obj = self.pool.get('ir.actions.report.xml') res1 = mod_obj.get_object_reference( cr, uid, 'c2c_stock_accounting', 'report_print_computed_product') id = res1 and res1[1] or False res.update(rep_obj.read(cr, uid, [id], context=context)[0]) self._logger.debug('FGF stock_location_product res %s' % res) location_products = self.read( cr, uid, ids, ['from_date', 'to_date', 'from_date2', 'to_date2', 'adjust_time'], context) self._logger.debug('FGF stock_location_products %s' % location_products) from_date1 = location_products[0]['from_date'] to_date1 = location_products[0]['to_date'] from_date2 = location_products[0]['from_date2'] to_date2 = location_products[0]['to_date2'] format = tools.DEFAULT_SERVER_DATETIME_FORMAT tz = context['tz'] date_local = tools.server_to_local_timestamp(date, format, format, tz) res['context']['local_from_date1'] = '' res['context']['local_to_date1'] = '' res['context']['local_from_date2'] = '' res['context']['local_to_date2'] = '' if from_date1: res['context'][ 'local_from_date1'] = tools.server_to_local_timestamp( from_date1, format, format, tz) if to_date1: res['context']['local_to_date1'] = tools.server_to_local_timestamp( to_date1, format, format, tz) if from_date2: res['context'][ 'local_from_date2'] = tools.server_to_local_timestamp( from_date2, format, format, tz) if to_date2: res['context']['local_to_date2'] = tools.server_to_local_timestamp( to_date2, format, format, tz) res['context']['from_date'] = from_date1 res['context']['to_date'] = to_date1 res['context']['from_date1'] = from_date1 res['context']['to_date1'] = to_date1 res['context']['from_date2'] = from_date2 res['context']['to_date2'] = to_date2 res['context']['location_name'] = self.pool.get('stock.location').read( cr, uid, res['context']['location'], ['name'])['name'] #res['context']['cr1'] = cr self._logger.debug('FGF stock_location_product res neu %s' % res) return res