Exemplo n.º 1
0
def dropbox(local_file, **kwargs):
    project_dir = os.path.dirname(os.path.abspath(__file__))
    remote_folder = kwargs.get('remote_folder', '')
    remote_folder = '/' + remote_folder
    print('local_file: {}'.format(local_file))
    dropbox_backup = cf.prompt_("Do you want to backup to Dropbox? (y/n): ",
                                ['y', 'n'],
                                default_='y',
                                unique_='existing')
    if dropbox_backup == 'n': return None
    compress_file_name = local_file + ".7z"

    compress_ = "7z a " + compress_file_name + " " + local_file + " -p"
    print(compress_)
    confirm_ = cf.prompt_("Do you want to run the command? (y/n): ",
                          ['y', 'n'],
                          default_='y',
                          unique_='existing')
    if confirm_ == 'n': return None
    os.system(compress_)
    temp_file = os.path.join(project_dir, compress_file_name)
    dropbox_command = "cd ~/git_clones/Dropbox-Uploader/ && ./dropbox_uploader.sh upload " + temp_file + " " + remote_folder
    print(dropbox_command)
    confirm_ = cf.prompt_("Do you want to run the command? (y/n): ",
                          ['y', 'n'],
                          default_='y',
                          unique_='existing')
    if confirm_ == 'n': return None
    os.system(dropbox_command)
Exemplo n.º 2
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))
Exemplo n.º 3
0
def dropbox(master_backup_file):
    remote_folder = '/db/'
    print('master_backup_file: {}'.format(master_backup_file))
    dropbox_backup = cf.prompt_("Do you want to backup to Dropbox? (y/n): ",
                                ['y', 'n'],
                                default_='y',
                                unique_='existing')
    if dropbox_backup == 'n': return None
    compress_file_name = master_backup_file + ".7z"
    compress_ = "7z a " + compress_file_name + " " + master_backup_file + " -p"
    print(compress_)
    confirm_ = cf.prompt_("Do you want to run the command? (y/n): ",
                          ['y', 'n'],
                          default_='y',
                          unique_='existing')
    if confirm_ == 'n': return None
    os.system(compress_)
    dropbox_command = "cd ~/git_clones/Dropbox-Uploader/ && ./dropbox_uploader.sh upload " + compress_file_name + " " + remote_folder
    print(dropbox_command)
    confirm_ = cf.prompt_("Do you want to run the command? (y/n): ",
                          ['y', 'n'],
                          default_='y',
                          unique_='existing')
    if confirm_ == 'n': return None
    os.system(dropbox_command)
Exemplo n.º 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_()
Exemplo n.º 5
0
def backup_master():
    backup_folder = os.path.join(cf.project_dir, "backup")
    temp_name = cf.get_current_timestamp().replace("/", "")
    temp_name = temp_name.replace(":", "")
    temp_name = temp_name.replace(" ", "_")
    master_backup_file_name = "master_schema_" + temp_name + ".pgsql"
    master_backup_file = os.path.join(backup_folder, master_backup_file_name)
    backup_command = "pg_dump -Fc -U dba_tovak -d chip -h localhost -n master > " + master_backup_file
    print(master_backup_file)
    os.system(backup_command)
    size_print(master_backup_file)
    compress_file_name = master_backup_file + ".7z"
    compress_ = "7z a " + compress_file_name + " " + master_backup_file + " -p"
    print(compress_)
    confirm_ = cf.prompt_("Do you want to run the command? (y/n): ",
                          ['y', 'n'],
                          default_='y',
                          unique_='existing')
    if confirm_ == 'n': return None
    os.system(compress_)
    size_print(compress_file_name)
    remote_folder = '/db/master/'
    dropbox_command = "cd ~/git_clones/Dropbox-Uploader/ && ./dropbox_uploader.sh upload " + compress_file_name + " " + remote_folder
    print(dropbox_command)
    confirm_ = cf.prompt_("Do you want to run the command? (y/n): ",
                          ['y', 'n'],
                          default_='y',
                          unique_='existing')
    if confirm_ == 'n': return None
    os.system(dropbox_command)
Exemplo n.º 6
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)
Exemplo n.º 7
0
def ask_cost():
    cost_before_discount = cf.prompt_("Enter cost: ", [], empty_='yes')
    discount = cf.prompt_("Enter discount: ", [], empty_='yes')
    transport_cost = cf.prompt_("Enter Transport Cost: ", [], empty_='yes')
    if discount:
        cost = (Decimal(cost_before_discount) *
                Decimal(1 - discount / 100)).quantize(Decimal("1.00"))
    else:
        cost = cost_before_discount
    final_cost = cost + transport_cost
    print('finishing ask_cost...')
    return cost, final_cost
