Esempio n. 1
0
    def accountInterestEod():
        print("Account Interest")
        interest_per_annam = 0.05
        debit_interest = 0.15
        all_accounts = session.query(Customer).all()
        for i in all_accounts:
            date = Getters.getSysDate().date  # time.strftime('%Y-%m-%d')
            print("Interest for date: " + date)
            acc = i.acc_number
            print("Account picked is: " + str(acc))
            eod_bal = float(i.working_bal)
            print("Working balance is: " + str(eod_bal))
            if i.working_bal > 0:
                # interest charges on credit balances
                interest = (interest_per_annam / 365) * eod_bal
            else:
                # interest charged on negative balances
                interest = (debit_interest / 365) * eod_bal
            print("Interest Charges: " + str(interest))
            table_update = Interest(date=date,
                                    account=acc,
                                    eod_bal=round(eod_bal, 2),
                                    interest_earned=round(interest, 4))
            session.add(table_update)
            print("Record Account " + date + " || " + str(acc) + " || " + str(
                eod_bal) + " ==== daily interest ----" + str(interest) + " Updated on date : ----" + date)

        session.commit()
        print("Account interest Calculation complete")
Esempio n. 2
0
    def ttUpdate(t_type, amount, tran_date, tran_ref, acc_num):
        """
        when a withdrawal or a deposit is done this is how the till is affected

        :param t_type:
        :param amount:
        :param tran_date:
        :param tran_ref:
        :param acc_num:
        :return:
        """
        customer = session.query(Customer).filter_by(
            acc_number=acc_num).first()
        print("Till Details: {}".format(Getters.getTillDetails()))
        till_detail = session.query(Till).filter_by(
            till_account=Getters.getTillDetails().till_account).first()

        tt = TellerTransactions(
            tran_type=t_type.value,  # CR or DR
            tranref=Auto.reference_string_generator(),
            amount=amount,
            date=tran_date,
            remark=tran_ref,
            create_date=datetime.datetime.now(),
            teller_id=till_detail.id,
            customer_id=customer.custid,
            user_id=Profile().user_details().uid)
        session.add(tt)
        session.commit()
        pass
Esempio n. 3
0
def create_system_currencies():
    currencies = [{
        "currency_code": "USD",
        "description": "United States Dollar"
    }, {
        "currency_code": "ZAR",
        "description": "South African Rand"
    }, {
        "currency_code": "GBP",
        "description": "Great Britain Pound"
    }]

    for currency in currencies:
        code = currency.get("currency_code")
        description = currency.get("description")
        if code not in [
                c.currency_code for c in session.query(Currency).all()
        ]:
            new_currency = Currency(currency_code=code,
                                    description=description,
                                    create_date=datetime.datetime.now())
            session.add(new_currency)
            session.commit()
        else:
            continue
Esempio n. 4
0
def create_banking_services():
    service_dictionary = [{
        "service_name": "Pay",
        "service_description": "for payments"
    }, {
        "service_name":
        "Transfer",
        "service_description":
        "Transfer funds to local banks"
    }, {
        "service_name": "CashSend",
        "service_description": "E-wallet services"
    }, {
        "service_name": "Bill Payments",
        "service_description": "Bill Payments"
    }]
    for service in service_dictionary:

        service_n = service.get("service_name")
        service_d = service.get("service_description")

        if service_n not in [
                s.service_name
                for s in session.query(BankingServices).filter_by(
                    service_name=service_n).all()
        ]:
            service_record = BankingServices(service_name=service_n,
                                             service_description=service_d)
            print("Banking service: {} create".format(service_n))
            session.add(service_record)
            session.commit()
        else:
            continue
Esempio n. 5
0
    def create_account(self):

        """
        this method does not take any parameter. it create a new account and associates it to the
        customer ID for the new customer created
        :return: 0 for exception, 1 for account created
        """
        # suspense_account = session.query(Customer).filter_by(account_type='acccreate').first()
        try:
            customer = session.query(Customer).filter_by(acc_number=self.cr_account).one()
        except ValueError as value_error:
            print(value_error)
            SystemOBS().start_logging(value_error)
            return 0
        # Update transactions Table
        CommitTransaction(trans_type=TransactionType.CREDIT.value,
                          trans_ref=References().get_transaction_reference,
                          trans_method=TransactionMethod.CASH.value,
                          cheque_number='None',
                          dr_account_number=self.suspense_account_new_account.acc_number,
                          cr_account_number=self.cr_account,
                          amount=self.amount,
                          current_balance=round(self.amount, 2),
                          remark='Account Creation',
                          customer_id=customer.custid) \
            .commit_to_database()

        # update the Account creation Suspense Account
        self.suspense_account_new_account.working_bal -= self.amount
        session.add(self.suspense_account_new_account)
        session.commit()
        SystemOBS.start_logging("Account Created: " + str(customer.acc_number))
        return 1
