def confirm(self, **kwargs): """Confirm LeadOrder and set availability dates.""" leadorder = self.document project = leadorder.project if not lead_confirmation_enabled(str(project.id)): raise WorkflowTransitionException( 'Lead order confirmation is not enabled') needed_fields = project.leadorder_confirmation_fields or [] fields = kwargs.get('fields', {}) for fieldname in needed_fields: value = fields.get(fieldname, []) if not value: raise WorkflowTransitionException( f'Field {fieldname} is required for this transition') else: payload = {fieldname: value} try: leadorder.update(payload) except ValidationError as exc: raise WorkflowTransitionException(exc.message) # Set actual_order_price leadorder.actual_order_price = leadorder.price # Set the current type to order leadorder.current_type = 'order' if not leadorder.assignments: create_new_assignment_from_order(leadorder, leadorder.request)
def order_created_handler(event): """Handle Order created event.""" order = event.obj request = event.request project = order.project # First set price and price_currency based on the project price = request.validated.get('price') or project.price order.price = price order.actual_order_price = price price_currency = project.price_currency order.price_currency = price_currency if not order.asset_types: order.asset_types = project.asset_types[:1] add_roles = ('customer_users', 'project_managers') apply_local_roles_from_parent(order, project, add_roles) location = request.validated.get('location', None) if not order.location and location: # force this because sometimes the obj.id is not available before the flush order.location = location # submit the order order.workflow.submit() create_new_assignment_from_order(order, request) cache_manager.refresh(order)
def remove_availability(self, **kwargs): """Transition: Inform the removal of availability dates to the customer.""" order = self.document order.availability = [] if order.state in ('assigned', 'scheduled'): old_assignment = order.assignments[-1] # this will handle the creation of a new Assignment message = kwargs.get('message', '') create_new_assignment_from_order(order, order.request, copy_payout=True) old_assignment.workflow.cancel(message=message) return True
def new_shoot(self, **kwargs): """Transition: Inform the new shoot of an Order the customer.""" message = kwargs.get('message', '') order = self.document order.availability = [] old_assignment = order.assignments[-1] create_new_assignment_from_order(order, order.request, copy_payout=True, old_assignment=old_assignment) fields = kwargs.get('fields') old_assignment.payout_value = fields.get('payout_value') old_assignment.travel_expenses = fields.get('travel_expenses') old_assignment.workflow.complete(message=message) return True
def reshoot(self, **kwargs): """Transition: Inform the reshoot of the Order the customer.""" message = kwargs.get('message', '') order = self.document order.availability = [] old_assignment = order.assignments[-1] # copy payout is not necessary in this case new_assignment = create_new_assignment_from_order(order, order.request) # prepare kwargs to assign the new assignment # explicit payout values are mandatory to assign transition # save original fields to use it to update old_assignment with posted values post_fields = kwargs['fields'] kwargs.update(message=ASSIGN_AFTER_RENEWSHOOT) kwargs['fields'] = dict(professional_id=old_assignment.professional_id, payout_value=old_assignment.payout_value, payout_currency=old_assignment.payout_currency, travel_expenses=old_assignment.travel_expenses) # update old assignment and complete old_assignment.payout_value = post_fields.get('payout_value') old_assignment.travel_expenses = post_fields.get('travel_expenses') old_assignment.workflow.complete(message=message) # after complete the old assignment the new one can be assigned if new_assignment.state == 'created': new_assignment.workflow.context = order.workflow.context new_assignment.workflow.submit() new_assignment.workflow.assign(**kwargs)
def perm_reject(self, **kwargs): """Transition: Inform the perm rejection of the Assignment. Move Order to pending state for a new shoot. """ order = self.document order.availability = [] old_assignment = order.assignment create_new_assignment_from_order(order, order.request, copy_payout=True, old_assignment=old_assignment) # force no None value for reason if kwargs['fields']['reason_additional_compensation'] == 'null': kwargs['fields']['reason_additional_compensation'] = None kwargs['fields']['additional_compensation'] = 0 old_assignment.workflow.perm_reject(**kwargs) return True
def unassign(self, **kwargs): """Transition: Un-assign the Order by cancel the Assignment and create a new one.""" order = self.document old_assignment = order.assignments[-1] if not old_assignment.workflow.can_cancel: upload = True if old_assignment.submission_path else False if upload: msg = ('It is not possible to unassign this order because the ' 'assignment already have a submission.') else: msg = ('It is not possible to unassign this order because the ' 'current assignment does not support a cancellation.') raise WorkflowTransitionException(msg) message = kwargs.get('message', '') create_new_assignment_from_order(order, order.request, copy_payout=True, old_assignment=old_assignment) old_assignment.workflow.cancel(message=message) return True
def reassign(self, **kwargs): """Transition: Inform the reassignment to the customer.""" order = self.document user_id = str(self.context.id) order.scout_manager = user_id old_assignment = order.assignment message = kwargs.get('message', '') old_assignment.workflow.cancel(message=message) new_assignment = create_new_assignment_from_order(order, order.request) # pass message and fields to the assign transition of the Assignment new_assignment.workflow.assign(**kwargs) return True