Exemplo n.º 8
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_
Exemplo n.º 9
0
 def edit_properties(self):
     property_ = cf.prompt_("Choose property to edit: ", sq_properties)
     if property_ == "id": return None
     old_value = getattr(self, property_)
     new_value = cf.prompt_("Enter new {} : ".format(property_), [],
                            default_=old_value)
     if old_value == new_value: return None
     if new_value == "quit": return "quit"
     if new_value == "back": return "back"
     if new_value:
         setattr(self, property_, new_value)
         cf.cursor_(sql.SQL(
             "update {} set {} = %s where id = %s returning {}").format(
                 sql.Identifier(self.owner_type), sql.Identifier(property_),
                 sql.Identifier(property_)),
                    arguments=(new_value, self.id))
Exemplo n.º 10
0
 def __init__(self, invoice_type, **kwargs):
     assert invoice_type in ["receipt", "payment"]
     self.invoice_type = invoice_type  # receipt | payment
     self.owner_type = cf.owner_type_d[
         self.invoice_type]  # customer | vendor
     self.id = kwargs.get('id_', '')
     if self.id:
         self.get_invoice_properties(**kwargs)
         print("Invoice exists and id is {}".format(self.id))
     else:
         self.gst_invoice_no = None
         owner_nickname = kwargs.get('nickname', '')
         if not owner_nickname:
             owner_nickname = self.ask_owner_nickname()
         if owner_nickname:
             id_ = owner.get_id_from_nickname(self.owner_type,
                                              owner_nickname)
         self.owner = owner.get_existing_owner_by_id(self.owner_type, id_)
         if self.owner:
             self.id_owner = self.owner.id
             self.amount = self.ask_amount()
             if self.amount:
                 self.date_ = get_date()
                 self.recipient, self.medium, self.detail = self.get_detail(
                 )
                 if self.recipient:
                     self.id = self.create_new_invoice()
                 make_gst_confirm = cf.prompt_("Make: ", ['y', 'n'],
                                               unique_="existing",
                                               empty_="yes")
                 if make_gst_confirm == "y":
                     self.makegst()
                     # self.save()
     cf.log_("Finished Money __init__")
Exemplo n.º 11
0
def get_date():
    today = datetime.date.today()
    get_date = cf.prompt_("Select: ", ['today', 'yesterday', 'other'], unique_ = "existing")
    if get_date == 'yesterday':
        the_date = today - datetime.timedelta(1)
    elif get_date == 'today':
        the_date = today
    elif get_date == 'other':
        while True:
            the_date = cf.prompt_("Enter date: ", [], default_=str(today))
            confirm_ = 'y'
            # confirm_ = cf.prompt_("Confirm date {} (y/n): ".format(the_date), [])
            if confirm_ == "y":
                break
    print(the_date)
    return the_date
Exemplo n.º 12
0
def select_file(the_date, type_):
    assert type_ in ['public', 'master']
    file_list = []
    for name in glob.glob('backup/' + the_date + '/' + type_ + '_*'):
        file_list.append(name)
    print(file_list)
    return cf.prompt_("select file: ", file_list, unique_="existing")
Exemplo n.º 13
0
 def set_gst_number(self):
     self.gst_number = cf.prompt_("Enter GST Number for {}: ".format(
         self.nickname), [],
                                  default_="27")
     cf.psql_("update {} set gst_number = %s where id = %s".format(
         self.owner_type),
              arg_=(self.gst_number, self.id))
Exemplo n.º 14
0
def delete_master():
    delete_command = "psql -U dba_tovak -d chip -h localhost -c 'drop schema master cascade'"
    confirm_ = cf.prompt_("Do you want to run the command? (y/n): ",
                          ['y', 'n'],
                          default_='y',
                          unique_='existing')
    if confirm_ == 'n': return None
    os.system(delete_command)
Exemplo n.º 15
0
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_
Exemplo n.º 16
0
def insert_invoice():
    debtors_list = cf.cursor_(
        sql.SQL("select distinct name_place from bank.sale_led"))
    debtors_list = [i[0] for i in debtors_list]
    while True:
        print("Enter 's' to stop")
        name_place = cf.prompt_("Enter debtor: ", debtors_list)
        if name_place == 's':
            break
        date_ = cf.prompt_("Enter Date in format 'YYYY-MM-DD': ", [],
                           default_='2018-02-')
        amount_ = cf.prompt_("Enter Amount: ", [])
        type_ = 'invoice'
        sq = "insert into bank.sale_led (type_, date_, name_place, amount) values (%s, %s, %s, %s) returning id"
        with conn() as cursor:
            cursor.execute(sq, (type_, date_, name_place, amount_))
        print('Entry was made in db')
