def set_pricelist_discount(owner_pricelist, id_owner, id_pricelist, discount, **kwargs): gst_ = kwargs.get('gst_', '') try: if gst_: cf.cursor_(sql.SQL( "insert into {} (id_owner, id_pricelist, gst_discount) values (%s, %s, %s) returning discount" ).format(sql.Identifier(owner_pricelist)), arguments=(id_owner, id_pricelist, discount)) else: cf.cursor_(sql.SQL( "insert into {} (id_owner, id_pricelist, discount) values (%s, %s, %s) returning discount" ).format(sql.Identifier(owner_pricelist)), arguments=(id_owner, id_pricelist, discount)) except Exception as e: if e.pgcode == '23505': print("Updating ...") if gst_: with conn() as cursor: cursor.execute( sql.SQL( "update {} set ( gst_discount ) = (%s) where id_owner = %s and id_pricelist = %s" ).format(sql.Identifier(owner_pricelist)), (discount, id_owner, id_pricelist)) else: with conn() as cursor: cursor.execute( sql.SQL( "update {} set ( discount ) = (%s) where id_owner = %s and id_pricelist = %s" ).format(sql.Identifier(owner_pricelist)), (discount, id_owner, id_pricelist)) else: print(e)
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_()
def set_freight(self, freight): self.freight = freight self.set_amount_after_freight() cf.cursor_(sql.SQL( "update {} set (freight, amount_after_freight) = (%s, %s) where id = %s returning id" ).format(sql.Identifier(self.invoice_type)), arguments=(self.freight, self.amount_after_freight, self.id))
def show_table_count(table_): master_table = sql.SQL("master.") + sql.Identifier(table_) public_table = sql.SQL("public.") + sql.Identifier(table_) count_master = cf.cursor_( sql.SQL("select count(id) from {}").format(master_table)) count_public = cf.cursor_( sql.SQL("select count(id) from {}").format(public_table)) count_master = count_master[0][0] if count_master else 0 count_public = count_public[0][0] if count_public else 0 return count_master, count_public
def set_amount_after_freight(self): # converting None to 0 for calculation if not self.freight: self.freight = 0 if not self.amount_before_freight: self.amount_before_freight = 0 # called by set_freight, not called directly self.amount_after_freight = Decimal( self.amount_before_freight) + Decimal(self.freight) self.amount_after_freight = self.amount_after_freight.quantize( Decimal("1.00")) cf.cursor_(sql.SQL( "update {} set (amount_after_freight) = (%s) where id = %s returning id" ).format(sql.Identifier(self.invoice_type)), arguments=(self.amount_after_freight, self.id))
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))
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))
def get_old_pricelist_discount(owner_pricelist, id_owner, id_pricelist, **kwargs): gst_ = kwargs.get('gst_', '') if gst_: result = cf.cursor_(sql.SQL( "select gst_discount from {} where id_owner = %s and id_pricelist = %s" ).format(sql.Identifier(owner_pricelist)), arguments=(id_owner, id_pricelist)) else: result = cf.cursor_(sql.SQL( "select discount from {} where id_owner = %s and id_pricelist = %s" ).format(sql.Identifier(owner_pricelist)), arguments=(id_owner, id_pricelist)) if result: print("old pricelist discount is {}".format(result[0][0])) return result[0][0]
def get_pricelist_value(id_product): result = cf.cursor_(sql.SQL( "select value from product_pricelist where id_product = %s order by version desc limit 1" ), arguments=(id_product, )) print("pricelist value is {}".format(result[0][0])) return result[0][0]
def send_receipt_to_sale_led(): # one time use only result = cf.cursor_( sql.SQL("select date_, name_place, amount from bank.receipt")) for a in result: 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, ("receipt", a[0], a[1], a[2]))
def get_existing_id_pricelist(name): result = cf.cursor_( sql.SQL("select id from pricelist where lower(name) = %s"), arguments=(name.lower(), )) if result: return result[0][0] else: return None
def get_id_pricelist_from_id_product(id_product): result = cf.cursor_(sql.SQL( "select id_pricelist from product_pricelist where id_product = %s"), arguments=(id_product, )) if result: return result[0][0] else: return None
def set_pricelist_condition(owner_pricelist, id_owner, id_pricelist, condition): try: cf.cursor_(sql.SQL( "insert into {} (id_owner, id_pricelist, condition) values (%s, %s, %s) returning condition" ).format(sql.Identifier(owner_pricelist)), arguments=(id_owner, id_pricelist, condition)) except Exception as e: if e.pgcode == '23505': print("Updating ...") with conn() as cursor: cursor.execute( sql.SQL( "update {} set ( condition ) = (%s) where id_owner = %s and id_pricelist = %s" ).format(sql.Identifier(owner_pricelist)), (condition, id_owner, id_pricelist)) else: print(e)
def get_id_pricelist(id_product): result = cf.cursor_(sql.SQL( "select id_pricelist from product_pricelist where id_product = %s order by version desc limit 1" ), arguments=(id_product, )) if result: return result[0] else: print("No Price List") return None
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)))
def set_amount_after_gst(self): self.gst_5 = self.get_gst_amount(5) self.gst_12 = self.get_gst_amount(12) self.gst_18 = self.get_gst_amount(18) self.gst_28 = self.get_gst_amount(28) self.freight_gst = (Decimal(self.freight) * Decimal(0.18)).quantize( Decimal("1.00")) print('freight_gst: {}'.format(self.freight_gst)) total_gst = Decimal(self.gst_5 + self.gst_12 + self.gst_18 + self.gst_28 + self.freight_gst).quantize( Decimal("1.00")) self.amount_after_gst = (self.amount_after_freight + total_gst).quantize(Decimal("1")) print('amount_after_gst: {}'.format(self.amount_after_gst)) cf.cursor_(sql.SQL( "update {} set (gst_5, gst_12, gst_18, gst_28, freight_gst, amount_after_gst) = (%s, %s, %s, %s, %s, %s) where id = %s returning id" ).format(sql.Identifier(self.invoice_type)), arguments=(self.gst_5, self.gst_12, self.gst_18, self.gst_28, self.freight_gst, self.amount_after_gst, self.id))
def view(transaction_type, **kwargs): gst_ = kwargs.get('gst_', '') if transaction_type == "sale_transaction": m = "Receipt" elif transaction_type == "purchase_transaction": m = "Payment" columns = [ 'ID', 'Date', 'Type', 'Owner ID', 'Invoice ID', m + ' ID', ' Amount' ] if gst_: result = cf.cursor_( sql.SQL( "select id, date_, type, id_owner, id_invoice, id_voucher, amount from {}" ).format(sql.Identifier(transaction_type))) else: result = cf.cursor_( sql.SQL( "select id, date_, type, id_owner, gst_invoice_no, id_voucher, amount from {}" ).format(sql.Identifier(transaction_type))) cf.pretty_table_multiple_rows(columns, result)
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)
def view_by_nickname(transaction_type, nickname, **kwargs): gst_ = kwargs.get('gst_', '') if transaction_type == "sale_transaction": m = "Receipt" owner_type = "customer" else: m = "Payment" owner_type = "vendor" columns = ['ID', 'Date', 'Type', 'Invoice ID', m + ' ID', ' Amount'] if gst_: result = cf.cursor_(sql.SQL( "select t.id,t.date_,t.type, t.id_invoice, t.id_voucher, t.amount from {} as t where t.id_owner = %s where t.gst_invoice_no is not null" ).format(sql.Identifier(transaction_type)), arguments=(owner.get_id_from_nickname( owner_type, nickname, no_create="yes"), )) else: result = cf.cursor_(sql.SQL( "select t.id,t.date_,t.type, t.id_invoice, t.id_voucher, t.amount from {} as t where t.id_owner = %s where t.gst_invoice_no is null" ).format(sql.Identifier(transaction_type)), arguments=(owner.get_id_from_nickname( owner_type, nickname, no_create="yes"), )) cf.pretty_table_multiple_rows(columns, result)
def add_and_modify_existing(table_): master_table = sql.SQL("master.") + sql.Identifier(table_) public_table = sql.SQL("public.") + sql.Identifier(table_) with conn() as cursor: # source: public.* # target: master.* # source names are not visible in the update part cu_joined = sql.SQL(',').join( sql.SQL('excluded.') + sql.Identifier(n) for n in properties_dict[table_]) sqcu = sql.SQL( "insert into {} select * from {} on conflict (id) do update set ({}) = ({}) returning id" ).format( master_table, public_table, sql.SQL(', ').join( sql.Identifier(n) for n in properties_dict[table_]), cu_joined) cursor.execute(sqcu) # delete master.customer records which are not in public.customer cf.cursor_( sql.SQL( "delete from {} as m where not exists (select * from {} p where m.id = p.id) returning id" ).format(master_table, public_table))
def make_dr_entries(): debtors_list = cf.cursor_( sql.SQL("select distinct name_place from bank.debtor")) debtors_list = [i[0] for i in debtors_list] result = cf.cursor_( sql.SQL( "select date_, desc_, ref_cheque, amount, type_, id from bank.bank_statement where type_ = 'CR' and debtor_name is null order by id" )) for result in result: date_ = result[0] print(date_) desc_ = str(result[1]) ref_cheque = str(result[2]) amount = result[3] type_ = str(result[4]) id_ = result[5] cf.pretty_table_print( ['date', 'desc', 'ref_cheque', 'amount', 'type'], [str(date_), desc_, ref_cheque, str(amount), type_]) options_list = get_options_list(amount) print(options_list) action = cf.prompt_("Enter debtor: ", debtors_list, empty_="yes") if action == "back": continue if action == "quit": break if action in debtors_list: receipt_entry = cf.cursor_(sql.SQL( "insert into bank.receipt (date_, name_place, amount) values (%s, %s, %s) returning id" ), arguments=(date_, action, amount)) print(receipt_entry) with conn() as cursor: cursor.execute( "update bank.bank_statement set (debtor_name) = (%s) where id = %s returning id", (action, id_)) debtor_name_entry = cursor.fetchone()[0] print(debtor_name_entry)
def get_owner_product_abbr_dict(owner_product, id_owner): result = cf.cursor_(sql.SQL( "select p.abbr_name, cast(o.rate as text), date(timestamp_), p.name from {} as o right outer join product as p on p.id = o.id_product and o.id_owner = %s where p.abbr_name is not null order by o.timestamp_ desc nulls last" ).format(sql.Identifier(owner_product)), arguments=(id_owner, )) if not result: return None result = [(v[0], v[3]) if v[1] is None else (v[0], v[1] + " (" + v[3] + ") " + str(v[2])) for v in result] # cf.log_(result) # convert tuple to dictionary # cf.log_(result) product_dict = dict(result) product_list_sorted = [v[0] for v in result] # product_list_sorted = sorted(product_list, key=product_list.get, reverse=True) # cf.log_(product_list_sorted) # cf.log_(product_list) return product_list_sorted, product_dict
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))
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')
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
def get_old_pricelist_condition(owner_pricelist, id_owner, id_pricelist): cf.log_("inside get_old_pricelist_condition") reducing_pricelist_id = get_id_pricelist_by_name("GI Fitting Reducing") if id_pricelist == reducing_pricelist_id: result = cf.cursor_(sql.SQL( "select condition from {} where id_owner = %s and id_pricelist = %s" ).format(sql.Identifier(owner_pricelist)), arguments=(id_owner, id_pricelist)) if result: if result[0][0] in ['reducing', 'non_reducing']: return result[0][0] condition = cf.prompt_("Enter Condition: ", ['reducing', 'non_reducing'], unique_="existing") if condition: set_pricelist_condition(owner_pricelist, id_owner, id_pricelist, condition) return condition return None
def add_saved(table_): master_table = sql.SQL("master.") + sql.Identifier(table_) public_table = sql.SQL("public.") + sql.Identifier(table_) if table_ in ["sale_invoice", "si_detail"]: transaction_table = "sale_transaction" if table_ == "sale_invoice": where_field = sql.Identifier("id") elif table_ == "si_detail": where_field = sql.Identifier("id_invoice") elif table_ in ["purchase_invoice", "pi_detail"]: transaction_table = "purchase_transaction" if table_ == "purchase_invoice": where_field = sql.Identifier("id") elif table_ == "pi_detail": where_field = sql.Identifier("id_invoice") result = cf.cursor_( sql.SQL( "select distinct id_invoice from {} where gst_invoice_no is null"). format(sql.Identifier(transaction_table))) saved_id_list = [ element for tupl in result for element in tupl if element is not None ] saved_id_tuple = tuple(saved_id_list) if saved_id_tuple: with conn() as cursor: # source: public.* # target: master.* # source names are not visible in the update part joined = sql.SQL(',').join( sql.SQL('excluded.') + sql.Identifier(n) for n in properties_dict[table_]) sq = sql.SQL( "insert into {} select * from {} where {} in %s returning id" ).format( master_table, public_table, where_field, sql.SQL(', ').join( sql.Identifier(n) for n in properties_dict[table_]), joined) cursor.execute(sq, (saved_id_tuple, )) result = cursor.fetchall() # print("\nAfter Update") # master_count, public_count=show_table_count(master_table, pt=public_table) return saved_id_tuple
def view_ledger(): debtors_list = cf.cursor_( sql.SQL("select distinct name_place from bank.debtor")) debtors_list = [i[0] for i in debtors_list] while True: action = cf.prompt_("Enter debtor: ", debtors_list, empty_="yes") if action == "back": continue if action == "quit": break with conn() as cursor: cursor.execute( "select date_, invoice_amount, receipt_amount, ts-tr from bank.sale_led_view where name_place = %s", (action, )) result = cursor.fetchall() columns = ['date', 'invoice_amount', 'receipt_amount', 'balance'] right_align_columns = ['invoice_amount', 'receipt_amount', 'balance'] left_align_columns = ['date'] pt = PrettyTable(columns) # pt.set_style(PLAIN_COLUMNS) for a in result: a0 = cf.reverse_date(str(a[0])) if a[1] is None: a1 = '' else: a1 = a[1] if a[2] is None: a2 = '' else: a2 = a[2] pt.add_row([a0, a1, a2, a[3]]) pt.align = 'r' for l in left_align_columns: pt.align[l] = 'l' # for r in right_align_columns: # pt.align[r] = 'r' print(pt)
def startswith_command(input_, invoice_): # Possible Return Values: # 1. ["continue", "continue"] if input_.startswith('pr '): no_of_prints = int(input_.split("pr ")[1]) if no_of_prints < 3: invoice_.update_invoice_with_sub_total() # create pdf of invoice sale_report.create_(invoice_, 'A6', no_of_print=no_of_prints) if input_.startswith('lr '): transport_lr_no = input_.split(" ")[1] invoice_.transport_lr_no = transport_lr_no cf.log_("transport_lr_no is {}".format(transport_lr_no)) cf.cursor_(sql.SQL( "update {} set (transport_lr_no) = (%s) where id = %s returning id" ).format(sql.Identifier(invoice_.invoice_type)), arguments=(transport_lr_no, invoice_.id)) if input_.startswith('fr '): freight = input_.split(" ")[1] cf.log_("freight is {}".format(freight)) try: if not float(freight).is_integer: freight = float(freight) except Exception as e: cf.log_(e) cf.log_("Incorrect value for freight") return {"arg1": "continue"} invoice_.set_freight(Decimal(freight)) invoice_.update_invoice_with_sub_total() invoice_.view_invoice_details(invoice_.fetch_invoice_details()) if input_.startswith('bn '): print('invoice_.gst_invoice_no is {}'.format(invoice_.gst_invoice_no)) if invoice_.gst_invoice_no is None: barrel_nipple.BarrelNipple(input_, invoice_) else: barrel_nipple.BarrelNipple(input_, invoice_, gst_=True) invoice_.update_invoice_with_sub_total() invoice_.view_invoice_details(invoice_.fetch_invoice_details()) if input_.startswith('ex '): print('invoice_.gst_invoice_no is {}'.format(invoice_.gst_invoice_no)) if invoice_.gst_invoice_no is None: extension.Extension(input_, invoice_) else: extension.Extension(input_, invoice_, gst_=True) # after implementing init_by_id in invoice_detail, the following code can be used as starting point to see only the added Extension items ''' id_result = ex.invoice_detail_id_list id_list = [element for tupl in id_result for element in tupl] cf.log_(id_list) temp_list = [] for id_ in id_list: i_detail_ = invoice_detail.InvoiceDetail(invoice_, product_name, id_=id_list) temp_list.append(i_detail_.get_detail_values()) cf.log_(temp_list) ''' invoice_.update_invoice_with_sub_total() invoice_.view_invoice_details(invoice_.fetch_invoice_details()) if input_.startswith(','): if input_ == ",,": return {"arg1": ","} return {"arg1": input_.split(",")[1]} return {"arg1": "continue"}
def get_id_owner_from_id(self, id_): # id is invoice table id result = cf.cursor_( sql.SQL("select id_owner from {} where id = %s").format( sql.Identifier(self.invoice_type)), arguments=(id_, )) return result[0][0]