Ejemplo n.º 1
0
 def __init_db(self):
     print(bcolors.BOLD + '---------- CREATE DB ----------' + bcolors.ENDC)
     self.pdao = ProfileDAO(DB_PATH)
     pdaoret = self.pdao.create_table()
     print(bcolors.HEADER + 'ProfileDAO ?> ' + bcolors.ENDC,
           bcolors.OKGREEN + 'OK' if pdaoret else bcolors.FAIL + "KO",
           bcolors.ENDC)
     self.idao = InsuranceDAO(DB_PATH)
     idaoret = self.idao.create_table()
     print(bcolors.HEADER + 'InsuranceDAO ?> ' + bcolors.ENDC,
           bcolors.OKGREEN + 'OK' if idaoret else bcolors.FAIL + "KO",
           bcolors.ENDC)
     self.fdao = InvoiceDAO(DB_PATH)
     fdaoret = self.fdao.create_table()
     print(bcolors.HEADER + 'InvoiceDAO ?> ' + bcolors.ENDC,
           bcolors.OKGREEN + 'OK' if fdaoret else bcolors.FAIL + "KO",
           bcolors.ENDC)
     self.cdao = ClientDAO(DB_PATH)
     cdaoret = self.cdao.create_table()
     print(bcolors.HEADER + 'ClientDAO ?> ' + bcolors.ENDC,
           bcolors.OKGREEN + 'OK' if cdaoret else bcolors.FAIL + "KO",
           bcolors.ENDC)
     self.qdao = QuotationDAO(DB_PATH)
     qdaoret = self.qdao.create_table()
     print(bcolors.HEADER + 'QuotationDAO ?> ' + bcolors.ENDC,
           bcolors.OKGREEN + 'OK' if qdaoret else bcolors.FAIL + "KO",
           bcolors.ENDC)
     self.qidao = QuotationItemDAO(DB_PATH)
     qidaoret = self.qidao.create_table()
     print(bcolors.HEADER + 'QuotationItemDAO ?> ' + bcolors.ENDC,
           bcolors.OKGREEN + 'OK' if qidaoret else bcolors.FAIL + "KO",
           bcolors.ENDC)
     return pdaoret and idaoret and fdaoret and cdaoret and qdaoret and qidaoret
Ejemplo n.º 2
0
 def setUp(self):
     self.qdao = QuotationDAO(DB_PATH)
     self.quotation = Quotation()
     self.quotation.client = "TEST 1"
     self.quotation.date_sent = "01/01/2020"
     self.quotation.date_validity = "01/01/2021"
     self.quotation.end_text = "TEST 2\nTEST 3\nTEST 4"
     self.quotation.id_profile = 1
     self.quotation.number = 230
     self.quotation.total = 2030.20
     self.quotation.tax_price = 55.10
Ejemplo n.º 3
0
def remove_quotation(n_quotation):
    ddao = QuotationDAO()
    didao = QuotationItemDAO()
    if didao.delete(didao.where('id_quotation', n_quotation)):
        ddao.delete(ddao.where('number', n_quotation))
        flash(
            _("The quotation n°%1 has been deleted successfull").replace(
                '%1', n_quotation), 'success')
        logging.info('remove quotation %s OK', n_quotation)
    else:
        flash(
            _('Error while suppression of quotation n°%1 !').replace(
                '%1', n_quotation), 'danger')
        logging.info('remove quotation %s FAILED', n_quotation)
Ejemplo n.º 4
0
def quotation_id(number=None):
    if not session.get('logged_in'):
        return redirect('/')
    logging.info('go url /quotation/%s', number)
    profile = get_profile_from_session()
    ddao = QuotationDAO()
    if not ddao.exist(ddao.where('number', number)):
        logging.info('redirect if quotation doesnt exist number: %s', number)
        return redirect('/quotation')
    quotation = ddao.get(ddao.where('number', number))[0]
    logging.info(
        'display pdf_template_quotation.html with quotation number: %s',
        number)
    return render_template('template/pdf_template_quotation.html',
                           profile=profile,
                           convert_date=convert_date,
                           quotation=quotation,
                           url="quotation")
