def set_movements(self, movements_specs: List[MovementSpec]) -> None: """ Set's movements, using an iterable of MovementSpec """ TransactionMovementSpecListValidator().validate(movements_specs) self.movement_set.all().delete() for mov_spec in movements_specs: self._convert_specs(mov_spec) full_clean_and_save(self)
def set_parent(self, parent: Account) -> None: if parent is None: msg = {'parent': self.ERR_MSGS['NULL_PARENT']} raise ValidationError(msg) if not parent.allows_children(): msg = self.ERR_MSGS['PARENT_CHILD_NOT_ALLOWED'] raise ValidationError({'parent': msg.format(parent)}) self.parent = parent full_clean_and_save(self)
def _convert_specs(self, mov_spec: MovementSpec) -> MovementSpec: """ Converts a MovementSpec into a Movement for self. """ return full_clean_and_save( Movement(account=mov_spec.account, transaction=self, currency=mov_spec.money.currency, quantity=round_decimal(mov_spec.money.quantity)))
def __call__(self, description: str, date_: datetime.date, movements_specs: List[MovementSpec]) -> Transaction: """ Creates a new Transaction. `movements_specs` should be a list of MovementSpec describing the movements for this transaction. """ trans = full_clean_and_save( Transaction(description=description, date=date_)) trans.set_movements(movements_specs) return trans
def __call__( self, name: str, acc_type: AccTypeEnum, parent: Account ) -> Account: """ Creates a new account. `acc_type` must be one of AccTypeEnum, and `parent` must be an Account """ assert acc_type in AccTypeEnum acc_type_obj = AccountType.objects.get(name=acc_type.value) self._validate_acc_type_obj(acc_type_obj) acc = Account( name=name, acc_type=acc_type_obj, ) acc.full_clean() acc.set_parent(parent) return full_clean_and_save(acc)
def set_name(self, x: str) -> None: self.name = x full_clean_and_save(self)
def __call__(self, name: str) -> Currency: """ Creates a currency using name """ return full_clean_and_save(Currency(name=name))
def set_date(self, x: datetime.date) -> None: self.date = x full_clean_and_save(self)
def set_description(self, x: str) -> None: self.description = x full_clean_and_save(self)