コード例 #1
0
def assign_pricelist_to_product():
    pl_last_name = ''
    while True:
        product_name = cf.prompt_("Enter product name: ",
                                  cf.get_completer_list("name", "product"),
                                  history_file="product_name.txt")
        if product_name == "quit": return "quit"
        if product_name == "back": return "back"
        id_product = product.get_product_details(product_name)[0]
        old_name = ''
        with conn() as cursor:
            cursor.execute(
                "select name, value from pricelist as pl join product_pricelist ppl on pl.id=ppl.id_pricelist where ppl.id_product = %s",
                (id_product, ))
            old_name_result = cursor.fetchone()
        if old_name_result:
            old_name = old_name_result[0]
            print("Price List Name is {}".format(old_name))
            print("You cannot edit name or value from here")
            return "back"
        pricelist_name = cf.prompt_("Enter pricelist name: ",
                                    cf.get_completer_list("name", "pricelist"),
                                    default_=pl_last_name)
        pl_last_name = pricelist_name
        if pricelist_name == "back": return "back"
        if pricelist_name == "quit": return "quit"
        pricelist_value = cf.prompt_("Enter pricelist value: ", [])
        if pricelist_value == "quit": return "quit"
        if pricelist_value == "back": return "back"
        id_pricelist = get_id_pricelist_by_name(pricelist_name)
        with conn() as cursor:
            cursor.execute(
                "insert into product_pricelist (id_product, id_pricelist, value) values (%s, %s, %s) returning id",
                (id_product, id_pricelist, pricelist_value))
コード例 #2
0
def get_owner(owner_type):
    nickname = cf.prompt_("Enter {} nickname: ".format(owner_type),
                          cf.get_completer_list("nickname", owner_type),
                          unique_="existing")
    if nickname == "quit": return "quit", None
    owner_ = owner.get_existing_owner_by_nickname(owner_type, nickname)
    return owner_
コード例 #3
0
def update_opening_balance(type_):
    owner_ = cf.prompt_("Enter Owner Name: ", cf.get_completer_list("nickname", type_.lower()), unique_="existing")
    balance_ = cf.prompt_("Enter amount: ", [])
    with conn() as cursor:
        cursor.execute("update {} set opening_balance = %s where nickname = %s returning name, opening_balance".format("master."+type_), (balance_, owner_))
        result = cursor.fetchall()
    cf.pretty_(['name', 'balance'], result)
コード例 #4
0
 def edit_property(self, property_, **kwargs):
     if property_ in ["packed", "unpack"]:
         old_value = getattr(self, property_)
         if old_value:
             new_value = None
             setattr(self, property_, new_value)
         else:
             new_value = "yes"
             setattr(self, property_, new_value)
         cf.cursor_(sql.SQL(
             "update {} set {} = %s where id = %s returning id").format(
                 sql.Identifier(self.invoice_detail_type),
                 sql.Identifier(property_)),
                    arguments=(new_value, self.id))
         return
     if property_ in ["id", "product_gst_rate"]:
         cf.log_("You cannot change 'id' value")
         return None
     old_value = getattr(self, property_)
     new_value = cf.prompt_(
         "Enter new {} [{}] for {}: ".format(property_, old_value,
                                             self.product_name),
         cf.get_completer_list(property_, self.invoice_detail_type))
     if new_value == "quit": return "quit"
     setattr(self, property_, new_value)
     cf.cursor_(
         sql.SQL("update {} set {} = %s where id = %s returning id").format(
             sql.Identifier(self.invoice_detail_type),
             sql.Identifier(property_)),
         arguments=(new_value, self.id))
     if property_ in ['product_gst_name']:
         confirm_ = cf.prompt_(
             "Do you want to update the name in Product table?: ",
             ['y', 'n'],
             default_='y',
             unique_='existing')
         if confirm_ == 'y':
             with conn() as cursor:
                 cursor.execute(
                     "update product set gst_name = %s where id = %s",
                     (new_value, self.product_id))
     if property_ in ["product_rate", "product_qty", "product_discount"]:
         sub_total = self.get_sub_total(property_=property_,
                                        property_value=Decimal(new_value))
         gst_amount = (Decimal(sub_total) * Decimal(self.product_gst_rate) *
                       Decimal(0.01)).quantize(Decimal("1.00"))
         with conn() as cursor:
             cursor.execute(
                 sql.SQL(
                     "update {} set ({}, sub_total, gst_amount) = (%s, %s, %s) where id = %s"
                 ).format(sql.Identifier(self.invoice_detail_type),
                          sql.Identifier(property_)),
                 (new_value, sub_total, gst_amount, self.id))
         setattr(self, "sub_total", sub_total)
         owner_product = cf.owner_product_from_invoice_type_d[
             self.invoice_.invoice_type]
         self.invoice_.update_invoice_with_sub_total()
         self.update_owner_product(owner_product, self.product_rate,
                                   **kwargs)
         self.view_()