Exemplo n.º 17
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
Exemplo n.º 18
0
def set_product_cost(a):
    cost_before_discount = cf.prompt_("Enter cost for {}: ".format(a[1]), [], default_=str(a[2]), empty_="yes")
    if cost_before_discount == "None":
        cost_before_discount = None
    if cost_before_discount:
        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)
Exemplo n.º 19
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]]
Exemplo n.º 20
0
 def ask_amount(self):
     amount = cf.prompt_("Enter amount: ", [])
     if amount == "quit": return None
     if amount == "back": return None
     if amount:
         try:
             return int(amount)
         except Exception as e:
             print(e)
             return None
Exemplo n.º 21
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)))
Exemplo n.º 22
0
def get_filter_result(filter_type, invoice_type, **kwargs):
    owner_type = cf.owner_type_d[invoice_type]
    owner_nickname = kwargs.get('nickname', '')
    if filter_type == "All Invoices":
        result = cf.cursor_(
            sql.SQL(
                "select s.invoice_no, s.date_, o.nickname, s.amount_before_freight, s.id from {} as s join {} as o on o.id = s.id_owner where s.gst_invoice_no is not null order by s.id desc"
            ).format(sql.Identifier(invoice_type), sql.Identifier(owner_type)))
    elif filter_type == "Unsaved Invoices":
        sq = 'select invoice_no, date_,  owner_name, owner_place, amount_after_freight, id from {} where id not in (select id_invoice from sale_transaction where id_invoice is not null)'.format(
            invoice_type)
        with conn() as cursor:
            cursor.execute(sq)
            result = cursor.fetchall()
    elif filter_type == "Search By Nickname":
        if not owner_nickname:
            with conn() as cursor:
                cursor.execute(
                    "select distinct id_owner from {}".format(invoice_type))
                id_list = cursor.fetchall()
            nickname_list = []
            for a in id_list:
                nickname_list.append(get_nickname_from_id(owner_type, a))
            owner_nickname = cf.prompt_("Enter {} Name: ".format(owner_type),
                                        nickname_list,
                                        unique_="existing")
            # owner_nickname = cf.prompt_("Enter {} Name: ".format(owner_type), cf.get_completer_list("nickname", owner_type))
        if invoice_type in ["receipt", "payment"]:
            result = cf.cursor_(sql.SQL(
                "select r.id, r.date_, c.name, r.amount from {} as r join {} as c on c.id = r.id_owner where c.nickname = %s"
            ).format(sql.Identifier(invoice_type), sql.Identifier(owner_type)),
                                arguments=(owner_nickname, ))
        else:
            result = cf.cursor_(sql.SQL(
                "select s.invoice_no, s.date_, o.nickname, s.amount_before_freight, s.id from {} as s join {} as o on o.id = s.id_owner where o.nickname = %s order by s.id desc"
            ).format(sql.Identifier(invoice_type), sql.Identifier(owner_type)),
                                arguments=(owner_nickname, ))
    elif filter_type == "All Estimates":
        result = cf.cursor_(
            sql.SQL(
                "select s.invoice_no, s.date_, o.nickname, s.amount_before_freight, s.id from {} as s join {} as o on o.id = s.id_owner where s.gst_invoice_no is null order by s.id desc limit 10"
            ).format(sql.Identifier(invoice_type), sql.Identifier(owner_type)))
    elif filter_type == "Last 10 Invoices":
        result = cf.cursor_(
            sql.SQL(
                "select s.invoice_no, s.date_, o.nickname, s.amount_before_freight, s.id from {} as s join {} as o on o.id = s.id_owner order by s.id desc limit 10"
            ).format(sql.Identifier(invoice_type), sql.Identifier(owner_type)))
    elif filter_type == "All Owner Invoices":
        result = cf.cursor_(sql.SQL(
            "select s.invoice_no, s.date_, o.nickname, s.amount_before_freight, s.id from {} as s join {} as o on o.id = s.id_owner where o.nickname = %s order by s.id desc"
        ).format(sql.Identifier(invoice_type), sql.Identifier(owner_type)),
                            arguments=(owner_nickname, ))
    return result
Exemplo n.º 23
0
 def set_gst_name(self):
     self.gst_name = cf.prompt_("Enter GST Owner Name for {}: ".format(
         self.nickname), [],
                                default_=self.name,
                                empty_="yes")
     if self.gst_name:
         cf.psql_("update {} set gst_name = %s where id = %s".format(
             self.owner_type),
                  arg_=(self.gst_name, self.id))
         return self.gst_name
     else:
         return None