Ejemplo n.º 5
0
def quotation():
    if not session.get('logged_in'):
        return redirect('/')
    profile = get_profile_from_session()
    ddao = QuotationDAO()
    l_quotation = ddao.get(ddao.where('id_profile', profile.id))
    logging.info('go url /quotation')
    last_quotation = l_quotation[-1].number if l_quotation else ''

    return render_template('quotation.html',
                           convert_date=convert_date,
                           Page_title=_('Quotation'),
                           quotation=reversed(l_quotation),
                           last_quotation=last_quotation,
                           profile=profile,
                           len=len,
                           color=Color,
                           url="quotation")
Ejemplo n.º 6
0
def add_quotation(form):
    profileSession = get_profile_from_session()
    if profileSession.id:
        id_profile = profileSession.id
    else:
        logging.warning('(Quotation) Session closed: %s', profileSession.id)
        flash(_("Impossible to add Quotation, Your session has been expired"),
              'danger')
        return

    ddao = QuotationDAO()
    n_quotation = form['quotation']

    if ddao.exist(ddao.where('number', n_quotation)):
        logging.info('quotation exist with number: %s', n_quotation)
        flash(
            _("Impossible to add Quotation, the number of quotation is ever used"
              ), 'danger')
        return

    client = form['client']
    date_sent = form['date_sent']
    date_validity = form['date_validity']
    tax = (form['tax'] == "true")
    lines = [(x.replace('lines[',
                        '').replace('][', '-').replace(']', ''), dict(form)[x])
             for x in dict(form) if x.startswith('lines[')]
    list_text = [
        dict(form)[x] for x in dict(form) if x.startswith('text_end[')
    ]
    quotation_obj = Quotation()
    quotation_obj.client = client
    quotation_obj.date_sent = date_sent
    quotation_obj.date_validity = date_validity
    quotation_obj.number = n_quotation
    quotation_obj.tax_price = 0
    quotation_obj.id_profile = id_profile
    quotation_obj.end_text = '\n'.join(list_text)

    didao = QuotationItemDAO()
    success = True
    nb_items = int(len(lines) / 3)
    list_quotation_item = list()
    for i in range(0, nb_items):
        quotationItem = QuotationItem()
        quotationItem.description = lines[(i * 3) + 0][1]
        quotationItem.quantity_text = lines[(i * 3) + 1][1]
        result = re.findall(r'[-+]?\d*\.\d+|^\d+', quotationItem.quantity_text)
        if len(result) == 0:
            result = [0]
        quotationItem.quantity = float(result[0])
        uprice = lines[(i * 3) + 2][1]
        if not uprice:
            uprice = 0
        quotationItem.unit_price = float(uprice)
        quotationItem.reduction = False
        list_quotation_item.append(quotationItem)
        quotation_obj.total += (quotationItem.quantity *
                                quotationItem.unit_price)
        if tax:
            quotation_obj.tax_price += (
                (quotationItem.quantity * quotationItem.unit_price) * 20 / 100)

    if not ddao.insert(quotation_obj):
        logging.info('add quotation %s FAILED', n_quotation)
        flash(
            _("Impossible to add quotation n°%1").replace('%1', n_quotation),
            'danger')
        return
    else:
        logging.info('add quotation %s OK', n_quotation)

    for quotationItem in list_quotation_item:
        quotationItem.id_quotation = quotation_obj.id
        success &= didao.insert(quotationItem)

    if not success:
        logging.warning('add quotation item %s FAILED', n_quotation)
        didao.delete(didao.where('id_quotation', n_quotation))
        ddao.delete(ddao.where('id', n_quotation))
        flash(
            _("Impossible to add quotation n°%1").replace('%1', n_quotation),
            'danger')
    else:
        logging.info('add quotation item %s OK', n_quotation)
        flash(
            _("The quotation n°%1 has been added successfull").replace(
                '%1', n_quotation), 'success')