コード例 #5
0
ファイル: owner.py プロジェクト: pythonpsql/chip
def get_new_owner(owner_type, **kwargs):
    owner_ = Owner(owner_type)
    owner_.nickname = kwargs.get('nickname', '')
    if not owner_.nickname:
        owner_.nickname = cf.prompt_("Enter {} Nickname: ".format(owner_type),
                                     cf.get_completer_list(
                                         "nickname", owner_type),
                                     unique_="yes")
    owner_.name = cf.prompt_("Enter {} Name: ".format(owner_type),
                             cf.get_completer_list("name", owner_type),
                             default_=owner_.nickname.title())
    owner_.place = cf.prompt_("Enter {} Place: ".format(owner_type),
                              cf.get_completer_list("place", owner_type))
    owner_.gst_name = cf.prompt_("Enter {} GST Name: ".format(owner_type), [],
                                 default_=owner_.name)
    owner_.id = create_new_owner_in_db(owner_)
    return owner_
コード例 #6
0
def create_product(name):
    unit = cf.prompt_("Enter {} Unit: ".format(name),
                      cf.get_completer_list("unit", "product"),
                      history_file=None,
                      default_="Nos")
    if unit == "quit": return "quit", "quit"
    if unit == "back": return "back", "back"
    abbr_name = cf.prompt_("Enter {} abbr: ".format(name),
                           cf.get_completer_list("abbr_name", "product"),
                           history_file=None,
                           unique_="y",
                           empty_="y")
    if abbr_name == "quit": return "quit", "quit"
    if abbr_name == "back": return "back", "back"
    print_name = cf.prompt_("Enter {} print_name: ".format(name),
                            cf.get_completer_list("print_name", "product"),
                            history_file=None,
                            unique_="y",
                            empty_="y",
                            default_=name)
    if print_name == "quit": return "quit", "quit"
    if print_name == "back": return "back", "back"
    result = cf.execute_(
        "insert into {} (name, unit, abbr_name, print_name) values (%s, %s, %s, %s) returning name, unit, id",
        ["product"],
        arg_=(name, unit, abbr_name, print_name),
        fetch_="yes")
    id_ = result[2]
    cf.log_("New Product ({}) was created".format(result[0]))
    pricelist = cf.prompt_("Enter {} price_list: ".format(name),
                           cf.get_completer_list("name", "pricelist"),
                           empty_="y")
    if pricelist == "quit": return "quit", "quit"
    if pricelist == "back": return "back", "back"
    if pricelist:
        id_pricelist = plf.get_id_pricelist_by_name(pricelist)
        pricelist_value = cf.prompt_("Enter pricelist value: ", [])
        if pricelist_value == "quit": return "quit"
        if pricelist_value == "back": return "back"
        with conn() as cursor:
            cursor.execute(
                "insert into product_pricelist (id_product, value, id_pricelist) values (%s, %s, %s)",
                (id_, pricelist_value, id_pricelist))
    return [result[0], result[1]]
コード例 #7
0
ファイル: command_functions.py プロジェクト: pythonpsql/chip
def get_command(invoice_):
    # invoice_result = owner.get_filter_result("Unsaved Invoices", "sale_invoice")
    if invoice_.invoice_type == "sale_invoice":
        invoice_list = owner.get_all_gst_invoices("sale_invoice")
        estimate_list = owner.get_all_unsaved_invoices("sale_invoice")
    elif invoice_.invoice_type == "purchase_invoice":
        invoice_list = owner.get_all_gst_invoices("purchase_invoice")
        estimate_list = owner.get_all_unsaved_invoices("purchase_invoice")

    invoice_dict = {}
    estimate_dict = {}

    for a in invoice_list:
        invoice_dict[str(a[4])] = "{}, {}, {}, {}".format(
            str(a[0]), str(a[2]), str(a[3]), str(a[1]))
    for a in estimate_list:
        estimate_dict[str(a[3])] = "{}, {}, {}".format(str(a[1]), str(a[2]),
                                                       str(a[0]))

    invoice_list = [
        str(a[4]) for a in invoice_list
    ]  # do not unpack dict with * to get this list because dictionary is always unsorted
    estimate_list = [
        str(a[3]) for a in estimate_list
    ]  # do not unpack dict with * to get this list because dictionary is always unsorted
    # invoice_result = owner.get_all_unsaved_invoices(invoice_.invoice_type)
    # invoice_list = [str(a[3]) for a in invoice_result]
    # invoice_dict = {}
    # for a in invoice_result:
    #     invoice_dict[str(a[3])] = "{}, {}, {}".format(str(a[0]), str(a[1]), str(a[2]))
    cf.log_("inside get command")
    owner_product = cf.owner_product_from_invoice_type_d[invoice_.invoice_type]
    owner_product_list, owner_product_dict = product.get_owner_product_dict(
        owner_product, invoice_.owner.id)
    # owner_product_abbr_list, owner_product_abbr_dict = product.get_owner_product_abbr_dict(owner_product, invoice_.owner.id)
    owner_nickname_list = cf.get_completer_list("nickname",
                                                invoice_.owner_type)
    # invoice_command_list = owner_product_list + owner_product_abbr_list + owner_nickname_list
    invoice_command_list = owner_product_list + owner_nickname_list + starting_list + startswith_list + [
        'b', 'q'
    ]
    # creating dict with None values
    owner_nickname_dict = dict.fromkeys(owner_nickname_list)
    # invoice_command_dict = {**owner_product_dict, **owner_product_abbr_dict, **owner_nickname_dict}
    invoice_command_dict = {**owner_product_dict, **owner_nickname_dict}
    return cf.prompt_dict("Enter {} command:".format(invoice_.invoice_type),
                          invoice_command_dict,
                          list_=invoice_command_list,
                          invoice_list=invoice_list,
                          invoice_dict=invoice_dict,
                          estimate_list=estimate_list,
                          estimate_dict=estimate_dict)