Esempio n. 6
0
    def deposit(self, transaction_reference):
        """
        This method takes an additional parameter @transaction_reference for a deposit transaction
        to be saved in the database.
            - A deposit affects the Teller Till account, this means theTeller Account is debited
            and Customer account credited.
        """
        customer = session.query(Customer).filter_by(acc_number=self.cr_account).one()
        current_balance = float(self.amount) + float(customer.working_bal)
        trans_ref = References().get_transaction_reference

        CommitTransaction(trans_type=TransactionType.CREDIT.value,
                          trans_ref=trans_ref,
                          trans_method=TransactionMethod.CASH.value,
                          trans_date=self.date,
                          cheque_number='None',
                          dr_account_number=self.suspense_account_teller.till_account,
                          cr_account_number=self.cr_account,
                          amount=self.amount,
                          current_balance=round(current_balance, 2),
                          remark='Deposit_' + transaction_reference,
                          customer_id=customer.custid).commit_to_database()

        # Update customers working balance
        customer.working_bal = round(current_balance, 2)
        session.add(customer)
        session.commit()
        # -------------------------------

        # Update Till Opening/Closing   Balance
        self.suspense_account_teller.c_balance -= round(float(self.amount), 2)
        session.add(self.suspense_account_teller)
        session.commit()
Esempio n. 7
0
def create_transaction_charge_type():
    charge_types = [{
        "tran_type": "CR",
        "tran_charge": 0
    }, {
        "tran_type": "DR",
        "tran_charge": 1.50
    }, {
        "tran_type": "TR",
        "tran_charge": 1.0
    }, {
        "tran_type": "RTGS",
        "tran_charge": 5.0
    }, {
        "tran_type": "SF",
        "tran_charge": 3.0
    }]

    for charge in charge_types:
        trans_type = charge.get("tran_type")
        trans_charge = charge.get("tran_charge")
        if trans_type not in [
                chg.tran_type
                for chg in session.query(TransactionCharge).all()
        ]:
            new_charge = TransactionCharge(tran_type=trans_type,
                                           tran_charge=trans_charge)
            session.add(new_charge)
            session.commit()
            print("Charge Type created")
        else:
            continue
Esempio n. 8
0
    def _create_user(cls, slack_id=None, username=None, first_name=None, real_name=None, *args, **kwargs):
        user = User()
        if not slack_id:
            slack_id = 'U%s' % str(uuid.uuid4())[:6]
        user.slack_id = slack_id

        if not username:
            username = str(uuid.uuid4())[:10]
        user.username = username

        if not first_name:
            first_name = str(uuid.uuid4())[:8]
        user.first_name = first_name

        if not real_name:
            real_name = str(uuid.uuid4())[:8]
        user.real_name = real_name

        for key, value in kwargs.iteritems():
            setattr(user, key, value)

        session.add(user)
        session.flush()
        session.commit()
        return user
Esempio n. 9
0
    def write_coupons_to_db(self, id):
        # self.process_wordai()
        with app.app_context():
            for row in self.coupons:
                coupon = Coupon(
                    original_title=row.get('original_title'),
                    title=row.get('original_title'),
                    original_description=row.get('original_description'),
                    description=row.get('original_description'),
                    price=row.get('price'),
                    expiry_date=row.get('expiry_date'),
                    url=row.get('url'),
                    code=row.get('code'),
                    store_id=id)
                session.add(coupon)

            try:
                session.commit()
            except Exception as e:
                print(str(e))
                session.rollback()

            store = Store.query.get(id)
            store.status = StoreStatus.done
            store.job_uid = None

            try:
                session.commit()
                return True
            except Exception as e:
                print(str(e))
                session.rollback()
                return False
