def _getPropertyDict(self, movement, **kw): """Gather start_date and stop_date, converge them to the end of month. """ property_dict = {} for property_name in ('start_date', 'stop_date'): date = movement.getProperty(property_name, None) if date is not None: end_of_month = atTheEndOfPeriod(date, 'month')-1 property_dict[property_name] = end_of_month return property_dict
def _getPropertyDict(self, movement, **kw): """Gather start_date and stop_date, converge them to the end of month. """ property_dict = {} for property_name in ('start_date', 'stop_date'): date = movement.getProperty(property_name, None) if date is not None: end_of_month = atTheEndOfPeriod(date, 'month') - 1 property_dict[property_name] = end_of_month return property_dict
def expandOpenOrderRule(self, applied_rule, **kw): """ Expand tries to find all applicable supply path and all applicable transformations. """ number_of_months_in_year = 12 # get career list that use this employment contract : career_list = self.getAggregateRelatedValueList() current_date = DateTime() for career in career_list: employee = career.getParentRelativeUrl() employer = career.getSubordinationValue( ) is not None and career.getSubordinationValue().getRelativeUrl( ) or None start_date = career.getStartDate() stop_date = career.getStopDate() for year_count in range(stop_date.year() - start_date.year() + 1): for month_count in range(stop_date.month() - start_date.month() + 1): # for first movement, we use the start_date day movement_start_date = addToDate(start_date, year=year_count, month=month_count) if month_count != 0 or year_count != 0: # if there is more than one movement in the period, start date is the begining of the month movement_start_date = DateTime( movement_start_date.strftime('%Y/%m/01 00:00:00')) movement_stop_date = atTheEndOfPeriod( movement_start_date, 'month') - 1 # create only one year in the future if movement_start_date > addToDate(current_date, year=1): break # if the stop_date is in not at the end of the month, use it if stop_date < movement_stop_date: movement_stop_date = stop_date if not self.assertMovementExists(applied_rule, movement_start_date) and\ movement_stop_date.month() <= number_of_months_in_year: property_dict = dict() simulation_movement = applied_rule.newContent( id='movement_%s_%s' % (movement_start_date.year(), movement_stop_date.month()), start_date=movement_start_date, stop_date=movement_stop_date, source=employee, destination=employer, source_section=employee, destination_section=employer, quantity=self.getQuantity(), quantity_unit=self.getQuantityUnit(), resource=self.getResource())
def _getPropertyDict(self, movement, **kw): """Gather start_date and stop_date, converge them to the end of month. """ property_dict = {} for property_name in self.getTestedPropertyList() or ('start_date', 'stop_date'): date = movement.getProperty(property_name, None) if date is not None: # wrap atTheEndOfPeriod value with DateTime(value..strftime('%Y/%m/%d')) so that # it returns a value with an appropriate time offset at that date. end_of_month = DateTime((atTheEndOfPeriod(date, 'month') - 0.5).strftime('%Y/%m/%d')) property_dict[property_name] = end_of_month return property_dict
def expandOpenOrderRule(self, applied_rule, **kw): """ Expand tries to find all applicable supply path and all applicable transformations. """ number_of_months_in_year = 12 # get career list that use this employment contract : career_list = self.getAggregateRelatedValueList() current_date = DateTime() for career in career_list: employee = career.getParentRelativeUrl() employer = career.getSubordinationValue() is not None and career.getSubordinationValue().getRelativeUrl() or None start_date = career.getStartDate() stop_date = career.getStopDate() for year_count in range(stop_date.year() - start_date.year() + 1): for month_count in range(stop_date.month() - start_date.month()+1): # for first movement, we use the start_date day movement_start_date = addToDate(start_date, year=year_count, month=month_count) if month_count != 0 or year_count != 0: # if there is more than one movement in the period, start date is the begining of the month movement_start_date = DateTime(movement_start_date.strftime('%Y/%m/01 00:00:00')) movement_stop_date = atTheEndOfPeriod(movement_start_date, 'month')-1 # create only one year in the future if movement_start_date > addToDate(current_date, year=1): break # if the stop_date is in not at the end of the month, use it if stop_date < movement_stop_date: movement_stop_date = stop_date if not self.assertMovementExists(applied_rule, movement_start_date) and\ movement_stop_date.month() <= number_of_months_in_year: property_dict = dict() simulation_movement = applied_rule.newContent( id = 'movement_%s_%s' % (movement_start_date.year(), movement_stop_date.month()), start_date = movement_start_date, stop_date = movement_stop_date, source = employee, destination = employer, source_section = employee, destination_section = employer, quantity = self.getQuantity(), quantity_unit = self.getQuantityUnit(), resource = self.getResource() )
portal_type_list = [] extend = portal_type_list.extend for module in module_list: extend(module.ERP5Folder_getUnrestrictedContentTypeList()) # compute sql params, we group and order by date and portal type if aggregation_level == "year": sql_format = "%Y" elif aggregation_level == "month": sql_format = "%Y-%m" elif aggregation_level == "week": sql_format = "%Y-%u" elif aggregation_level == "day": sql_format = "%Y-%m-%d" if to_date is not None: to_date = atTheEndOfPeriod(to_date, period=aggregation_level) count_kw = {} if from_date is not None and to_date is not None: count_kw['creation_date'] = { 'range': 'minmax', 'query': (from_date, to_date), } elif from_date is not None: count_kw['creation_date'] = { 'range': 'min', 'query': from_date, } elif to_date is not None: count_kw['creation_date'] = { 'range': 'max', 'query': to_date,
portal_type_list = [] extend = portal_type_list.extend for module in module_list: extend(module.ERP5Folder_getUnrestrictedContentTypeList()) # compute sql params, we group and order by date and portal type if aggregation_level == "year": sql_format = "%Y" elif aggregation_level == "month": sql_format = "%Y-%m" elif aggregation_level == "week": sql_format = "%Y-%u" elif aggregation_level == "day": sql_format = "%Y-%m-%d" if to_date is not None: to_date = atTheEndOfPeriod(to_date, period=aggregation_level) params = {"creation_date":(from_date, to_date)} query=None if from_date is not None and to_date is not None: params = {"creation_date":(from_date, to_date)} query = Query(range="minmax", **params) elif from_date is not None: params = {"creation_date":from_date} query = Query(range="min", **params) elif to_date is not None: params = {"creation_date":to_date} query = Query(range="max", **params) select_expression = {'date' : 'DATE_FORMAT(creation_date, "%s")'%sql_format, 'portal_type' : None} group_by = ['DATE_FORMAT(creation_date, "%s")' % sql_format, 'portal_type'] # count number of object created by the user for each type of document
def test_atTheEndOfPeriod(self): date = DateTime('2008/01/01 00:00:00 Universal') self.assertEqual(atTheEndOfPeriod(date, 'year').pCommonZ(), 'Jan. 1, 2009 12:00 am Universal') self.assertEqual(atTheEndOfPeriod(date, 'month').pCommonZ(), 'Feb. 1, 2008 12:00 am Universal') self.assertEqual(atTheEndOfPeriod(date, 'week').pCommonZ(), 'Jan. 7, 2008 12:00 am Universal') self.assertEqual(atTheEndOfPeriod(date, 'day').pCommonZ(), 'Jan. 2, 2008 12:00 am Universal') # Switch to summer time self.assertEqual('Apr. 6, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/04/05 23:59:59 US/Eastern'), 'day').pCommonZ()) self.assertEqual('Apr. 7, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/04/06 00:00:00 US/Eastern'), 'day').pCommonZ()) self.assertEqual('Apr. 7, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/04/06 23:59:59 US/Eastern'), 'day').pCommonZ()) self.assertEqual('May 1, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/04/01 US/Eastern'), 'month').pCommonZ()) # Switch to winter time self.assertEqual('Oct. 26, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/10/25 23:59:59 US/Eastern'), 'day').pCommonZ()) self.assertEqual('Oct. 27, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/10/26 00:00:00 US/Eastern'), 'day').pCommonZ()) self.assertEqual('Oct. 27, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/10/26 23:59:59 US/Eastern'), 'day').pCommonZ()) self.assertEqual('Nov. 1, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/10/01 US/Eastern'), 'month').pCommonZ())
from Products.ERP5Type.DateUtils import atTheEndOfPeriod return atTheEndOfPeriod(context.getStopDate(), 'month') - 1
def test_atTheEndOfPeriod(self): date = DateTime('2008/01/01 00:00:00 Universal') self.assertEqual(atTheEndOfPeriod(date, 'year').pCommonZ(), 'Jan. 1, 2009 12:00 am Universal') self.assertEqual(atTheEndOfPeriod(date, 'month').pCommonZ(), 'Feb. 1, 2008 12:00 am Universal') self.assertEqual(atTheEndOfPeriod(date, 'week').pCommonZ(), 'Jan. 7, 2008 12:00 am Universal') self.assertEqual(atTheEndOfPeriod(date, 'day').pCommonZ(), 'Jan. 2, 2008 12:00 am Universal') # Switch to summer time self.assertEqual('Apr. 6, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/04/05 23:59:59 US/Eastern'), 'day').pCommonZ()) self.assertEqual('Apr. 7, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/04/06 00:00:00 US/Eastern'), 'day').pCommonZ()) self.assertEqual('Apr. 7, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/04/06 23:59:59 US/Eastern'), 'day').pCommonZ()) self.assertEqual('May 1, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/04/01 US/Eastern'), 'month').pCommonZ()) # Switch to winter time self.assertEqual('Oct. 26, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/10/25 23:59:59 US/Eastern'), 'day').pCommonZ()) self.assertEqual('Oct. 27, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/10/26 00:00:00 US/Eastern'), 'day').pCommonZ()) self.assertEqual('Oct. 27, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/10/26 23:59:59 US/Eastern'), 'day').pCommonZ()) self.assertEqual('Nov. 1, 2008 12:00 am US/Eastern', atTheEndOfPeriod(DateTime('2008/10/01 US/Eastern'), 'month').pCommonZ())