コード例 #8
0
def set_pricelist_discount_for_owner(owner_type, **kwargs):
    reducing_pricelist_id = get_id_pricelist_by_name("GI Fitting Reducing")
    owner_pricelist = cf.owner_pricelist_from_owner_type_d[owner_type]
    id_owner = owner.get_id_from_nickname(
        owner_type,
        cf.prompt_("Enter {} Name: ".format(owner_type.title()),
                   cf.get_completer_list("nickname", owner_type)))
    id_pricelist = get_id_pricelist_by_name(
        cf.prompt_("Enter Price List Name: ",
                   cf.get_completer_list("name", "pricelist")))
    pricelist_discount = get_old_pricelist_discount(owner_pricelist, id_owner,
                                                    id_pricelist, **kwargs)
    if id_pricelist == reducing_pricelist_id:
        condition = get_old_pricelist_condition(owner_pricelist, id_owner,
                                                id_pricelist)
        set_pricelist_condition(owner_pricelist, id_owner, id_pricelist,
                                condition)
    pricelist_discount = cf.prompt_("Enter Discount: ", [],
                                    empty="y",
                                    default_=str(pricelist_discount))
    set_pricelist_discount(owner_pricelist, id_owner, id_pricelist,
                           pricelist_discount, **kwargs)
コード例 #9
0
def get_invoice_owner(invoice_, **kwargs):
    owner_nickname = kwargs.get('nickname', '')
    if not owner_nickname:
        owner_nickname = cf.prompt_(
            "Enter {} nickname: ".format(invoice_.owner_type),
            cf.get_completer_list("nickname", invoice_.owner_type))
    owner_ = owner.get_existing_owner_by_nickname(invoice_.owner_type,
                                                  owner_nickname)
    # print(owner_.gst_name)

    if not owner_:
        owner_ = owner.get_new_owner(invoice_.owner_type,
                                     nickname=owner_nickname)
    return owner_
コード例 #10
0
 def get_detail(self):
     if self.owner_type == "customer": temp_ = "vendor"
     if self.owner_type == "vendor": temp_ = "customer"
     vendor_names = cf.get_completer_list("nickname", temp_)
     recipient = cf.prompt_("Enter recipient/payer: ",
                            vendor_names,
                            default_="self")
     if recipient in ["quit", "back"]: return None, None, None
     medium = cf.prompt_("Enter medium: ", [
         'Transfer', 'Cash', 'Cheque', 'Bank Cash', 'Bank Cheque',
         'Invoice', 'Adjustment'
     ],
                         empty_="yes",
                         default_="Cash")
     if medium in ["quit", "back"]: return None, None, None
     detail = cf.prompt_("Enter detail: ", [], empty_="yes")
     if detail in ["quit", "back"]: return None, None, None
     return recipient, medium, detail
コード例 #11
0
 def edit_product_property(self, property_):
     if property_ == "id":
         cf.log_("You cannot change 'id' of the product")
         return None
     old_value = getattr(self, property_)
     new_value = cf.prompt_("Enter new {} for {}: ".format(
         property_, self.name),
                            cf.get_completer_list(property_, "product"),
                            default_=old_value,
                            empty_="yes")
     if old_value == new_value: return None
     setattr(self, property_, new_value)
     try:
         cf.execute_(
             "update product set {} = %s where id = %s returning id",
             [property_],
             arg_=(new_value, self.id))
     except Exception as e:
         print(e)
