Ejemplo n.º 1
0
 def __init__(self, user_email, price_limit, item_id, active=True, last_checked=None, _id=None):
     self.user_email = user_email
     self.price_limit = price_limit
     self.item = Item.get_by_id(item_id)
     self.last_checked = datetime.datetime.utcnow() if last_checked is None else last_checked
     self._id = uuid.uuid4().hex if _id is None else _id
     self.active = active
Ejemplo n.º 2
0
 def __init__(self, user_email, price_limit, item_id, active=True, last_checked=None, _id=None):
     self.user_email = user_email
     self.price_limit = price_limit
     self.active = active
     self.item = Item.get_by_id(item_id)
     self.last_checked = datetime.datetime.utcnow() if last_checked is None else last_checked
     self._id = uuid.uuid4().hex if _id is None else _id
Ejemplo n.º 3
0
def edit_item(item_id):
    item = Item.get_by_id(item_id)
    companies = Item_company.get_all_companies()
    types = Type.get_all_types()

    if request.method == 'POST':
        model_name = request.form.get('model_name')
        x = request.form.get('company_name')
        company = request.form.get('add_new_company')
        hsn_code = request.form.get('hsn_code')
        type = request.form.get('add_new_type')
        y = request.form.get('type')

        tax = request.form.get('tax')
        price = request.form.get('price')
        if company == None:
            company = x
        if type == None:
            type = y
        # print(model_name,x,company,hsn_code,type,y,tax,price)
        item = Item(hsn_code, company, model_name, type, tax, price, item_id)
        item.save_to_mongo()
        return redirect(url_for('.index'))

    return render_template('items/edit_item.jinja2',
                           item=item,
                           companies=companies,
                           types=types,
                           new_item_page=True)
Ejemplo n.º 4
0
 def __init__(self,
              user_email,
              price_limit,
              item_id,
              last_checked,
              _id=uuid4().hex):
     self.user_email = user_email
     self.price_limit = price_limit
     self.item = Item.get_by_id(item_id)
     self.last_checked = datetime.utcnow(
     ) if not last_checked else last_checked
     self._id = _id
Ejemplo n.º 5
0
def update_item_price(item_id):
    """
    Checks if price has changed. Connected to the monitors.html template.
    :return:
    """
    item = Item.get_by_id(item_id)

    current_price = item.load_price()
    old_price = item.price
    if old_price == current_price:
        return redirect(url_for('users.user_monitors', alert='No changes!'))
    else:
        # save new price
        pass
    pass
Ejemplo n.º 6
0
 def __init__(self,
              user_email,
              price_limit,
              item_id,
              active=True,
              last_checked=None,
              _id=None):
     self.active = active
     self.user_email = user_email
     self.price_limit = price_limit
     self.item = Item.get_by_id(item_id)
     utc_now = pytz.utc.localize(datetime.datetime.utcnow())
     time_now = utc_now.astimezone(pytz.timezone("America/Chicago"))
     self.last_checked = time_now if last_checked is None else last_checked
     self._id = uuid.uuid4().hex if _id is None else _id
Ejemplo n.º 7
0
def update_alert(alert_id):
    alert = Alert.get_by_id(alert_id)
    item = Item.get_by_id(alert.item._id)
    # in case we receive GET - this is the first time the page is opened
    # in case we receive  POST - we have the details
    if request.method == 'GET':
        return render_template('alerts/edit_alert.html', alert=alert)
    else:
        # get from the request the newly created alert details
        price_limit = float(request.form['price_limit'])

        alert.price_limit = price_limit
        alert.save_to_mongo()

        return redirect(url_for('users.user_alerts'))
Ejemplo n.º 8
0
 def __init__(self,
              user_email,
              price_limit,
              item_id,
              active=True,
              store=None,
              last_checked=None,
              _id=None):
     self.user_email = user_email
     self.price_limit = float(price_limit)
     self.item = Item.get_by_id(item_id)
     self.last_checked = datetime.datetime.utcnow(
     ) if last_checked is None else last_checked
     self._id = uuid.uuid4().hex if _id is None else _id
     self.active = active
     store = Store.find_by_url(self.item.url)
     self.store = store.name