Esempio n. 10
0
File: eom.py Progetto: trustmub/OBS
 def accountInterestEom():
     # Calculates the total interest for each account in the interest table
     # Credits the account with the interest credits the interests account
     # update the transaction table appropriately
     sys_date = datetime.datetime.strptime(Getters.getSysDate().date, '%Y-%m-%d')
     mo = sys_date.strftime('%m')
     all_accounts = session.query(Customer).all()
     if session.query(CobDates).filter_by(date=sys_date).filter_by(process='ai').first():
         print("Account interest has already run")
     else:
         for i in all_accounts:
             account = i.acc_number
             selector = session.query(Interest).filter_by(account=account).filter(
                 extract('month', Interest.date) == mo).all()
             total = 0
             for x in selector:
                 total += round(x.interest_earned, 2)
             tot = round(total, 2)
             i.working_bal += tot
             print("Account {} working balance upadated".format(i.working_bal))
             session.add(i)
             session.commit()
             TransactionUpdate.accInterestUpdate(account, tot, i.working_bal, i.custid)
             print("Account interest updated for Account {} Amount: ${} working balance now ${}".format(account, tot, i.working_bal))
         new = CobDates(date=sys_date,
                        process='ai',
                        status=1,
                        create_date=datetime.datetime.now())
         print("Cob Process for Account Interest done")
         session.add(new)
         session.commit()
     pass
Esempio n. 11
0
    def accCreationCash(date, amount, acc_num):
        # establish the account for account creation
        acc_creation_sus_acc = session.query(Customer).filter_by(
            account_type='acccreate').first()

        cus = session.query(Customer).filter_by(acc_number=acc_num).one()
        # Update transactions Table
        trans = Transactions(trantype='CR',
                             tranref=Auto.reference_string_generator(),
                             tranmethod='Cash',
                             tran_date=date,
                             cheque_num='None',
                             acc_number=acc_creation_sus_acc.acc_number,
                             cr_acc_number=acc_num,
                             amount=amount,
                             current_balance=round(amount, 2),
                             remark='Account Creation',
                             custid=cus.custid)
        session.add(trans)
        session.commit()

        # update the Account creation Suspanse Account
        acc_creation_sus_acc.working_bal -= amount
        session.add(acc_creation_sus_acc)
        session.commit()
        # ---------------------------------------------

        pass
Esempio n. 12
0
File: eom.py Progetto: trustmub/OBS
 def serviceFeesEom():
     if Getters.getCobDates(Getters.getSysDate().date):
         if session.query(CobDates).filter_by(process='sf').filter_by(status=1):
             print("service process skipped")
             pass
         else:
             print("Effect the process table")
             pass
     else:
         charge = session.query(TransactionCharge).filter_by(tran_type='SF').first()
         all_accounts = session.query(Customer).all()
         for i in all_accounts:
             if i.contact_number == '09100000' or i.account_type == 'Student':
                 print("account {} passed. Account Type is {}".format(i.acc_number, i.account_type))
                 pass
             else:
                 account = i.acc_number
                 # record = session.query(Customer).filter_by(acc_number=account).first()
                 # update an EOM transaction update
                 TransactionUpdate.eomServfeeTransactionUpdate(account, Getters.getSysDate().date, charge.tran_charge)
                 print("Transaction updated " + str(account) + " " + str(charge.tran_charge) + " " + str(Getters.getSysDate().date) + " record effected")
                 # TransactionUpdate.accChargeUpdate('SF', account, Getters.getSysDate().date)
                 ChargeTransaction(Getters.getSysDate().date, account).charges(TransactionType.SERVICE_FEE)
                 print("Charge effected for account {}".format(account))
         new = CobDates(date=Getters.getSysDate().date,
                        process='sf',
                        status=1,
                        create_date=datetime.datetime.now())
         session.add(new)
         session.commit()
         print("Process table updated")
Esempio n. 13
0
def amend_cus():
    record = None
    if request.method == 'POST':
        acc_num = int(request.form['acc_number'])
        if Verify.account_exists(acc_num):

            a_record = session.query(Customer).filter_by(
                acc_number=acc_num).one()
            if request.form['first_name'] == a_record.first_name:
                pass
            else:
                a_record.first_name = request.form['first_name']
            if request.form['last_name'] == a_record.last_name:
                pass
            else:
                a_record.last_name = request.form['last_name']
            if request.form['dob'] == a_record.dob:
                pass
            else:
                a_record.dob = request.form['dob']
            if request.form['gender'] == a_record.gender:
                pass
            else:
                a_record.gender = request.form['gender']
            if request.form['contact_number'] == a_record.contact_number:
                pass
            else:
                a_record.contact_number = int(request.form['contact_number'])
            if request.form['email'] == a_record.email:
                pass
            else:
                a_record.email = request.form['email']
            if request.form['address'] == a_record.address:
                pass
            else:
                a_record.address = request.form['address']
            if request.form['country'] == a_record.country:
                pass
            else:
                a_record.country = request.form['country']
            if request.form['account_type'] == a_record.account_type:
                pass
            else:
                a_record.account_type = request.form['account_type']
            a_record.create_date = a_record.create_date

            session.add(a_record)
            session.commit()
            return redirect(
                url_for('customer.my_cus', user=Profile().user_details()))
        else:
            flash('Account Cannot be modified, Search Again')
            record = None
            return redirect(url_for('customer.amend_cus'))
    else:
        return render_template('customer/amend_cus.html',
                               record=record,
                               user=Profile().user_details(),
                               account=Getters.getAccountType())