コード例 #12
0
def set_property(property_, by_name=False):
    if by_name:
        name = cf.prompt_("Enter product name: ",
                          cf.get_completer_list("name", "product"),
                          unique_="existing")
        if name in ["quit", "back"]: return "back"
        cf.log_(name)
        old_value = cf.execute_("select {} from {} where lower({})= %s",
                                [property_],
                                table_="product",
                                where_="name",
                                arg_=(name.lower(), ),
                                fetch_="yes")
        old_value = old_value[0]
        if old_value == None: old_value = ""
        new_value = cf.prompt_("{} for {}: ".format(property_, name), [],
                               default_=old_value)
        if new_value == "quit": return "back"
        if new_value == "back": return "back"
        if new_value == "s":
            return "back"  # only for consistency with bulk abbreviate
        if old_value == new_value: return "back"
        cf.log_(
            cf.execute_(
                "update product set {} = %s where name = %s returning id",
                [property_],
                arg_=(new_value, name)))
        return "back"
    result = cf.cursor_(
        sql.SQL("select name from product where {} is null order by id desc").
        format(sql.Identifier(property_)))
    name_list = [element for tupl in result for element in tupl]
    for name in name_list:
        new_value = cf.prompt_("{} for {}: ".format(property_, name), [])
        if new_value == "quit": return "quit"
        if new_value == "back": return "back"
        if new_value == "s": continue
        cf.log_(
            cf.cursor_(sql.SQL(
                "update product set {} = %s where name = %s returning id").
                       format(sql.Identifier(property_)),
                       arguments=(new_value, name)))
コード例 #13
0
ファイル: command_functions.py プロジェクト: pythonpsql/chip
def classify_command(command_, invoice_):
    cf.log_("inside classify_command")
    owner_nickname_list = cf.get_completer_list("nickname",
                                                invoice_.owner_type)
    # Possible Return Values:
    # 1. ["continue", "continue"]
    # 2. ["owner_name", invoice_]
    # 3. ["quit", "quit"]
    # Take care to check for starting list on top since the single letter inputs will hold true for product_list and owner_list
    if any([command_.startswith(n) for n in startswith_list]):
        cf.log_("command_ starts with a startswith_list value")
        return startswith_command(command_, invoice_)
    if command_ in starting_list:
        cf.log_("command_ is in starting list")
        return starting_command(command_, invoice_)
    if command_ in owner_nickname_list:
        owner_nickname = command_
        owner_type = invoice_.owner_type
        owner_command = cf.prompt_dict(
            "Enter {}[{}] command: ".format(owner_type, owner_nickname),
            command_dict.owner_commands[owner_type])
        owner_command = "o" + owner_command
        return {
            "arg1": owner_command,
            "arg2": owner_nickname,
            "arg3": invoice_
        }
    else:
        # elif command_.lower() in [name.lower() for name in self.product_list]:
        product_qty = command_.split()[-1]
        product_name = " ".join(command_.split()[:-1])
        try:
            cf.log_("Creating new invoice_detail")
            i_detail_ = invoice_detail.get_new_invoice_detail_by_product(
                invoice_, product_name, product_qty)
            invoice_.update_invoice_with_sub_total()
            i_detail_.view_()
        except Exception as e:
            cf.log_(e)

        return {"arg1": "continue"}