Ejemplo n.º 9
0
    def get_data_for_serial_no_list():
        json_datas = []
        serial_nos = Serial_no.get_all_serial_no()
        for serial_no in serial_nos:
            invoice_item = Invoice_item.get_by_id(serial_no.invoice_item_id)
            invoice_item.item_id = Item.get_by_id(invoice_item.item_id)
            invoice = Invoice.get_by_id(invoice_item.invoice_id)
            invoice.party_id = Party.get_by_id(invoice.party_id)
            x = "<td><div class=\"dropdown-content\"><a id=\"navbarDropdownMenuLink" + invoice._id + "\" href=\"#\" data-toggle=\"dropdown\"aria-haspopup=\"true\" aria-expanded=\"false\" class=\"nav-link tasks-toggle\"><i class=\"icon-new-file\"></i></a><div aria-labelledby=\"navbarDropdownMenuLink" + invoice._id + "\" class=\"invoice_datatable dropdown-menu tasks-list\"><a href=\"/invoices/print/" + invoice._id + "\" class=\"dropdown-item\"><div class=\"text d-flex justify-content-between\"><strong><i class=\"fa fa-file-pdf-o fa fw\" style=\"margin-right: 6px;padding-left: 3px;\"></i>Print</strong></div></a></div></div></td>"

            json_data = {
                "no": serial_no.serial_no,
                "invoice_no": invoice.no,
                "date": datetime.datetime.strftime(invoice.date, "%d-%m-%y"),
                "item": invoice_item.item_id.model_name,
                "party": invoice.party_id.name,
                "city": invoice.party_id.city,
                "price": invoice_item.rate_per,
                "action": x,
            }
            json_datas.append(json_data)
        return json_datas
Ejemplo n.º 10
0
    def make_final_workbook(self):
        gst=[]
        igst = []
        gst.append(['Date','Number','Party Name','City','GSTIN','Product Model Name','Quantity','Rate Per','Base Price','SGST','CGST','Total','Serial_No','e-Way Bill No.'])
        igst.append(['Date', 'Number', 'Party Name', 'City', 'GSTIN', 'Product Model Name', 'Quantity', 'Rate Per',
                    'Base Price', 'IGST', 'Total', 'Serial_No','e-Way Bill No.'])
        gst.append([])
        igst.append([])
        invoices = Invoice.filter_by_date(self.start,self.end)
        print(invoices)

        for invoice in invoices:
            total_invoice,total_base_price,total_tax = 0,0,0
            invoice.date = datetime.datetime.strftime(invoice.date,'%d-%m-%Y')
            invoice.party_id = Party.get_by_id(invoice.party_id)
            invoice_items = Invoice_item.get_by_invoice_id(invoice._id)
            flag = False
            if invoice.party_id.tax_type() == 'gst':
                flag = True
            for invoice_item in invoice_items:

                invoice_item.item_id = Item.get_by_id(invoice_item.item_id)
                y = []
                serial_nos = Serial_no.get_by_invoice_item_id(invoice_item._id)
                q=''
                for i in serial_nos:
                    q = q+i.serial_no+'\n'
                print(q)
                invoice_item.quantity = int(invoice_item.quantity)
                invoice_item.rate_per = float(invoice_item.rate_per)
                invoice_item.item_id.tax = float(invoice_item.item_id.tax)
                base_price = invoice_item.rate_per * invoice_item.quantity
                tax = (base_price * invoice_item.item_id.tax) / 100
                total = base_price + tax
                total_base_price +=base_price
                total_tax +=tax
                total_invoice+=total
                if flag:
                    y = [invoice.date,
                         invoice.no,
                         invoice.party_id.name,
                         invoice.party_id.city,
                         invoice.party_id.gstin,
                         invoice_item.item_id.model_name,
                         invoice_item.quantity,
                         invoice_item.rate_per,
                         base_price,
                         tax/2,
                         tax/2,
                         total,
                         q]
                    gst.append(y)
                else:
                    y = [invoice.date,
                         invoice.no,
                         invoice.party_id.name,
                         invoice.party_id.city,
                         invoice.party_id.gstin,
                         invoice_item.item_id.model_name,
                         invoice_item.quantity,
                         invoice_item.rate_per,
                         base_price,
                         tax,
                         total,
                         q]
                    igst.append(y)
            if flag:
                gst.append(['','','','','','','','','',total_base_price,total_tax/2,total_tax/2,total_invoice,invoice.e_way])
                gst.append([])
            else:
                igst.append(['','','','','','','','','',total_base_price,total_tax,total_invoice,invoice.e_way])
                igst.append([])
        print(igst)
        print(gst)
        for i in igst:
            print(i)
        print()
        for i in gst:
            print(i)
        self.gst = gst
        self.igst = igst
        self.make_workbook(gst,igst)