Esempio n. 14
0
    def withdrawal(self, transaction_reference):
        """
        this methods takes in transaction reference generated at the point of withdrawal and save
        the record in the Transaction table. in a withdrawal, two transaction record are created,
        one for the debited account and the other for the credited account.

            - A withdrawal affects the Tellers till balance, this means the Teller account will be
            credited and customer account debited """
        customer = session.query(Customer).filter_by(acc_number=self.cr_account).one()

        current_balance = float(customer.working_bal) - float(self.amount)
        main_withdrawal_transaction \
            = Transactions(trantype='DR',
                           tranref=transaction_reference,
                           tranmethod='Cash',
                           tran_date=self.date,
                           cheque_num='None',
                           acc_number=int(self.cr_account),
                           cr_acc_number=int(self.suspense_account_teller.till_account),
                           amount=self.amount,
                           current_balance=round(current_balance, 2),
                           remark='Withdrawal ' + transaction_reference,
                           custid=customer.custid)
        session.add(main_withdrawal_transaction)
        session.commit()
        # update customer working balance
        customer.working_bal = round(current_balance, 2)
        session.add(customer)
        session.commit()
        # -------------------------------
        # Update Till Opening/Closing balance
        self.suspense_account_teller.c_balance += round(self.amount, 2)
        session.add(self.suspense_account_teller)
        session.commit()
        # -------------------------------

        # 2. charge details between customer and charge account
        # charge_account = session.query(Customer).filter_by(account_type='charges').first()
        get_charge = session.query(TransactionCharge).filter_by(tran_type=TransactionType.DEBIT).first()
        current_balance_after_charge = float(customer.working_bal) - float(get_charge.tran_charge)
        charge_withdrawal_transaction \
            = Transactions(trantype='DR',
                           tranref=Auto.reference_string_generator(),
                           tranmethod='Charge Transfer',
                           tran_date=transaction_reference,
                           cheque_num='None',
                           acc_number=int(self.cr_account),
                           cr_acc_number=int(self.suspense_account_charges.acc_number),
                           amount=float(get_charge.tran_charge),
                           current_balance=round(current_balance_after_charge, 2),
                           remark='Debit Charge',
                           custid=customer.custid)
        session.add(charge_withdrawal_transaction)
        session.commit()

        # Update Working balance on charge
        customer.working_bal = round(current_balance_after_charge, 2)
        session.add(customer)
        session.commit()
Esempio n. 15
0
 def rollover_system_date():
     date_change = session.query(SysDate).first()
     mydate = datetime.datetime.strptime(Getters.getSysDate().date, '%Y-%m-%d')
     add_day = datetime.timedelta(days=1)
     new_date = mydate + add_day
     date_change.date = new_date.strftime('%Y-%m-%d')
     session.add(date_change)
     session.commit()
Esempio n. 16
0
def create_system_date():
    date_obj = session.query(SysDate).all()
    if not date_obj:
        sys_date = SysDate(date=time.strftime('%Y-%m-%d'),
                           create_date=datetime.datetime.now())
        session.add(sys_date)
        session.commit()
    else:
        print("System Date Already Set To: {}".format(date_obj[0].date))
Esempio n. 17
0
    def link_banking_service(self, service_id):
        api_user = session.query(ApiUser).filter_by(account_number=self.account_number).first()
        service = session.query(BankingServices).filter_by(id=int(service_id))

        record = CustomerBankingService(api_user_id=api_user.user_id,
                                        service_id=service_id,
                                        status="active")
        session.add(record)
        session.commit()
Esempio n. 18
0
def hello_world():
    product = Product(name="product_1")
    category = Category(name="category_1", description='description')
    product.categories = [category]

    session.add(product)
    session.commit()

    return 'Hello, World!'
