def patch(self): """Contract Edit (partial) """ contract = self.request.validated['contract'] if self.request.authenticated_role != 'Administrator' and contract.status != 'active': self.request.errors.add( 'body', 'data', 'Can\'t update contract in current ({}) status'.format( contract.status)) self.request.errors.status = 403 return apply_patch(self.request, save=False, src=self.request.validated['contract_src']) if contract.status == 'terminated' and not contract.amountPaid: self.request.errors.add( 'body', 'data', 'Can\'t terminate contract while \'amountPaid\' is not set') self.request.errors.status = 403 return if save_contract(self.request): self.LOGGER.info( 'Updated contract {}'.format(contract.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'contract_patch'})) return {'data': contract.serialize('view')}
def patch(self): """ Contract change edit """ change = self.request.validated['change'] data = self.request.validated['data'] if change.status == 'active': self.request.errors.add( 'body', 'data', 'Can\'t update contract change in current ({}) status'.format( change.status)) self.request.errors.status = 403 return if 'status' in data and data[ 'status'] != change.status: # status change if not data.get("dateSigned", ''): self.request.errors.add( 'body', 'data', 'Can\'t update contract change status. \'dateSigned\' is required.' ) self.request.errors.status = 403 return change['date'] = get_now() apply_patch(self.request, save=False, src=change.serialize()) if change['dateSigned']: contract = self.request.validated['contract'] changes = contract.get("changes", []) if len(changes) > 1: # has previous changes last_change = contract.changes[:-1][-1] last_date_signed = last_change.dateSigned if not last_date_signed: # BBB old active changes last_date_signed = last_change.date obj_str = "last active change" else: last_date_signed = contract.dateSigned obj_str = "contract" if last_date_signed: # BBB very old contracts if change['dateSigned'] < last_date_signed: self.request.errors.add( 'body', 'data', 'Change dateSigned ({}) can\'t be earlier than {} dateSigned ({})' .format(change['dateSigned'].isoformat(), obj_str, last_date_signed.isoformat())) self.request.errors.status = 403 return if save_contract(self.request): self.LOGGER.info( 'Updated contract change {}'.format(change.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'contract_change_patch'})) return {'data': change.serialize('view')}
def patch(self): """Contract Edit (partial) """ contract = self.request.validated['contract'] apply_patch(self.request, save=False, src=self.request.validated['contract_src']) validate_terminate_contract_without_amountPaid(self.request) if save_contract(self.request): self.LOGGER.info('Updated contract {}'.format(contract.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'contract_patch'})) return {'data': contract.serialize('view')}
def patch(self): """Contract Edit (partial) """ contract = self.request.validated["contract"] apply_patch(self.request, save=False, src=self.request.validated["contract_src"]) validate_terminate_contract_without_amountPaid(self.request) validate_update_contracting_items_unit_value_amount(self.request) if save_contract(self.request): self.LOGGER.info( "Updated contract {}".format(contract.id), extra=context_unpack(self.request, {"MESSAGE_ID": "contract_patch"}), ) return {"data": contract.serialize("view")}
def patch(self): """Contract Edit (partial) """ contract = self.request.validated['contract'] apply_patch(self.request, save=False, src=self.request.validated['contract_src']) validate_terminate_contract_without_amountPaid(self.request) if save_contract(self.request): self.LOGGER.info( 'Updated contract {}'.format(contract.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'contract_patch'})) return {'data': contract.serialize('view')}
def patch(self): """Contract Document Update""" if apply_patch(self.request, src=self.request.context.serialize()): update_file_content_type(self.request) self.LOGGER.info('Updated contract document {}'.format(self.request.context.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'contract_document_patch'})) return {'data': self.request.context.serialize("view")}
def patch(self): """Contract Document Update""" if apply_patch(self.request, src=self.request.context.serialize()): update_file_content_type(self.request) self.LOGGER.info( 'Updated contract document {}'.format(self.request.context.id), extra=context_unpack( self.request, {'MESSAGE_ID': 'contract_document_patch'})) return {'data': self.request.context.serialize("view")}
def patch(self): """Contract Document Update""" if apply_patch(self.request, src=self.request.context.serialize()): update_file_content_type(self.request) self.LOGGER.info( "Updated contract document {}".format(self.request.context.id), extra=context_unpack( self.request, {"MESSAGE_ID": "contract_document_patch"}), ) return {"data": self.request.context.serialize("view")}
def patch(self): """ Contract change edit """ change = self.request.validated["change"] data = self.request.validated["data"] if "status" in data and data[ "status"] != change.status: # status change validate_update_contract_change_status(self.request) change["date"] = get_now() apply_patch(self.request, save=False, src=change.serialize()) if change["dateSigned"]: contract = self.request.validated["contract"] changes = contract.get("changes", []) if len(changes) > 1: # has previous changes last_change = contract.changes[:-1][-1] last_date_signed = last_change.dateSigned if not last_date_signed: # BBB old active changes last_date_signed = last_change.date obj_str = "last active change" else: last_date_signed = contract.dateSigned obj_str = "contract" if last_date_signed: # BBB very old contracts if change["dateSigned"] < last_date_signed: # Can't move validator because of code above raise_operation_error( self.request, "Change dateSigned ({}) can't be earlier than {} dateSigned ({})" .format(change["dateSigned"].isoformat(), obj_str, last_date_signed.isoformat()), ) if save_contract(self.request): self.LOGGER.info( "Updated contract change {}".format(change.id), extra=context_unpack(self.request, {"MESSAGE_ID": "contract_change_patch"}), ) return {"data": change.serialize("view")}
def patch(self): """Contract Edit (partial) """ contract = self.request.validated['contract'] if self.request.authenticated_role != 'Administrator' and contract.status != 'active': self.request.errors.add('body', 'data', 'Can\'t update contract in current ({}) status'.format(contract.status)) self.request.errors.status = 403 return apply_patch(self.request, save=False, src=self.request.validated['contract_src']) if contract.status == 'terminated' and not contract.amountPaid: self.request.errors.add('body', 'data', 'Can\'t terminate contract while \'amountPaid\' is not set') self.request.errors.status = 403 return if save_contract(self.request): self.LOGGER.info('Updated contract {}'.format(contract.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'contract_patch'})) return {'data': contract.serialize('view')}
def patch(self): """Contract Edit (partial) """ contract = self.request.validated['contract'] data = self.request.validated['data'] if 'status' in data and data['status'] != contract.status: # if status change # old status vs new status if contract.status not in ['draft', 'active'] or data['status'] not in ['active', 'terminated']: self.request.errors.add('body', 'data', 'Can\'t update contract status') self.request.errors.status = 403 return elif contract.status != 'active': self.request.errors.add('body', 'data', 'Can\'t update contract in current ({}) status'.format(contract.status)) self.request.errors.status = 403 return apply_patch(self.request, src=self.request.validated['contract_src']) self.LOGGER.info('Updated contract {}'.format(contract.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'contract_patch'})) return {'data': contract.serialize('view')}
def patch(self): """ Contract change edit """ change = self.request.validated['change'] data = self.request.validated['data'] if 'status' in data and data[ 'status'] != change.status: # status change validate_update_contract_change_status(self.request) change['date'] = get_now() apply_patch(self.request, save=False, src=change.serialize()) if change['dateSigned']: contract = self.request.validated['contract'] changes = contract.get("changes", []) if len(changes) > 1: # has previous changes last_change = contract.changes[:-1][-1] last_date_signed = last_change.dateSigned if not last_date_signed: # BBB old active changes last_date_signed = last_change.date obj_str = "last active change" else: last_date_signed = contract.dateSigned obj_str = "contract" if last_date_signed: # BBB very old contracts if change['dateSigned'] < last_date_signed: # Can't move validator because of code above raise_operation_error( self.request, 'Change dateSigned ({}) can\'t be earlier than {} dateSigned ({})' .format(change['dateSigned'].isoformat(), obj_str, last_date_signed.isoformat())) if save_contract(self.request): self.LOGGER.info( 'Updated contract change {}'.format(change.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'contract_change_patch'})) return {'data': change.serialize('view')}
def patch(self): """Contract Document Update""" if self.request.validated['contract'].status != 'active': self.request.errors.add('body', 'data', 'Can\'t update document in current ({}) contract status'.format( self.request.validated['contract'].status)) self.request.errors.status = 403 return if apply_patch(self.request, src=self.request.context.serialize()): update_file_content_type(self.request) self.LOGGER.info('Updated contract document {}'.format(self.request.context.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'contract_document_patch'})) return {'data': self.request.context.serialize("view")}
def patch(self): """ Contract change edit """ change = self.request.validated['change'] data = self.request.validated['data'] if 'status' in data and data['status'] != change.status: # status change if data['status'] != 'active': self.request.errors.add('body', 'data', 'Can\'t update contract change in current ({}) status'.format(change.status)) self.request.errors.status = 403 return change['date'] = get_now() if apply_patch(self.request, src=change.serialize()): self.LOGGER.info('Updated contract change {}'.format(change.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'contract_change_patch'})) return {'data': change.serialize('view')}
def patch(self): """Contract Document Update""" if self.request.validated['contract'].status != 'active': self.request.errors.add('body', 'data', 'Can\'t update document in current ({}) contract status'.format( self.request.validated['contract'].status)) self.request.errors.status = 403 return data = self.request.validated['data'] if "relatedItem" in data and data.get('documentOf') == 'change': if not [1 for c in self.request.validated['contract'].changes if c.id == data['relatedItem'] and c.status == 'pending']: self.request.errors.add('body', 'data', 'Can\'t add document to \'active\' change') self.request.errors.status = 403 return if apply_patch(self.request, src=self.request.context.serialize()): update_file_content_type(self.request) self.LOGGER.info('Updated contract document {}'.format(self.request.context.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'contract_document_patch'})) return {'data': self.request.context.serialize("view")}
def patch(self): """Contract Document Update""" if self.request.validated['contract'].status != 'active': self.request.errors.add('body', 'data', 'Can\'t update document in current ({}) contract status'.format( self.request.validated['contract'].status)) self.request.errors.status = 403 return data = self.request.validated['data'] if "relatedItem" in data and data.get('documentOf') == 'change': if not [1 for c in self.request.validated['contract'].changes if c.id == data['relatedItem'] and c.status == 'pending']: self.request.errors.add('body', 'data', 'Can\'t add document to \'active\' change') self.request.errors.status = 403 return if apply_patch(self.request, src=self.request.context.serialize()): update_file_content_type(self.request) self.LOGGER.info('Updated contract document {}'.format(self.request.context.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'contract_document_patch'})) return {'data': self.request.context.serialize("view")}
def apply(self, request, **kwargs): return apply_patch(request, **kwargs)