def getNextPeriodicalDate(current_date): next_start_date = current_date next_start_date = addToDate(next_start_date, day=1) while 1: if (validateDay(next_start_date)) and \ (validateWeek(next_start_date)) and \ (validateMonth(next_start_date)): break else: next_start_date = addToDate(next_start_date, day=1) return next_start_date
def getLeaveBlocAsDict(leave_period, leave_category): bloc = {} bloc['S21.G00.60.001'] = leave_category.getCodification() bloc['S21.G00.60.002'] = formatDate(leave_period.getStartDate()) bloc['S21.G00.60.003'] = formatDate(leave_period.getStopDate()) bloc['S21.G00.60.004'] = '01' # we do subrogation first_subrogation_day = addToDate(leave_period.getStartDate(), day=3) bloc['S21.G00.60.005'] = formatDate(first_subrogation_day) # 3 months of subrogation, as defined in the collective agreement bloc['S21.G00.60.006'] = formatDate( addToDate(first_subrogation_day, month=3, days=-1)) bloc['S21.G00.60.007'] = bank_account.getIban() bloc['S21.G00.60.008'] = bank_account.getBicCode() # employee restarted work during this period if getattr(leave_period, 'expiration_date', None): bloc['S21.G00.60.010'] = formatDate(leave_period.getExpirationDate()) bloc['S21.G00.60.011'] = '01' # Restart normally return bloc
def test_03_EveryHour(self): alarm = self.newAlarm(enabled=True) now = DateTime() date = addToDate(now, day=2) alarm.setPeriodicityStartDate(date) alarm.setPeriodicityHourFrequency(1) self.tic() alarm.setNextAlarmDate(current_date=now) self.assertEqual(alarm.getAlarmDate(), date) now = addToDate(now, day=2) alarm.setNextAlarmDate(current_date=now) next_date = addToDate(date, hour=1) self.assertEqual(alarm.getAlarmDate(), next_date) now = addToDate(now, hour=1, minute=5) alarm.setNextAlarmDate(current_date=now) next_date = addToDate(next_date, hour=1) self.assertEqual(alarm.getAlarmDate(), next_date) # check if manual invoking does not break getAlarmDate() result. alarm.activeSense() self.assertEqual(alarm.getAlarmDate(), next_date)
def render_date_range(date_range): m = re.match(r'(\d+)([dwmy])', date_range) if m is not None: period_dict = { 'd': 'day', 'w': 'week', 'm': 'month', 'y': 'year', } num, period = m.groups() period = period_dict[period.lower()] return addToDate(DateTime(), **{period: -int(num)})
# Get task dates start_date = pasted_task.getStartDate() stop_date = pasted_task.getStopDate() duration = int(stop_date) - int(start_date) second_to_add = int(next_date) - int(start_date) for line in pasted_task.getMovementList(): # Get task line dates if line.hasStartDate(): line_start_date = line.getStartDate() else: line_start_date = start_date if line.hasStopDate(): line_stop_date = line.getStopDate() else: line_stop_date = stop_date line_duration = int(line_stop_date) - int(line_start_date) # Line dates are different from task dates next_line_start_date = addToDate(line_start_date, second=second_to_add) line.edit( start_date=next_line_start_date, stop_date=addToDate(next_line_start_date, second=line_duration), ) pasted_task.edit( start_date=next_date, stop_date=addToDate(next_date, second=duration), )
from erp5.component.module.DateUtils import addToDate from Products.ZSQLCatalog.SQLCatalog import Query portal = context.getPortalObject() portal_categories = portal.portal_categories now = DateTime() effective_date = context.getEffectiveDate() previous_pay_day = addToDate(effective_date, month=-1) # Get period dates result = portal.portal_catalog(portal_type="DSN Monthly Report", simulation_state="validated", sort_on=[("creation_date", "descending")]) from_date = DateTime(effective_date.year(), effective_date.month(), 1) # We report leave periods which are not over yet ... result = portal.portal_catalog(portal_type='Leave Request Period', query=Query(expiration_date=None)) leave_period_list = [period.getObject() for period in result] # ... And leave periods which ended during last period result = portal.portal_catalog(portal_type='Leave Request Period', expiration_date=">=%s" % from_date.strftime("%Y/%m")) # We need to filter results, because we can't search in a date interval with # a smaller grain than a month. leave_period_list.extend([ period.getObject() for period in result if period.getExpirationDate() > from_date
from Products.ZSQLCatalog.SQLCatalog import Query from erp5.component.module.DateUtils import addToDate from DateTime import DateTime portal = context.getPortalObject() portal.portal_catalog.searchAndActivate( portal_type="Expense Validation Request", method_id='ExpenseValidationRequest_createRepresentativeRecord', creation_date=Query(creation_date=addToDate(DateTime(), to_add={'day': -120}), range="min"), activate_kw={'tag': tag}, ) context.activate(after_tag=tag).getId()
if ctp_code not in aggregated_social_contribution_dict: aggregated_social_contribution_dict[ctp_code] = employee_ctp[ctp_code].copy() else: for summing_parameter in ('base', 'quantity'): aggregated_social_contribution_dict[ctp_code][summing_parameter] = \ aggregated_social_contribution_dict[ctp_code][summing_parameter] + employee_ctp[ctp_code][summing_parameter] # Find the payment transaction for the social contributions if len(payment_transaction_list): for payment in payment_transaction_list: corporate_registration_code = payment.getDestinationSectionValue().getCorporateRegistrationCode() if corporate_registration_code == social_contribution_organisation.getCorporateRegistrationCode(): if establishment.isQuaterlyPayment(): amount_list = [] for i in range(3): start_date = addToDate(first_date_of_month, month=-i) stop_date = getLastDateOfMonth(addToDate(first_date_of_month, month=-i)) + 1 amount = -1. * portal.portal_simulation.getInventory( from_date=start_date, to_date=stop_date, section_uid=organisation.getUid(), mirror_section_uid=social_contribution_organisation.getUid(), node_uid=portal.account_module['securite_sociale'].getUid(), ledger_uid=portal.portal_categories.ledger.accounting.general.getUid(), parent_portal_type='Accounting Transaction', ) amount_list.append(amount) dsn_file.append(getDSNBlockDict(block_id='S21.G00.20', target=payment, corporate_registration_code=social_contribution_organisation.getCorporateRegistrationCode(), first_date_of_month=start_date,
if context.getPortalType() != 'Person': raise TypeError('Person object is required') from DateTime import DateTime from erp5.component.module.DateUtils import addToDate key = context.Base_getBearerTokenKey() if not key: raise ValueError('Bearer Key Token is not defined') token = { 'expiration_timestamp': addToDate(DateTime(), to_add={ 'hour': 1 }).timeTime(), 'reference': context.Person_getUserId(), 'user-agent': context.REQUEST.getHeader('User-Agent'), 'remote-addr': context.REQUEST.get('REMOTE_ADDR') } hmac = context.Base_getHMAC(key, str(token)) context.Base_setBearerToken(hmac, token) return hmac, token['expiration_timestamp']
from DateTime import DateTime from erp5.component.module.DateUtils import addToDate from Products.ERP5Type.Message import translateString month_added = 1 if frequency == 'quarterly': month_added = 3 date = context.getStartDate() while date < context.getStopDate(): end_date = addToDate(date, dict(month=month_added)) # recreate a DateTime to have it in the proper timezone start_date = DateTime(date.year(), date.month(), date.day()) stop_date = DateTime((end_date - 1).year(), (end_date - 1).month(), (end_date - 1).day()) period = context.newContent(portal_type='Accounting Period', start_date=start_date, stop_date=stop_date) if frequency == 'quarterly': period.setShortTitle('%s-%s' % (start_date.strftime('%Y %m'), (end_date - 1).strftime('%m'))) else: period.setShortTitle(start_date.strftime('%Y-%m')) period.setTitle(str(translateString(start_date.strftime('%B')))) if open_periods: period.start() date = end_date
def _getPropertyDict(self, movement, **kw): property_dict = {} start_date = self._getStartDate(movement) property_dict['start_date'] = start_date property_dict['stop_date'] = addToDate(start_date, day=1) return property_dict