コード例 #14
0
ファイル: start.py プロジェクト: pythonpsql/chip
def chip():
    cf.clear_screen(msg="Chip")
    # input_ = {"arg1": 'plm'}
    input_ = None
    while True:
        cf.log_("start input_ is {}".format(input_))
        if not input_:
            input_ = get_input()
            cf.log_("input_.get('arg1') is {}".format(input_.get('arg1')))
        elif input_ == "back":
            input_ = None
            continue
        elif input_ == "quit":
            cf.log_("You quit")
            import sys
            sys.exit()
            break
        elif input_.get("arg1") == "slms":
            tr.view_summary()
            input_ = None
            continue
        elif input_.get("arg1") == "slmp":
            place = cf.prompt_("Enter place: ",
                               cf.get_completer_list("place", "customer"),
                               existing_="yes")
            tr.get_customer_balance(place=place)
            input_ = None
            continue
        elif input_.get("arg1") == "slgp":
            place = cf.prompt_("Enter place: ",
                               cf.get_completer_list("place", "customer"),
                               existing_="yes")
            tr.get_gst_customer_balance(place=place)
            input_ = None
            continue
        elif input_.get("arg1") == "slmc":
            tr.get_customer_balance()
            input_ = None
            continue
        elif input_.get("arg1") == "test":
            # tr.view("sale_transaction")
            # tr.view("purchase_transaction")
            # tr.view_by_nickname("sale_transaction", "Kishor Light House")
            # master.add_saved("sale_invoice")
            input_ = None
            continue
        elif input_.get('arg1') in ['saved', 'unsaved']:
            if input_.get('arg1') == 'unsaved':
                sq = 'select id, owner_name, owner_place, amount_after_freight from sale_invoice where id not in (select id_invoice from sale_transaction where id_invoice is not null) and gst_invoice_no is null'
                sq_purchase = 'select id, owner_name, owner_place, amount_after_freight from purchase_invoice where id not in (select id_invoice from purchase_transaction where id_invoice is not null) and gst_invoice_no is null'
            elif input_.get('arg1') == 'saved':
                sq = 'select id, owner_name, owner_place, amount_after_freight from sale_invoice where id in (select id_invoice from sale_transaction where id_invoice is not null) and gst_invoice_no is null'
                sq_purchase = 'select id, owner_name, owner_place, amount_after_freight from purchase_invoice where id in (select id_invoice from purchase_transaction where id_invoice is not null) and gst_invoice_no is null'
            with conn() as cursor:
                cursor.execute(sq)
                result = cursor.fetchall()
            with conn() as cursor:
                cursor.execute(sq_purchase)
                result_purchase = cursor.fetchall()
            for a_result in [result, result_purchase]:
                pt = PrettyTable(['id', 'name', 'place', 'amount'])
                pt.align['amount'] = 'r'
                for a in a_result:
                    pt.add_row(a)
                print(pt)
                print("Count: {}".format(len(a_result)))
            input_ = None
            continue

        elif input_.get("arg1") == "invoice_by_id":
            invoice_type = input_.get("arg3")
            invoice_id = input_.get("arg2")
            invoice_ = invoice.get_existing_invoice(invoice_type, invoice_id)
            invoice_.view_invoice_details(invoice_.fetch_invoice_details())
            input_ = cm.command_loop(invoice_)
            continue
        elif input_.get("arg1") == "todo":
            input_ = None
            continue
        elif input_.get("arg1") == "gbr":
            product_name = cf.prompt_("Enter product name: ",
                                      cf.get_completer_list("name", "product"),
                                      unique_="existing")
            product.get_buy_rate(product_name)
            input_ = None
            continue
        elif input_.get("arg1") == "sl":
            input_ = tr.ledger_operations("sale_transaction")
            continue
        elif input_.get("arg1") == "sbmc":
            input_ = tr.get_a_balance("sale_transaction", master_=True)
            continue
        elif input_.get("arg1") == "sbma":
            input_ = tr.get_all_balances("sale_transaction", master_=True)
            continue
        elif input_.get("arg1") == "sbga":
            input_ = tr.get_all_gst_balances("sale_transaction")
            continue
        elif input_.get("arg1") == "slg":
            input_ = tr.ledger_operations("sale_transaction", gst_=True)
            continue
        elif input_.get("arg1") == "slm":
            input_ = tr.ledger_operations("sale_transaction", master_="yes")
            continue
        elif input_.get("arg1") == "slmd":
            input_ = tr.ledger_operations("sale_transaction",
                                          master_="yes",
                                          date_='yes')
            continue
        elif input_.get("arg1") == "pl":
            input_ = tr.ledger_operations("purchase_transaction")
            continue
        elif input_.get("arg1") == "plg":
            input_ = tr.ledger_operations("purchase_transaction", gst_=True)
            continue
        elif input_.get("arg1") == "plm":
            input_ = tr.ledger_operations("purchase_transaction",
                                          master_="yes")
            continue
        elif input_.get("arg1") == "backup":
            print("This command is currently disabled")
            # master.export(only_backup=True)
            input_ = None
            continue
        elif input_.get("arg1") == "ex":
            confirm_ = cf.prompt_("Do you want to export? ", ['y', 'n'],
                                  unique_="existing")
            if confirm_ != 'y':
                print("You canceled. No changes were made.")
                input_ = None
                continue
            master.save_all_money()
            master.export()
            input_ = None
            continue
        elif input_.get("arg1") in ["rin", "ptin"]:
            if input_.get("arg1") == "rin":
                invoice_type = "receipt"
            elif input_.get("arg1") == "ptin":
                invoice_type = "payment"
            invoice_ = money.Money(invoice_type)
            input_ = None
            continue
        elif input_.get("arg1") in ["rie", "ptie"]:
            if input_.get("arg1") == "rie":
                invoice_type = "receipt"
            elif input_.get("arg1") == "ptie":
                invoice_type = "payment"
            invoice_id = owner.view(invoice_type,
                                    filter_type="Search By Nickname")
            if invoice_id in ["quit", "back"]:
                input_ = {"arg1": input_}
                continue
            money_ = money.Money(invoice_type, id_=invoice_id)
            money_.view_invoice_details(money_.fetch_invoice_details())
            while True:
                property_ = cf.prompt_(
                    "Enter property to edit/'delete' to delete record: ",
                    money.sq_properties,
                    empty_='yes')
                if property_ == "delete":
                    money_.delete_()
                    break
                if property_ in money.sq_properties:
                    money_.edit_property(property_)
                    continue
                if property_ in ["back", "quit"]:
                    break
            input_ = None
            continue
        elif input_.get("arg1") in ["rip", "ptip"]:
            if input_.get("arg1") == "rip":
                invoice_type = "receipt"
                owner_type = "customer"
            elif input_.get("arg1") == "ptip":
                invoice_type = "payment"
                owner_type = "vendor"
            with conn() as cursor:
                cursor.execute(
                    "select r.date_, c.name, r.amount, r.medium, r.recipient, r.detail from {} as r join {} as c on c.id = r.id_owner where gst_invoice_no is null order by r.date_"
                    .format(invoice_type, owner_type))
                result = cursor.fetchall()
            column_list = [
                'Date', 'Name', 'Amount', 'Medium', 'Recipient', 'Detail'
            ]
            cf.pretty_table_multiple_rows(column_list, result)
            input_ = None
            continue
        elif input_.get("arg1") == "praa":
            input_ = product.set_property("abbr_name")
            if input_ in ["quit", "back"]:
                input_ = {"arg1": input_}
            continue
        elif input_.get("arg1") == "pra":
            input_ = product.set_property("abbr_name", by_name="yes")
            if input_ in ["quit", "back"]:
                input_ = {"arg1": input_}
            continue
        elif input_.get("arg1") == "prn":
            input_ = product.set_property("name", by_name="yes")
            if input_ in ["quit", "back"]:
                input_ = {"arg1": input_}
            continue
        elif input_.get("arg1") == "prc":
            while True:
                name = cf.prompt_("Enter New Product Name: ",
                                  cf.get_completer_list("name", "product"),
                                  unique_="yes")
                if name in ["quit", "back"]:
                    input_ = {"arg1": input_}
                    break
                input_ = product.create_product(name)
            continue
        elif input_.get("arg1") == "prde":
            input_ = cf.prompt_("Enter product name: ",
                                cf.get_completer_list("name", "product"),
                                unique_="existing")
            if input_ in ["quit", "back"]:
                input_ = {"arg1": input_}
                continue
            product.delete_product(input_)
            input_ = None
            continue
        elif input_.get("arg1") in ["sipn", "pipn", ","]:
            if input_.get("arg1") in ["sipn", ","]:
                invoice_type = "sale_invoice"
            elif input_.get("arg1") == "pipn":
                invoice_type = "purchase_invoice"
            invoice_id = owner.view(invoice_type,
                                    filter_type="Search By Nickname")
            if invoice_id in ["quit", "back"]:
                input_ = {"arg1": input_}
                continue
            invoice_ = invoice.get_existing_invoice(invoice_type, invoice_id)
            invoice_.view_invoice_details(invoice_.fetch_invoice_details())
            input_ = cm.command_loop(invoice_)
            continue
        elif input_.get("arg1") in ["sip", "pip"]:
            if input_.get("arg1") == "sip":
                invoice_type = "sale_invoice"
            elif input_.get("arg1") == "pip":
                invoice_type = "purchase_invoice"
            invoice_id = owner.view(invoice_type)
            if invoice_id == "back":
                print("you chose to cancel")
                input_ = None
                continue
            invoice_ = invoice.get_existing_invoice(invoice_type, invoice_id)
            invoice_.view_invoice_details(invoice_.fetch_invoice_details())
            input_ = cm.command_loop(invoice_)
            continue
        elif input_.get("arg1") in ["sil", "pil"]:
            if input_.get("arg1") == "sil":
                invoice_type = "sale_invoice"
            elif input_.get("arg1") == "pil":
                invoice_type = "purchase_invoice"
            last_invoice_id = owner.get_last_invoice_id(invoice_type)
            if not last_invoice_id:
                cf.log_("There are no previous invoices")
                input_ = None
                continue
            invoice_ = invoice.get_existing_invoice(invoice_type,
                                                    last_invoice_id)
            # print("reahced here0")
            invoice_.view_invoice_details(invoice_.fetch_invoice_details())
            # print("reahced here")
            input_ = cm.command_loop(invoice_)
            continue
        elif input_.get("arg1") in ["cun", "ven"]:
            if input_.get("arg1") == "cun":
                invoice_type = "sale_invoice"
            elif input_.get("arg1") == "ven":
                invoice_type = "purchase_invoice"
            owner_type = cf.owner_type_d[invoice_type]
            id_ = owner.get_new_owner(owner_type)
            input_ = None
            continue
        elif input_.get("arg1") == "prn":
            input_ = cf.prompt_("Enter Product Name: ",
                                cf.get_completer_list("name", "product"),
                                history_file='product_name.txt')
            if input_ in ["quit", "back"]:
                input_ = {"arg1": input_}
            else:
                input_ = product.Product.init_by_name(input_)
                input_ = None
            continue
        elif input_.get("arg1") in ["sin", "pin"]:
            if input_.get("arg1") == "sin":
                invoice_type = "sale_invoice"
            elif input_.get("arg1") == "pin":
                invoice_type = "purchase_invoice"
            invoice_ = invoice.get_new_invoice(invoice_type)
            input_ = cm.inside_invoice(invoice_)
            continue
        elif input_.get("arg1") == "plp":
            input_ = plf.assign_pricelist_to_product()
            if input_ in ["quit", "back"]:
                input_ = {"arg1": input_}
            continue
        elif input_.get("arg1") in ["cupln", "vepln"]:
            if input_.get("arg1") == "cupln":
                owner_type = "customer"
            elif input_.get("arg1") == "vepln":
                owner_type = "vendor"
            confirm_ = cf.prompt_("Change discount for: ", ['gst', 'non-gst'],
                                  unique_="existing")
            if confirm_ == "gst":
                gst_arg = True
            else:
                gst_arg = False
            plf.set_pricelist_discount_for_owner(owner_type, gst_=gst_arg)
            continue
        elif input_.get('arg1') == "q" or input_.get('arg1') == "quit":
            cf.log_("You entered 'q' to quit")
            import sys
            sys.exit()
            break
        elif input_.get('arg1') == "b" or input_.get('arg1') == "back":
            input_ = None
            continue
        elif input_.get('arg1') == "ivp":
            invoice_ = input_.get('arg2')
            result = invoice_.fetch_invoice_details()
            invoice_.view_invoice_details(result)
            l = len(result)
            no_of_results = 5
            v = l - no_of_results
            while True:
                view_command = cf.prompt_("View Previous/Next 5: (p/n)", [],
                                          empty_="yes")
                if view_command == "p":
                    previous_v = v
                    cf.log_("previous_v is {}".format(previous_v))
                    v = v - no_of_results
                    cf.log_("v is {}".format(v))
                    if not v < 0:
                        cf.log_("{}, {}".format(v, previous_v - 1))
                        invoice.view_print(result[v:previous_v - 1])
                        print("v, previous_v:\n{}, {}".format(v, previous_v))
                        continue
                    else:
                        invoice.view_print(result[:previous_v])
                        print("reached top")
                        v = l - no_of_results
                        continue
                elif view_command == "n":
                    if 'next_v' not in locals():
                        next_v = previous_v
                    else:
                        next_v = v
                    v = next_v + no_of_results
                    if len(result) > v:
                        print("v, next_v:\n{}, {}".format(v, next_v))
                        invoice.view_print(result[next_v:v])
                        continue
                    else:
                        invoice.view_print(result[v - no_of_results:])
                        print("reached bottom")
                        v = len(result) - no_of_results
                        continue
                else:
                    break
            input_ = cm.command_loop(invoice_)
            continue
        elif input_.get('arg1') in ["oli", "olim"]:
            owner_nickname = input_.get('arg2')
            last_invoice_ = input_.get('arg3')
            if input_.get('arg1') == 'olim':
                master_ = True
            else:
                master_ = False
            invoice_type = last_invoice_.invoice_type
            owner_type = last_invoice_.owner_type
            id_owner = owner.get_id_from_nickname(owner_type, owner_nickname)
            invoice_id = owner.get_owner_last_invoice_id(invoice_type,
                                                         id_owner,
                                                         master_=master_)
            invoice_ = invoice.get_existing_invoice(invoice_type,
                                                    invoice_id,
                                                    master_=master_)
            sale_report.create_(invoice_, 'A6', master_=True)
            # invoice_.view_invoice_details(invoice_.fetch_invoice_details(master_=master_))
            if master_:
                input_ = cm.open_invoice_by_id(last_invoice_.id, invoice_type)
                continue
            input_ = cm.command_loop(invoice_)
            continue
        elif input_.get('arg1') == "ov":
            owner_nickname = input_.get('arg2')
            last_invoice_ = input_.get('arg3')
            invoice_type = last_invoice_.invoice_type
            owner_type = last_invoice_.owner_type
            id_owner = owner.get_id_from_nickname(owner_type, owner_nickname)
            owner_ = owner.get_existing_owner_by_id(owner_type, id_owner)
            owner_.display_basic_info()
            input_ = None
            continue
        elif input_.get('arg1') == "oai":
            owner_nickname = input_.get('arg2')
            last_invoice_ = input_.get('arg3')
            invoice_type = last_invoice_.invoice_type
            owner_type = last_invoice_.owner_type
            id_owner = owner.get_id_from_nickname(owner_type, owner_nickname)
            owner_ = owner.get_existing_owner_by_id(owner_type, id_owner)
            invoice_id = owner_.get_owner_invoice(invoice_type)
            input_ = cm.open_invoice_by_id(invoice_id, invoice_type)
            continue
        elif input_.get('arg1') == "oe":
            try:
                owner_nickname = input_.get('arg2')
                last_invoice_ = input_.get('arg3')

                # above two statements do not generate exception
                invoice_type = last_invoice_.invoice_type
            except Exception as e:
                cf.log_(e)
                owner_type = cf.prompt_('Select Owner Type: ',
                                        ["customer", "vendor"])
                if owner_type in ["quit", "back"]:
                    input_ = {"arg1": "back"}
                owner_nickname = cf.prompt_("Enter Owner Nickname: ",
                                            cf.get_completer_list(
                                                "nickname", owner_type),
                                            unique_="existing")
                id_owner = owner.get_id_from_nickname(owner_type,
                                                      owner_nickname)
                owner_ = owner.get_existing_owner_by_id(owner_type, id_owner)
                while True:
                    owner_.edit_properties()
                input_ = None
                continue
            owner_type = last_invoice_.owner_type
            id_owner = owner.get_id_from_nickname(owner_type, owner_nickname)
            owner_ = owner.get_existing_owner_by_id(owner_type, id_owner)
            while True:
                owner_.edit_properties()
            input_ = None
            continue
        elif input_.get("arg1") == "osb":
            nickname = input_.get('arg2')
            last_invoice_ = input_.get('arg3')
            invoice_type = last_invoice_.invoice_type
            owner_product = cf.owner_product_from_invoice_type_d[invoice_type]
            owner_type = last_invoice_.owner_type
            id_owner = owner.get_id_from_nickname(owner_type,
                                                  nickname,
                                                  no_create="y")
            cm.sandbox(id_owner, owner_product)
            input_ = cm.open_invoice_by_id(last_invoice_.id, invoice_type)
            continue
        elif input_.get('arg1') == "on":
            owner_nickname = input_.get('arg2')
            last_invoice_ = input_.get('arg3')
            invoice_type = last_invoice_.invoice_type
            invoice_ = invoice.get_new_invoice(invoice_type,
                                               nickname=owner_nickname)
            input_ = cm.inside_invoice(invoice_)
            continue
        elif input_.get('arg1') == "op":
            owner_nickname = input_.get('arg2')
            last_invoice_ = input_.get('arg3')
            invoice_type = last_invoice_.invoice_type
            owner_type = last_invoice_.owner_type
            id_owner = owner.get_id_from_nickname(owner_type, owner_nickname)
            invoice_id = owner.get_owner_last_invoice_id(
                invoice_type, id_owner)
            invoice_ = invoice.get_existing_invoice(invoice_type, invoice_id)
            cf.log_("reached op here")
            sale_report.create_(invoice_, 'A6')
            # go back to current invoice
            invoice_ = invoice.get_existing_invoice(invoice_type,
                                                    last_invoice_.id)
            invoice_.view_invoice_details(invoice_.fetch_invoice_details())
            input_ = cm.command_loop(invoice_)
            # ask for invoice and print it
            pass
        elif input_.get('arg1') == "opl":
            input_ = None
            # set pricelist discount
            pass
        elif input_.get('arg1') == "ol":
            input_ = None
            pass
        else:
            cf.log_("Unknown command: {}".format(input_))
            input_ = None
            continue
