Exemple #1
0
    def clear_credit(self, amount_to_pay):
        """Check if expenses on credit are cleared"""
        if not self.on_credit:
            raise Exception('This is not a credit expense')

        paid = self.credit['paid']
        actual_bal = self.credit['balance']
        count = self.credit['payments']

        balance = float(self.amount) - (float(paid) + float(amount_to_pay))

        self.credit_status = 'PAID' if int(balance) == 0 else 'PARTIAL'
        app.logger.info(self.credit_status)

        if balance < 0.0:
            raise Exception('Amount {0}, Actual {1}, Balance {2}'.format(
                commas(self.amount), commas(actual_bal), commas(balance)))
        else:
            entry = Entry.init_expense(self)
            entry.amount = amount_to_pay
            entry.reference = self.uuid + str(count)
            entry.transact()
    def clear_credit(self, amount_to_pay):
        """Check if expenses on credit are cleared"""
        if not self.on_credit:
            return

        paid = self.credit['paid']
        actual_bal = self.credit['balance']
        count = self.credit['payments']

        balance = float(self.amount) - (float(paid) + float(amount_to_pay))

        self.credit_status = 'PAID' if int(balance) == 0 else 'PARTIAL'

        if balance < 0.0:
            raise Exception(
                'Amount to pay should not be greater than the balance {2}'.
                format(commas(actual_bal)))
        else:
            exp = Expenditure.get(reference=self.uuid)
            exp.amount = amount_to_pay
            exp.pay_type = self.pay_type
            entry = Entry.init_expenditure(exp)
            entry.reference = self.uuid + str(count)
            entry.transact()
Exemple #3
0
    def is_valid(self):
        """validate the object"""

        if self.category not in ('sale', 'purchase'):
            return False, {"msg": "The category {0} doesn't exist".format(self.tran_type)}, 422
        if not Item.get(uuid=self.credit) and not Item.get(uuid=self.debit):
            return False, {"msg": "The supplied item id does not exist"}, 422
        if ItemLog.get(reference=self.reference):
            return False, {"msg": "The supplied reference already exists"}, 409
        if ItemLog.get(reference=self.cheque_number):
            return False, {"msg": "This transaction is already reversed"}, 409
        if self.category == "reversal" and not ItemLog.get(
                reference=self.cheque_number
        ):
            return False, {"msg": "You can only reverse an existing transaction"}, 422

        # check balance
        item = Item.get(uuid=self.debit)
        bal_after = int(item.quantity) - int(self.quantity)
        app.logger.info(item.quantity, self.quantity)

        if Item.get(uuid=self.item_id).name != 'labour' and self.category == 'sale' and float(bal_after) < 0.0:
            return False, {
                "msg": "Insufficient quantity on the {0} account {1}".format(item.name, commas(item.quantity))}, 409

        if self.tran_type == "reversal":
            orig = ItemLog.get(reference=self.cheque_number)
            self.debit = orig.credit
            self.credit = orig.debit
            self.amount = orig.amount
            self.entity_id = orig.entity_id

        return True, self, 200
Exemple #4
0
    def is_valid(self):
        """validate the object"""
        
        if not TransactionType.get(uuid=self.tran_type):
            return False, {"msg": "The transaction type {0} doesn't exist".format(self.tran_type)}, 422
        if not Account.get(id=self.credit) and not Account.get(id=self.debit):
            return False, {"msg": "The supplied account id does not exist"}, 422
        if Entry.get(reference=self.reference):
            return False, {"msg": "The supplied reference already exists"}, 409
        if Entry.get(reference=self.cheque_number):
            return False, {"msg": "This transaction is already reversed"}, 409
        if self.tran_type == "reversal" and not Entry.get(
                reference=self.cheque_number
            ):
            return False, {"msg": "You can only reverse an existing transaction"}, 422
        
        # check balance
        account = Account.get(id=self.debit)
        bal_after = int(account.balance) - int(self.amount)
        app.logger.info(self.amount)

        if account.minimum_balance is not None and float(bal_after) < float(account.minimum_balance):
            return False, {"msg": "Insufficient balance on {0} account {1}".format(account.name,commas(account.balance))}, 409

        if self.tran_type == "reversal":
            orig = Entry.get(tranid=self.cheque_number)
            self.debit = orig.credit
            self.credit = orig.debit
            self.amount = orig.amount
            self.entity_id = orig.entity_id

        
        return True, self, 200