Esempio n. 19
0
    def withdrawalTransactionUpdate(tran_date, acc_number, amount, tranref):
        #   1. withdrawal detail between customer and till
        customer = session.query(Customer).filter_by(
            acc_number=acc_number).one()
        till_detail = session.query(Till).filter_by(
            till_account=Getters.getTillDetails().till_account).first()
        cb = float(customer.working_bal) - float(amount)
        trans = Transactions(trantype='DR',
                             tranref=tranref,
                             tranmethod='Cash',
                             tran_date=tran_date,
                             cheque_num='None',
                             acc_number=int(acc_number),
                             cr_acc_number=int(till_detail.till_account),
                             amount=amount,
                             current_balance=round(cb, 2),
                             remark='Withdrawal ' + tranref,
                             custid=customer.custid)
        session.add(trans)
        session.commit()
        # update customer working balance
        customer.working_bal = round(cb, 2)
        session.add(customer)
        session.commit()
        # -------------------------------
        # Update Till Opening/Closing balance
        till_detail.c_balance += round(amount, 2)
        session.add(till_detail)
        session.commit()
        # -------------------------------

        # 2. charge details between customer and charge account
        charge_account = session.query(Customer).filter_by(
            account_type='charges').first()
        get_charge = session.query(TransactionCharge).filter_by(
            tran_type='DR').first()
        cb2 = float(customer.working_bal) - float(get_charge.tran_charge)
        trans2 = Transactions(trantype='DR',
                              tranref=Auto.reference_string_generator(),
                              tranmethod='Charge Transfer',
                              tran_date=tran_date,
                              cheque_num='None',
                              acc_number=int(acc_number),
                              cr_acc_number=int(charge_account.acc_number),
                              amount=float(get_charge.tran_charge),
                              current_balance=round(cb2, 2),
                              remark='Debit Charge',
                              custid=customer.custid)
        session.add(trans2)
        session.commit()

        # Update Working balance on charge
        customer.working_bal = round(cb2, 2)
        session.add(customer)
        session.commit()
Esempio n. 20
0
    def import_from_service(self, rows, source='myprivatevpn'):
        for row in rows:
            ip = row.get('proxy_ip')
            port = row.get('proxy_port')
            proxy = Proxy(name="{0}:{1}".format(ip, port), source=source)
            session.add(proxy)

        try:
            session.commit()
            return True
        except Exception as e:
            print(str(e))
            session.rollback()
            return False
Esempio n. 21
0
 def create_customer(self):
     new_client = Customer(first_name=self.first_name,
                           last_name=self.last_name,
                           dob=self.dob,
                           gender=self.gender,
                           contact_number=self.contact_number,
                           email=self.email,
                           address=self.address,
                           country=self.country,
                           acc_number=self.acc_account,
                           working_bal=self.working_bal,
                           account_type=self.account_type,
                           create_date=datetime.datetime.now(),
                           inputter_id=self.inputter_id)
     session.add(new_client)
     session.commit()
Esempio n. 22
0
def create_system_tellers():
    record_till = session.query(Till).all()
    if len(record_till) <= 6:
        for _ in range(0, 6):
            print("Teller account created")
            new_teller = Till(
                branch_code='',
                o_balance=0,
                c_balance=0,
                till_account=Auto().system_account_number_generator(),
                currency="USD",
                remark='',
                date='',
                create_date=datetime.datetime.now(),
                user_id='')
            session.add(new_teller)
            session.commit()
Esempio n. 23
0
    def deposit(self):
        account_creation_current_balance = round(self.amount, 2)

        transaction = Transactions(
            trantype='CR',
            tranref=Auto.reference_string_generator(),
            tranmethod='Cash',
            tran_date=self.date,
            cheque_num='None',
            acc_number=self._suspence_account.acc_number,
            cr_acc_number=self.acc_number,
            amount=self.amount,
            current_balance=round(self.amount, 2),
            remark='Account Creation',
            custid=self._customer_account.custid)
        session.add(transaction)
        session.commit()
Esempio n. 24
0
 def commit_to_database(self):
     """
     persists a transaction record in the database using the session instance.
     :return:
     """
     transaction = Transactions(trantype=self.trans_type,
                                tranref=self.trans_ref,
                                tranmethod=self.trans_method,
                                tran_date=self.trans_date,
                                cheque_num=self.cheque_number,
                                acc_number=self.dr_account_number,
                                cr_acc_number=self.cr_account_number,
                                amount=self.amount,
                                current_balance=self.current_balance,
                                remark=self.remark,
                                custid=self.customer_id)
     session.add(transaction)
     session.commit()
