def importFromFilesystem(cls, context, reference, version, source_reference=None): """ Import a Component from the filesystem into ZODB and validate it so it can be loaded straightaway provided validate() does not raise any error of course """ import os.path if source_reference is None or not source_reference.startswith( 'Products'): path = os.path.join(cls._getFilesystemPath(), reference + '.py') else: import inspect module_obj = __import__(source_reference, globals(), {}, level=0, fromlist=[source_reference]) path = inspect.getsourcefile(module_obj) with open(path) as f: source_code = f.read() # Checking that the source code is syntactically correct is not # needed when importing from filesystem, moreover errors may occur # if in the same transaction a Component is created and another # one depending upon the former... object_id = '%s.%s.%s' % (cls.getIdPrefix(), version, reference) new_component = context.newContent(id=object_id, reference=reference, source_reference=source_reference, version=version, text_content=source_code, portal_type=cls.portal_type) # XXX-ARNAU: checkConsistency() is also called before commit in # Component_checkSourceCodeAndValidateAfterModified. Also, everything # should be done in checkConsistency()... error_message_list = [ m for m in new_component.checkSourceCode() if m['type'] in ('F', 'E') ] if error_message_list: raise SyntaxError(error_message_list) consistency_message_list = new_component.checkConsistency() if consistency_message_list: from Products.DCWorkflow.DCWorkflow import ValidationFailed raise ValidationFailed(consistency_message_list) new_component.validate() return new_component
from Products.DCWorkflow.DCWorkflow import ValidationFailed from Products.ERP5Type.Message import translateString period = state_change['object'] portal = period.getPortalObject() period.Base_checkConsistency() # This tag is used in AccountingPeriod_createBalanceTransaction if portal.portal_activities.countMessageWithTag('BalanceTransactionCreation'): raise ValidationFailed(translateString("Balance transaction creation already in progress. Please try again later.")) valid_simulation_state_list = ['cancelled', 'delivered', 'deleted', 'rejected'] all_state_list = [x[1] for x in portal.Base_getTranslatedWorkflowStateItemList(wf_id='accounting_workflow')] invalid_simulation_state_list = [state for state in all_state_list if state not in valid_simulation_state_list] if period.getParentValue().getPortalType() == 'Organisation': # if this is a "main" accounting period, we refuse to close if the previous # period is not already closed. for other_period in period.getParentValue().contentValues( portal_type='Accounting Period', checked_permission='View'): if other_period != period and \ other_period.getSimulationState() not in ('delivered', 'cancelled') and\ other_period.getStartDate() < period.getStartDate(): raise ValidationFailed(translateString( "Previous accounting periods has to be closed first.")) section = period.getParentValue()
# Check that the transaction is in an open accounting period when we validate # it. skip_period_validation = state_change['kwargs'].get('skip_period_validation', 0) transition = state_change['transition'] if transition.id in ('plan_action', 'confirm_action'): skip_period_validation = 1 source_section = transaction.getSourceSectionValue( portal_type=['Organisation', 'Person']) destination_section = transaction.getDestinationSectionValue( portal_type=['Organisation', 'Person']) if source_section is None and destination_section is None: raise ValidationFailed( translateString('At least one section must be defined.')) # check that no categories are used for section if transaction.getSourceSectionValue(portal_type='Category') is not None or\ transaction.getDestinationSectionValue(portal_type='Category') is not None: raise ValidationFailed( translateString('Using category for section is invalid.')) transaction_line_list = transaction.getMovementList( portal_type=transaction.getPortalAccountingMovementTypeList()) def checkAccountingPeriodRecursivly(accounting_period, transaction_date): valid = accounting_period.getSimulationState() in ('planned', 'started') if not valid: return False
from Products.DCWorkflow.DCWorkflow import ValidationFailed from Products.ERP5Type.Message import translateString container.Event_checkConsistency(sci) portal = sci.getPortal() portal_workflow = portal.portal_workflow event = sci['object'] follow_up_ticket_type = portal_workflow.getInfoFor(event, 'follow_up_ticket_type', wf_id='event_workflow') follow_up_ticket_title = portal_workflow.getInfoFor(event, 'follow_up_ticket_title', wf_id='event_workflow') if follow_up_ticket_type not in ["", None] and \ follow_up_ticket_title not in ["", None]: return if not event.getFollowUp(): raise ValidationFailed( translateString('Follow up must be set to acknowledge an Event.'))
from Products.DCWorkflow.DCWorkflow import ValidationFailed delivery = state_change['object'] divergence_list = delivery.getDivergenceList() Base_translateString = delivery.Base_translateString if not len(divergence_list): delivery.converge() raise ValidationFailed(Base_translateString('No divergence found.')) delivery_solve_property_dict = {} listbox = state_change['kwargs'].get('delivery_group_listbox') if listbox is not None: for k, v in listbox.items(): object_url = v['choice'] if object_url != 'ignore': object = delivery.restrictedTraverse(object_url) delivery_solve_property_dict[k] = object.getPropertyList(k) divergence_to_accept_list = [] divergence_to_adopt_list = [] divergence_dict = {} for divergence in divergence_list: simulation_movement_url = divergence.getProperty( 'simulation_movement').getRelativeUrl() property = divergence.getProperty('tested_property') divergence_dict['%s&%s' % (simulation_movement_url, property)] = divergence for listbox in [ state_change['kwargs'].get('line_group_listbox'), state_change['kwargs'].get('cell_group_listbox')
from Products.DCWorkflow.DCWorkflow import ValidationFailed from Products.ERP5Type.Message import translateString kwargs = state_change['kwargs'] password = kwargs['password'] password_confirm = kwargs['password_confirm'] if password != password_confirm: raise ValidationFailed(translateString('Passwords do not match.')) reference = kwargs['reference'] if not reference: raise ValidationFailed(translateString('User Login is not specified.'))
from Products.DCWorkflow.DCWorkflow import ValidationFailed from Products.ERP5Type.Message import translateString internal_invoice = state_change['object'] old_state = state_change['old_state'] if old_state.getId() == 'draft': if internal_invoice.InternalInvoiceTransaction_getAuthenticatedUserSection( ) == internal_invoice.getDestinationSection(): raise ValidationFailed( translateString("Your entity should not be destination.")) return state_change.getPortal().portal_workflow.accounting_workflow.scripts[ script.getId()](state_change)
# XXX: Duplicates Base_checkConsistency so proxy role is really effective. from Products.DCWorkflow.DCWorkflow import ValidationFailed message_list = [ x.getTranslatedMessage() for x in state_change['object'].checkConsistency() ] if message_list: raise ValidationFailed(message_list)
bank_account.getReference(), 'utf8'), bank_account_currency=unicode( bank_account.getPriceCurrencyReference(), 'utf8'))) source_currency = None source_section = line.getSourceSectionValue() if source_section is not None: source_currency = source_section.getProperty('price_currency') if source_currency == line.getResource(): if ((line.getSourceCredit() != line.getSourceInventoriatedTotalAssetCredit()) or (line.getSourceDebit() != line.getSourceInventoriatedTotalAssetDebit())): raise ValidationFailed( translateString("Source conversion should not be set.")) destination_currency = None destination_section = line.getDestinationSectionValue() if destination_section is not None: destination_currency = destination_section.getProperty( 'price_currency') if destination_currency == line.getResource(): if ((line.getDestinationCredit() != line.getDestinationInventoriatedTotalAssetCredit()) or (line.getDestinationDebit() != line.getDestinationInventoriatedTotalAssetDebit())): raise ValidationFailed( translateString("Destination conversion should not be set."))
# Check that it is possible to open the accounting date. from Products.DCWorkflow.DCWorkflow import ValidationFailed from Products.ERP5Type.Message import Message from DateTime import DateTime now = DateTime() accounting_date = state_change['object'] # Check that site is defined on accounting_date site_uid = accounting_date.getSiteUid() if site_uid is None: msg = Message(domain='ui',message="Sorry, the site is not defined") raise ValidationFailed (msg,) opened_date_list = accounting_date.portal_catalog(portal_type="Accounting Date", simulation_state="opened", default_site_uid=accounting_date.getSiteUid()) if len(opened_date_list) > 0: msg = Message(domain='ui',message="Sorry, another accounting date is already opened") raise ValidationFailed (msg,)