Ejemplo n.º 11
0
def print_invoice(invoice_id):
    print(invoice_id)
    company = Company.get_company()
    company[0].address = format(company[0].address)
    company[0].address = Utils.format_address(company[0].address)

    invoice = Invoice.get_by_id(invoice_id)

    if (invoice is None):
        invoice = Invoice.get_by_no(invoice_id)
    invoice_id = invoice._id
    invoice.date = datetime.datetime.strftime(invoice.date, "%d-%m-%Y")
    invoice_items = Invoice_item.get_by_invoice_id(invoice_id)
    invoice_package = {}
    invoice_package['invoice'] = invoice
    #invoice_package.append(invoice)
    party = Party.get_by_id(invoice.party_id)
    party.address = Utils.format_address(party.address)
    invoice_package['party'] = party
    tax_type = party.tax_type()
    tax, igst, round_off, total_amount, hsn_taxable_tot, total_quantity = 0.0, 0.0, 0.0, 0.0, 0.0, 0
    hsn_list = {}

    invoice_package['invoice_items'] = []
    sr = 0
    for invoice_item in invoice_items:
        sr += 1
        serial_no = Serial_no.get_by_invoice_item_id(invoice_item._id)
        total_quantity += invoice_item.quantity
        #invoice_package.append([invoice_item,serial_no])

        item = Item.get_by_id(invoice_item.item_id)
        print(item.type_id)
        amount_item = int(invoice_item.quantity) * float(invoice_item.rate_per)

        if item.hsn not in hsn_list:
            hsn_list[item.hsn] = [0, invoice_item.rate_per, 0, 0, item.tax]

        if tax_type == "gst":
            tax1 = amount_item * float(item.tax) / 200
            total_amount += (tax1 * 2)
        else:
            tax1 = amount_item * float(item.tax) / 100
            total_amount += tax1

        hsn_list[item.hsn][2] += tax1
        hsn_list[item.hsn][0] += amount_item

        if tax_type == "gst":
            hsn_list[item.hsn][3] += tax1 * 2
        else:
            hsn_list[item.hsn][3] += tax1
        hsn_taxable_tot += amount_item
        tax += tax1

        print('Type_obj', item.type_id)
        item.type_id = Type.get_by_id(item.type_id)

        print(item.type_id)
        print()
        invoice_package['invoice_items'].append({
            "invoice_item": invoice_item,
            "item": item,
            "serial_no": serial_no,
            "amount": amount_item,
            "sr_no": sr
        })
    if tax_type == "gst":
        x = tax * 2
    else:
        x = tax
    invoice_package['total_tax_amount'] = x
    total = hsn_taxable_tot + x
    round_off = abs(round(total) - total)

    invoice_package['hsn_taxable_total'] = hsn_taxable_tot
    invoice_package['tax'] = tax
    invoice_package['total_items'] = len(invoice_items)
    invoice_package['round_off'] = round_off
    invoice_package['total'] = total
    invoice_package['tax_type'] = tax_type
    invoice_package['company'] = company[0]
    invoice_package['total_words'] = Utils.get_currency_words(total)
    if tax_type == "gst":
        invoice_package['tax_words'] = Utils.get_currency_words(tax * 2)
    else:
        invoice_package['tax_words'] = Utils.get_currency_words(tax)
    invoice_package['hsn_list'] = hsn_list
    invoice_package['total_quantity'] = total_quantity
    #for i in invoice_package:
    #   print(i,invoice_package[i])

    #print()

    #for i in invoice_package['invoice_items']:
    #    print(i)

    print(invoice_package['hsn_list'])
    #print(company[0].address)
    #print(party.address)
    return render_template('invoices/invoice_print.jinja2',
                           invoice_package=invoice_package)