コード例 #15
0
 def ask_owner_nickname(self):
     owner_nickname = cf.prompt_(
         "Enter {} nickname: ".format(self.owner_type),
         cf.get_completer_list("nickname", self.owner_type))
     if owner_nickname == cf.quit_: return None
     return owner_nickname
コード例 #16
0
#! /usr/bin/env python3
from database import Database, CursorFromConnectionFromPool as conn
import common_functions as cf

if __name__ == "__main__":
    Database.initialise(database='chip', host='localhost', user='******')
    while True:
        place = cf.prompt_("Enter place: ",
                           cf.get_completer_list("place", "customer"))
        if place == "q":
            break
        if place == "a":
            with conn() as cursor:
                cursor.execute("select date_, place from tour")
                all_ = cursor.fetchall()
            cf.pretty_(['Date', 'Place'], all_)
            continue
        date_ = cf.prompt_("Enter date: ", [], default_="2018-")
        if date_:
            with conn() as cursor:
                cursor.execute(
                    "insert into tour (place, date_) values (%s, %s) returning date_, place",
                    (place, date_))
                result = cursor.fetchall()
            cf.pretty_(['Date', 'Place'], result)
        else:
            print("No changes were made")
    print("Bye!")
コード例 #17
0
        discount = cf.prompt_("Enter discount for {}: ".format(a[1]), [], default_=str(0), empty_="yes")
        if discount:
            discount = float(discount)
            cost = (Decimal(cost_before_discount) * Decimal(1 - discount/100)).quantize(Decimal("1.00"))
        else:
            cost = cost_before_discount
        transport_cost = cf.prompt_("Enter Tranport Cost for {}: ".format(a[1]), [], default_=str(0), empty_="yes")
        timestamp_ = cf.get_current_timestamp()
        final_cost = (Decimal(cost) + Decimal(transport_cost)).quantize(Decimal("1.00"))
        with conn() as cursor:
            cursor.execute("update product set (purchase_cost, cost, timestamp_) = (%s, %s, %s) where id = %s returning name, cost, timestamp_", (cost, timestamp_, a[0]))
            result = cursor.fetchall()
        cf.pretty_(['name', 'cost', 'final_cost', 'timestamp_'], result)

# product.get_buy_rate(invoice_detail_.product_name)
if __name__ == "__main__":
    while True:
        product_name = cf.prompt_("Choose Product or 'a' for all: ", cf.get_completer_list("name", "product"))
        if product_name == "a":
            result = get_all_products()
            for a in result:
                print(a)
                product.get_buy_rate(a[1])
                set_product_cost(a)
        else:
            a = get_a_product(product_name)
            product.get_buy_rate(product_name)
            set_product_cost(a)