Esempio n. 25
0
    def eomServfeeTransactionUpdate(acc_number, tran_date, amount):
        charged_customer = session.query(Customer).filter_by(
            acc_number=acc_number).first()
        current_balance = charged_customer.working_bal - amount

        servfee = session.query(Customer).filter_by(
            account_type='servfee').first()
        # same transactiion reference for customer and suspense account
        tranref = Auto.reference_string_generator()
        # transaction for Charged Customer
        trans = Transactions(trantype='SF',
                             tranref=tranref,
                             tranmethod='COB',
                             tran_date=tran_date,
                             cheque_num='None',
                             acc_number=acc_number,
                             cr_acc_number=servfee.acc_number,
                             amount=amount,
                             current_balance=round(current_balance, 2),
                             remark='SERVFEES',
                             custid=charged_customer.custid)
        session.add(trans)
        session.commit()

        # update customer working balance
        charged_customer.working_bal = round(current_balance, 2)
        session.add(charged_customer)
        session.commit()
        # -------------------------------

        # transaction for Suspense account
        cb = servfee.working_bal + amount
        trans_sus = Transactions(trantype='SF',
                                 tranref=tranref,
                                 tranmethod='COB',
                                 tran_date=tran_date,
                                 cheque_num='None',
                                 acc_number=acc_number,
                                 cr_acc_number=servfee.acc_number,
                                 amount=amount,
                                 current_balance=round(cb, 2),
                                 remark='SERVFEES',
                                 custid=servfee.custid)

        session.add(trans_sus)
        session.commit()

        # update Suspence account Working balance
        servfee.working_bal = cb
        session.add(servfee)
        session.commit()
        # ---------------------------------------

        pass
Esempio n. 26
0
def add_user():
    """
    create new user in db
    :return:
    """
    username = args.username
    password = args.password
    name = args.name
    email = args.email

    if username and password and name and email:

        user = User(username=username,
                    password=password,
                    name=name,
                    email=email)
        session.add(user)
        session.commit()
        print("User added successfully")
Esempio n. 27
0
 def add_product(self, name, description, price, category):
     """
     Admin only activity
     Add new product to the database
     :return:
     """
     try:
         category = self.db.query(Category).filter(
             Category.name.ilike(category)).one()
         new_product = Product(name=name,
                               description=description,
                               price=price,
                               category_id=category.id)
         session.add(new_product)
         session.commit()
         print("\n'%s' added successfully\n" % name)
         return True
     except NoResultFound:
         return False
Esempio n. 28
0
    def accInterestUpdate(cr_acc, total_amount, cb, cust_id):
        dr_acc_record = session.query(Customer).filter_by(
            account_type='interest').first()
        trans2 = Transactions(
            trantype='CR',
            tranref=Auto.reference_string_generator(),
            tranmethod='Interest',
            tran_date=Getters.getSysDate().date,
            cheque_num='None',
            acc_number=int(dr_acc_record.acc_number),  # interest account
            cr_acc_number=cr_acc,  # Client account
            amount=float(total_amount),
            current_balance=round(cb, 2),
            remark='Interest',
            custid=cust_id)

        session.add(trans2)
        session.commit()
        pass
Esempio n. 29
0
def create_system_branches():
    branches = [{
        "code": "01",
        "description": "Head Office"
    }, {
        "code": "02",
        "description": "Treasury"
    }, {
        "code": "03",
        "description": "Reconciliation"
    }]
    for branch in branches:
        branch_code = branch.get("code")
        description = branch.get("description")
        if branch_code not in [b.code for b in session.query(Branch).all()]:
            new_branch = Branch(code=branch_code, description=description)
            session.add(new_branch)
            session.commit()
        else:
            continue
Esempio n. 30
0
    def add_to_cart(self, product_name):
        """
        Add given product to the cart
        :param username:
        :param product_name:
        :return:
        """
        product = self.db.query(Product).filter(
            Product.name.ilike(product_name)).one()
        item = self.db.query(Cart).filter(Cart.user_id.like(
            self.user_id)).filter(Cart.product_id.like(product.id)).all()

        # check whether item already exist in the cart
        if not item:
            cart = Cart(user_id=self.user_id, product_id=product.id)
            session.add(cart)
            session.commit()
            print("\n'%s' added to the cart" % product_name)
        else:
            print("\n'%s' is already present in the cart" % product_name)