Ejemplo n.º 12
0
def edit_invoice(invoice_id):
    parties = Party.get_parties()
    items = Item.get_items()
    invoice_items = Invoice_item.get_by_invoice_id(invoice_id)

    company = Company.get_company()
    invoice = Invoice.get_by_id(invoice_id)
    invoice.date = datetime.datetime.strftime(invoice.date, "%d-%m-%Y")
    invoice_package = {}
    invoice_package['invoice'] = invoice

    party = Party.get_by_id(invoice.party_id)

    invoice_package['party'] = party
    tax_type = party.tax_type()
    tax, igst, round_off, total_amount, hsn_taxable_tot, total_quantity = 0.0, 0.0, 0.0, 0.0, 0.0, 0

    invoice_package['invoice_items'] = []
    sr = 0

    for invoice_item in invoice_items:
        sr += 1
        serial_no = Serial_no.get_by_invoice_item_id(invoice_item._id)
        total_quantity += invoice_item.quantity
        item = Item.get_by_id(invoice_item.item_id)
        amount_item = int(invoice_item.quantity) * float(invoice_item.rate_per)
        if tax_type == "gst":
            tax1 = amount_item * float(item.tax) / 200
            total_amount += (tax1 * 2)
        else:
            tax1 = amount_item * float(item.tax) / 100
            total_amount += tax1
        tax += tax1
        hsn_taxable_tot += amount_item
        invoice_package['invoice_items'].append({
            "invoice_item": invoice_item,
            "item": item,
            "serial_no": serial_no,
            "amount": amount_item,
            "sr_no": sr
        })

    if tax_type == "gst":
        x = tax * 2
    else:
        x = tax
    invoice_package['total_tax_amount'] = x
    total = hsn_taxable_tot + x
    round_off = abs(round(total) - total)
    invoice_package['tax'] = tax
    invoice_package['total_items'] = len(invoice_items)
    invoice_package['round_off'] = round_off
    invoice_package['total'] = total
    invoice_package['tax_type'] = tax_type
    invoice_package['company'] = company[0]

    #    for i in invoice_package:
    #        print(i,invoice_package[i])

    if request.method == 'POST':
        Invoice.get_by_id(invoice_id).delete()
        string = {}
        data = request.form
        print(data)
        print()
        for key in data.keys():
            for value in data.getlist(key):
                string[key] = value

        for i in string:
            print(i, string[i])
        # ---- Invoice Creation ----

        no = string['number']
        party_id = Party.get_by_gstin(string['select_party'])

        date = string['date']
        narration = string['narration']

        invoice_amount = string['total_amount']
        e_way = string['e_way']

        invoice = Invoice(no, party_id._id, invoice_amount, date, narration,
                          e_way)
        invoice.save_to_mongo()
        # --- Find Items
        items = []
        serial_no = {}

        for i in string:
            print(i[:7])
            if i[:12] == 'select_item_':
                items.append([i, string[i][14::]])

            if i[:7] == 'myModal':
                if i[8] != '_':
                    num = int(i[7]) * 10 + int(i[8])
                else:
                    num = int(i[7])
                if str(num) not in serial_no:
                    serial_no[str(num)] = []

                serial_no[str(num)].append(string[i])

        # print(items)
        item_details = []
        for i in range(len(items)):
            item = items[i][0][12::]
            quantity = string['quantity_' + item]
            rate_per = string['rate_per_' + item]
            item_details.append(
                [item, items[i][1], quantity, rate_per, serial_no[item]])

        # print()
        # print(item_details)

        for i in item_details:
            item_id = Item.get_by_name(i[1])
            print(invoice._id, item_id, float(i[3]), int(i[2]))
            invoice_item = Invoice_item(invoice._id, item_id._id, float(i[3]),
                                        int(i[2]))
            invoice_item.save_to_mongo()
            for j in i[4]:
                serial_no = Serial_no(invoice_item._id, j)
                serial_no.save_to_mongo()
        # print()
        # print(serial_no)
        # print(string)

        return redirect(url_for('.print_invoice', invoice_id=invoice._id))

    return render_template('invoices/edit_invoice.jinja2',
                           invoice_package=invoice_package,
                           edit_invoice_page=True,
                           parties=parties,
                           items=items,
                           company=Company.get_company()[0])
Ejemplo n.º 13
0
 def get_item_price(self):
     return Item.get_by_id(self.item_id).price
Ejemplo n.º 14
0
 def get_itemobject_by_id(_id):
     return Item.get_by_id(_id)