def create(cls: Type[T],
               entity: Entity,
               name: str,
               am_type: AMType,
               denomination: Denomination,
               description: Optional[str] = None,
               parent: Optional[T] = None,
               counter_party: Optional[Entity] = None,
               color: Optional[Color] = None) -> T:

        arguments = Account.CreateArguments(name, description, am_type, parent,
                                            denomination, counter_party, color)

        data = DataPackage.from_object(arguments)
        parameters = UrlParameters(entity_id=entity.id_)

        request = ApiRequest(path=Account._PATH,
                             method=HTTPMethod.POST,
                             credentials=entity.session,
                             data=data,
                             url_parameters=parameters)

        account = cls._decode(entity, request.response_data)

        return account
Exemplo n.º 2
0
    def update(
            self,
            name: Optional[str] = None,
            description: Optional[str] = None,
            owner: Optional[User] = None,
            permissions_graph: Optional[PermissionsGraph] = None) -> 'Entity':
        """
        Modify data describing this Entity. Returns this Entity, the Entity
        instance is not modified in place.
        """

        owner_id = None
        if owner is not None:
            owner_id = owner.id_

        update_arguments = Entity.UpdateArguments(
            self,
            name=name,
            description=description,
            owner_id=owner_id,
            permissions_graph=permissions_graph)

        data_package = DataPackage.from_object(data=update_arguments)

        request = ApiRequest(path=Entity.PATH,
                             method=HTTPMethod.PUT,
                             credentials=self._session,
                             data=data_package,
                             url_parameters=None)

        updated_entity = Entity.decode(request.response_data, self.session)

        return updated_entity
    def update(self: T,
               name: Optional[str] = None,
               am_type: Optional[AMType] = None,
               parent: Optional[T] = None,
               description: Optional[str] = None,
               denomination: Optional[Denomination] = None,
               counterparty: Optional[Entity] = None,
               color: Optional[Color] = None) -> 'Account':
        """
        Update this Account with new metadata.
        """

        arguments = Account.UpdateArguments(self, name, am_type, parent,
                                            description, denomination,
                                            counterparty, color)

        data = DataPackage.from_object(arguments)
        parameters = UrlParameters(entity_id=self.entity.id_)

        request = ApiRequest(path=Account._PATH,
                             method=HTTPMethod.PUT,
                             credentials=self.entity.session,
                             data=data,
                             url_parameters=parameters)

        account = Account._decode(self.entity, request.response_data)

        if account.id_ != self.id_:
            raise ApiError('Returned Account ID does not match request ID')

        return account
    def create(
        cls: Type[T],
        entity: Entity,
        name: str,
        code: str,
        exponent: int,
        description: Optional[str] = None,
        priority: Optional[int] = None
    ) -> T:

        arguments = CustomUnit.CreationArguments(
            code,
            name,
            exponent,
            priority,
            description
        )

        parameters = UrlParameters(entity_id=entity.id_)

        request = ApiRequest(
            path=CustomUnit._PATH,
            credentials=entity.session,
            method=HTTPMethod.POST,
            data=DataPackage.from_object(arguments),
            url_parameters=parameters
        )

        return CustomUnit._decode(entity, request.response_data)
    def update(self: T,
               time: Optional[datetime] = None,
               entries: Optional[List[Entry]] = None,
               denomination: Optional[Denomination] = None,
               description: Optional[str] = None) -> T:
        """Replace existing transaction data with supplied data."""

        arguments = Transaction.UpdateArguments(self, time, entries,
                                                denomination, description)

        data = DataPackage.from_object(arguments)
        parameters = UrlParameters(entity_id=self.entity.id_)

        request = ApiRequest(path=Transaction._PATH,
                             method=HTTPMethod.PUT,
                             credentials=self.entity.session,
                             data=data,
                             url_parameters=parameters)

        transaction = Transaction._decode(self.entity, request.response_data)

        if transaction.id_ != self.id_:
            raise ApiError('Mismatched response Trasaction ID - Fatal')

        return transaction
    def update(
        self,
        name: Optional[str] = None,
        code: Optional[str] = None,
        priority: Optional[int] = None,
        description: Optional[str] = None,
        exponent: Optional[str] = None
    ) -> None:
        """
        Replace existing Custom Unit data with supplied data. Parameters
        not supplied will default to existing values.
        """
        if name is None:
            name = self.name
        if code is None:
            code = self.code
        if priority is None:
            priority = self.priority
        if description is None:
            description = self.description
        if exponent is None:
            exponent = self.exponent

        assert isinstance(code, str)
        assert isinstance(priority, int)
        assert isinstance(description, str)
        assert isinstance(exponent, int)

        arguments = CustomUnit.UpdateArguments(
            self.id_,
            code,
            name,
            exponent,
            priority,
            description
        )

        parameters = UrlParameters(entity_id=self.entity.id_)

        request = ApiRequest(
            path=self._PATH,
            method=HTTPMethod.PUT,
            data=DataPackage.from_object(arguments),
            url_parameters=parameters,
            credentials=self.entity.session
        )

        return CustomUnit._decode(
            self.entity,
            request.response_data
        )
Exemplo n.º 7
0
    def create(cls: Type[T],
               session: Session,
               name: str,
               description: Optional[str],
               region: Optional[Region] = None) -> T:

        new_entity_arguments = cls.CreateArguments(name, description, region)

        request_data = DataPackage.from_object(new_entity_arguments)

        request = ApiRequest(Entity.PATH, HTTPMethod.POST, session,
                             request_data, None, False)

        created_entity = cls.decode(request.response_data, session)

        return created_entity
    def create(
        cls: Type[T],
        entity: Entity,
        time: datetime,
        entries: List[Entry],
        denomination: Denomination,
        description: Optional[str] = None,
    ) -> T:

        arguments = Transaction.CreateArguments(time, entries, denomination,
                                                description)

        data = DataPackage.from_object(arguments)
        parameters = UrlParameters(entity_id=entity.id_)

        request = ApiRequest(path=Transaction._PATH,
                             method=HTTPMethod.POST,
                             credentials=entity.session,
                             data=data,
                             url_parameters=parameters)

        transaction = cls._decode(entity, request.response_data)

        return transaction