Exemplo n.º 24
0
def add_pre_gst_balances():
    # one time use only
    while True:
        debtors_list = cf.cursor_(
            sql.SQL("select distinct name_place from bank.debtor"))
        debtors_list = [i[0] for i in debtors_list]
        action = cf.prompt_("Enter debtor: ", debtors_list, empty_="yes")
        if action == "back":
            continue
        if action == "quit":
            break
        amount = cf.prompt_("Enter amount: ", [])
        if amount == "back":
            continue
        if amount == "quit":
            break
        result = cf.cursor_(sql.SQL(
            "insert into bank.debtor (date_, name_place, amount) values (%s, %s, %s) returning id"
        ),
                            arguments=('2017-06-30', action, amount))
        print(result)
Exemplo n.º 25
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)
Exemplo n.º 26
0
 def edit_property(self, property_):
     if property_ == "id":
         cf.log_("You cannot change 'id' value")
         return None
     old_value = getattr(self, property_)
     new_value = cf.prompt_("Enter new {} [{}] : ".format(
         property_, old_value), [],
                            default_=str(old_value))
     setattr(self, property_, new_value)
     cf.cursor_(
         sql.SQL("update {} set {} = %s where id = %s returning id").format(
             sql.Identifier(self.invoice_type), sql.Identifier(property_)),
         arguments=(new_value, self.id))
Exemplo n.º 27
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_
Exemplo n.º 28
0
def sandbox(id_owner, owner_product):
    # TODO add feature to modify or add new rates
    result = cf.cursor_(sql.SQL(
        "select distinct p.name from product as p join {} as op on op.id_product = p.id where op.id_owner = %s"
    ).format(sql.Identifier(owner_product)),
                        arguments=(id_owner, ))
    product_custom_owner_list = [element[0] for element in result]
    while True:
        product_name = cf.prompt_("Enter Product Name: ",
                                  product_custom_owner_list,
                                  unique_="existing")
        if product_name == "quit": break
        if product_name == "back": break
        product_id = product.get_id_from_name(product_name)
        rate, discount = invoice_detail.get_previous_rate_discount(
            id_owner, owner_product, product_id)
        cf.log_("Rate: {}\nDiscount: {}".format(rate, discount))
Exemplo n.º 29
0
def get_pricelist_discount(invoice_, id_pricelist, id_product, **kwargs):
    big_pricelist_id = get_id_pricelist_by_name("GI Fitting Big")
    reducing_pricelist_id = get_id_pricelist_by_name("GI Fitting Reducing")
    elbow_id = get_id_pricelist_by_name("GI Fitting Elbow")
    id_owner = invoice_.owner.id
    invoice_type = invoice_.invoice_type
    owner_pricelist = cf.owner_pricelist_from_invoice_type_d[invoice_type]
    condition = get_old_pricelist_condition(owner_pricelist, id_owner,
                                            id_pricelist)
    cf.log_("finished get_old_pricelist_condition.\nCondition is {}".format(
        condition))
    pricelist_discount = get_old_pricelist_discount(owner_pricelist, id_owner,
                                                    id_pricelist, **kwargs)
    if not pricelist_discount:
        pricelist_discount = cf.prompt_("Enter Discount: ", [])
        set_pricelist_discount(owner_pricelist, id_owner, id_pricelist,
                               pricelist_discount, **kwargs)
        if id_pricelist == reducing_pricelist_id:
            print("Also updating discount of GI Fitting Big pricelist...")
            set_pricelist_discount(owner_pricelist, id_owner, big_pricelist_id,
                                   pricelist_discount, **kwargs)
        if id_pricelist == big_pricelist_id:
            print("Also updating discount of GI Fitting Reducing pricelist...")
            condition = get_old_pricelist_condition(owner_pricelist, id_owner,
                                                    reducing_pricelist_id,
                                                    **kwargs)
            set_pricelist_condition(owner_pricelist, id_owner, id_pricelist,
                                    condition)
            set_pricelist_discount(owner_pricelist, id_owner,
                                   reducing_pricelist_id, pricelist_discount,
                                   **kwargs)
    if condition:
        if condition == "non_reducing":
            product_name = product.get_product_name_from_id(id_product)
            product_name_for_condition = (
                product_name.split("Red. ")[1]).split(" X ")[0]
            id_product = product.get_product_details(
                product_name_for_condition)[0]
            print("Product Name For Condition is {} and its id is {}".format(
                product_name_for_condition, id_product))
    pricelist_value = get_pricelist_value(id_product)
    if id_pricelist == elbow_id and pricelist_discount < 15:
        pricelist_value = pricelist_discount
        pricelist_discount = 0
    return pricelist_value, pricelist_discount
Exemplo n.º 30
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)