Exemplo n.º 1
0
 def test_delete_a_product(self):
     """ Delete a Product """
     p = Product(0, 'Asus2500', 'Laptop', '234', 'laptop', 'blue', 4)
     p.save()
     self.assertEqual(len(Product.all()), 1)
     # delete the product and make sure it isn't in the database
     p.delete()
     self.assertEqual(len(Product.all()), 0)
Exemplo n.º 2
0
 def test_add_a_product(self):
     """ Create a product and add it to the database """
     p = Product.all()
     self.assertEqual(p, [])
     p = Product(0, 'Asus2500', 'Laptop', '234', 'laptop', 'blue', 4)
     self.assertTrue(p != None)
     self.assertEqual(p.id, 0)
     p.save()
     # Asert that it was assigned an id and shows up in the database
     self.assertEqual(p.id, 1)
     products = Product.all()
     self.assertEqual(len(products), 1)
Exemplo n.º 3
0
    def get(self):
        """ Returns all of the Products """
        app.logger.info('Request to list Products...')
        results = []
        category = request.args.get('category')
        #print (category)
        name = request.args.get('name')
        if category:
            # print("Category is " + category)
            results = Product.find_by_category(str(category).lower())
        elif name:
            results = Product.find_by_name(str(name).lower())
        else:
            results = Product.all()

            # for pro in results:
            #     print(pro.id)
        # app.logger.info('[%s] Products returned', len(results))
        # return make_response(jsonify([p.serialize() for p in results]),
        #                     HTTP_200_OK)
        resultsUpd = [prod.serialize() for prod in results]

        # for prod in resultsUpd:
        #     print(prod['id'])

        return resultsUpd, status.HTTP_200_OK
Exemplo n.º 4
0
    def get(self, category=None):
        if self.request.get('offset'):
            offset = int(self.request.get('offset'))
        else:
            offset = 0

        if self.request.get('limit'):
            limit = int(self.request.get('limit'))
        else:
            limit = 15

        if category:
            products = Product.all().order('-created').filter('category =', category).fetch(limit, offset=offset)
        else:
            products = Product.all().order('-created').fetch(limit, offset=offset)
        
        self.render_template('get_read', { 'products' : products, 'offset' : offset, 'limit' : limit, 'category' : category })
Exemplo n.º 5
0
 def get(self, subdomain):
     namespace_manager.set_namespace(subdomain)
     products = Product.all()
     context = {
                'url':webapp2.uri_for('addproducts'),
                'products':products
                }
     self.render_response('admin-products.html',**context)
Exemplo n.º 6
0
def warning_of_prod():
    """"""
    list_w = []
    for store in Store.all():
        for prod in Product.all():
            report = last_report_store_prod(store.name, prod.name)
            try:
                if report.remaining < Config.nb_warning:
                    list_w.append(report)
            except AttributeError:
                pass
    return list_w
Exemplo n.º 7
0
def warning_of_prod():
    """"""
    l = []
    for store in Store.all():
        for prod in Product.all():
            report = last_report_store_prod(store.name, prod.name)
            try:
                if report.remaining < Config.nb_warning:
                    l.append(report)
            except AttributeError:
                pass
    return l
Exemplo n.º 8
0
def list_product():
    """ Retrieves a list of products from the database """
    results = []
    category = request.args.get('category')
    name = request.args.get('name')
    if category:
        results = Product.find_by_category(category)
    elif name:
        results = Product.find_by_name(name)
    else:
        results = Product.all()

    return jsonify([p.serialize() for p in results]), HTTP_200_OK
Exemplo n.º 9
0
 def get(self, subdomain):
     '''query'''
     search = self.request.get('search_input')
     
     '''Changing namespace'''
     namespace_manager.set_namespace(subdomain)
     ''''''
     
     query = Product.all().search(search)
     
     context = {'products':query,
                'imagelinker':image_linker}
     
     self.render_response('search-result.html',**context)
Exemplo n.º 10
0
 def test_update_a_product(self):
     """ Update a Product """
     p = Product(0, 'Asus2500', 'Laptop', '234', 'laptop', 'blue', 4)
     p.save()
     self.assertEqual(p.id, 1)
     # Change it an save it
     p.category = "gaming_laptop"
     p.save()
     self.assertEqual(p.id, 1)
     # Fetch it back and make sure the id hasn't changed
     # but the data did change
     products = Product.all()
     self.assertEqual(len(products), 1)
     self.assertEqual(products[0].category, "gaming_laptop")
    def get(self):
        app.logger.info('Request to list Products...')
        category = request.args.get('category')
        name = request.args.get('name')
        if category:
            results = Product.find_by_category(str(category).lower())
        elif name:
            results = Product.find_by_name(str(name).lower())
        else:
            results = Product.all()

        resultsUpd = [prod.serialize() for prod in results]

        return resultsUpd, status.HTTP_200_OK
Exemplo n.º 12
0
def write_product_xls(file_name, data):
    ''' Export data '''
    # Principe
    # write((nbre ligne - 1), nbre colonne, "contenu", style(optionnel).
    # write_merge((nbre ligne - 1), (nbre ligne - 1) + nbre de ligne
    # à merger, (nbre de colonne - 1), (nbre de colonne - 1) + nbre
    # de colonne à merger, u"contenu", style(optionnel)).
    book = xlwt.Workbook(encoding='ascii')
    sheet = book.add_sheet(u"Rapports")

    sheet.col(0).width = 0x0d00 * 2
    sheet.col(1).width = 0x0d00 * 4
    sheet.col(2).width = 0x0d00 * 2
    rowx = 0
    sheet.write_merge(rowx, rowx + 1, 0, 3,
                      u"Rapports de gestion de stock %s" % Config.NAME_ORGA, style_title)
    rowx += 3
    sheet.write_merge(rowx, rowx, 1, 2, u"Date du rapport: ", style)

    rowx += 1
    title = [u"Code", u"Article", u"Nombre de pièce", u""]
    for colx, val_center in enumerate(title):
        sheet.write(rowx, colx, val_center, style_t_table)
    rowx += 1
    for prod in Product.all():
        if int(rowx) % 2 == 0:
            style_row_table = style1
        else:
            style_row_table = style2
        sheet.write(rowx, 0, prod.code, style_row_table)
        sheet.write(rowx, 1, prod.name, style_row_table)
        sheet.write(rowx, 2, prod.number_parts_box, style_row_table)
        # sheet.write(rowx, 3, '[u"%s",u"%s"],' % (prod.code, prod.name))

        rowx += 1
    book.save(file_name)
    return file_name
Exemplo n.º 13
0
    def __init__(self, report, parent, *args, **kwargs):
        QtGui.QDialog.__init__(self, parent, *args, **kwargs)
        self.setWindowTitle(u"Modification")
        self.title = FPageTitle(u"Vous le vous modifié ?")

        self.op = report
        vbox = QtGui.QVBoxLayout()

        self.qty_use = QtGui.QLineEdit(str(self.op.qty_use))
        self.qty_use.setValidator(QtGui.QIntValidator())

        self.date_ = FormatDate(QtCore.QDate(self.op.date))

        self.time = QtGui.QDateTimeEdit(QtCore.QTime.currentTime())
        formbox = QtGui.QVBoxLayout()
        editbox = QtGui.QGridLayout()
        formbox.addWidget(FBoxTitle(u"Modification"))
        # Combobox widget

        i = 0
        self.liste_type = Reports.TYPES
        self.box_type = QtGui.QComboBox()
        for index in xrange(0, len(self.liste_type)):
            ty = self.liste_type[index]
            if ty == self.op.type_:
                i = index
            sentence = u"%(type_)s" % {'type_': ty}
            self.box_type.addItem(sentence, QtCore.QVariant(ty))
            self.box_prod.setCurrentIndex(i)
        # Combobox widget
        # self.liste_store = Store.order_by(desc(Store.id)).all()
        # self.box_mag = QtGui.QComboBox()
        # for index in xrange(0, len(self.liste_store)):
        #     op = self.liste_store[index]
        #     sentence = _(u"%(name)s") % {'name': op.name}
        #     self.box_mag.addItem(sentence, QtCore.QVariant(op.id))
        # Combobox widget

        self.liste_product = Product.all()
        self.box_prod = QtGui.QComboBox()

        for index in xrange(0, len(self.liste_product)):
            op = self.liste_product[index]
            if op == self.op.product.article:
                i = index
            sentence = u"%(article)s" % {'article': op.article}
            self.box_prod.addItem(sentence, QtCore.QVariant(op.id))
            self.box_prod.setCurrentIndex(i)

        editbox.addWidget(QtGui.QLabel(u"Type"), 0, 0)
        editbox.addWidget(self.box_type, 1, 0)
        # editbox.addWidget(QtGui.QLabel((_(u"Store"))), 0, 1)
        # editbox.addWidget(self.box_mag, 1, 1)
        editbox.addWidget(QtGui.QLabel(u"Produit"), 0, 2)
        editbox.addWidget(self.box_prod, 1, 2)
        editbox.addWidget(QtGui.QLabel(u"Quantité"), 0, 3)
        editbox.addWidget(self.qty_use, 1, 3)
        editbox.addWidget(QtGui.QLabel((u"Date")), 0, 4)
        editbox.addWidget(self.date_, 1, 4)
        butt = Button(u"Enregistrer")
        butt.clicked.connect(self.edit_report)
        cancel_but = Button(u"Annuler")
        cancel_but.clicked.connect(self.cancel)
        editbox.addWidget(butt, 2, 3)
        editbox.addWidget(cancel_but, 2, 4)
        formbox.addLayout(editbox)
        vbox.addLayout(formbox)
        self.setLayout(vbox)
Exemplo n.º 14
0
    def __init__(self, table_p, report, parent, *args, **kwargs):
        QDialog.__init__(self, parent, *args, **kwargs)

        self.setWindowTitle(u"Modification")
        self.table_p = table_p
        self.rpt = report
        self.parent = parent

        self.out_op = True
        if self.rpt.type_ == Report.E:
            self.out_op = False

        self.selling_price_field = IntLineEdit(unicode(self.rpt.selling_price))
        self.cost_buying_field = IntLineEdit(unicode(self.rpt.cost_buying))
        self.qty_field = IntLineEdit(unicode(self.rpt.qty))

        self.date_field = FormatDate(QDate(self.rpt.date))
        self.date_field.setEnabled(False)

        butt = Button(u"Mise à jour")
        butt.clicked.connect(self.edit_report)
        cancel_but = Button(u"Annuler")
        cancel_but.clicked.connect(self.cancel)

        # Combobox widget
        i = 0
        self.liste_type = [Report.E, Report.S]
        self.box_type = QComboBox()
        self.box_type.setEnabled(False)
        for index in xrange(0, len(self.liste_type)):
            ty = self.liste_type[index]
            if ty == self.rpt.type_:
                i = index
            sentence = u"%(ty)s" % {'ty': ty}
            self.box_type.addItem(sentence, ty)
            self.box_type.setCurrentIndex(i)
        # Combobox widget
        # self.liste_store = Store.order_by(desc(Store.id)).all()
        # self.box_mag = QComboBox()
        # for index in xrange(0, len(self.liste_store)):
        #     op = self.liste_store[index]
        #     sentence = u"%(name)s" % {'name': op.name}
        #     self.box_mag.addItem(sentence, QVariant(op.id))
        # Combobox widget

        self.liste_product = Product.all()
        self.box_prod_field = QComboBox()
        self.box_prod_field.setEnabled(False)

        for index in xrange(0, len(self.liste_product)):
            prod = self.liste_product[index]
            if prod.name == self.rpt.product.name:
                i = index
            sentence = u"%(name)s" % {'name': prod.name}
            self.box_prod_field.addItem(sentence, prod.id)
            self.box_prod_field.setCurrentIndex(i)
        vbox = QVBoxLayout()
        formbox = QFormLayout()
        # editbox.addWidget(FormLabel((_(u"Store"))), 0, 1)
        # editbox.addWidget(self.box_mag, 1, 1)
        formbox.addRow(FormLabel(u"Type"), FormLabel(self.rpt.type_))
        formbox.addRow(FormLabel(u"Désignation"), self.box_prod_field)
        formbox.addRow(FormLabel(u"Quantité"), self.qty_field)
        formbox.addRow(FormLabel("Prix d'achat"), self.cost_buying_field)
        formbox.addRow(FormLabel("Prix vente"), self.selling_price_field)
        formbox.addRow(FormLabel(u"Date"), self.date_field)
        formbox.addRow(butt, cancel_but)
        vbox.addLayout(formbox)
        self.setLayout(vbox)
Exemplo n.º 15
0
def index(request, *args):
    "Index page - show available products"
    return render_to_response('store/index.html', {
        'products': Product.all()
    }, RequestContext(request))
Exemplo n.º 16
0
 def set_data_for(self, *args):
     rest = self.restor_pew_order()
     self.data = [(2 if prod.name in rest.keys() else 0,
                   rest[prod.name] if prod.name in rest.keys() else "",
                   prod.name, prod.code) for prod in Product.all()]
Exemplo n.º 17
0
    def __init__(self, table_p, report, parent, *args, **kwargs):
        QDialog.__init__(self, parent, *args, **kwargs)

        self.setWindowTitle(u"Modification")
        self.table_p = table_p
        self.rpt = report
        self.parent = parent

        self.out_op = True
        if self.rpt.type_ == Report.E:
            self.out_op = False

        self.selling_price_field = IntLineEdit(unicode(self.rpt.selling_price))
        self.cost_buying_field = IntLineEdit(unicode(self.rpt.cost_buying))
        self.qty_field = IntLineEdit(unicode(self.rpt.qty))

        self.date_field = FormatDate(QDate(self.rpt.date))
        self.date_field.setEnabled(False)

        butt = Button(u"Mise à jour")
        butt.clicked.connect(self.edit_report)
        cancel_but = Button(u"Annuler")
        cancel_but.clicked.connect(self.cancel)

        # Combobox widget
        i = 0
        self.liste_type = [Report.E, Report.S]
        self.box_type = QComboBox()
        self.box_type.setEnabled(False)
        for index in xrange(0, len(self.liste_type)):
            ty = self.liste_type[index]
            if ty == self.rpt.type_:
                i = index
            sentence = u"%(ty)s" % {'ty': ty}
            self.box_type.addItem(sentence, ty)
            self.box_type.setCurrentIndex(i)
        # Combobox widget
        # self.liste_store = Store.order_by(desc(Store.id)).all()
        # self.box_mag = QComboBox()
        # for index in xrange(0, len(self.liste_store)):
        #     op = self.liste_store[index]
        #     sentence = u"%(name)s" % {'name': op.name}
        #     self.box_mag.addItem(sentence, QVariant(op.id))
        # Combobox widget

        self.liste_product = Product.all()
        self.box_prod_field = QComboBox()
        self.box_prod_field.setEnabled(False)

        for index in xrange(0, len(self.liste_product)):
            prod = self.liste_product[index]
            if prod.name == self.rpt.product.name:
                i = index
            sentence = u"%(name)s" % {'name': prod.name}
            self.box_prod_field.addItem(sentence, prod.id)
            self.box_prod_field.setCurrentIndex(i)
        vbox = QVBoxLayout()
        formbox = QFormLayout()
        # editbox.addWidget(FormLabel((_(u"Store"))), 0, 1)
        # editbox.addWidget(self.box_mag, 1, 1)
        formbox.addRow(FormLabel(u"Type"), FormLabel(self.rpt.type_))
        formbox.addRow(FormLabel(u"Désignation"), self.box_prod_field)
        formbox.addRow(FormLabel(u"Quantité"), self.qty_field)
        formbox.addRow(FormLabel("Prix d'achat"), self.cost_buying_field)
        formbox.addRow(FormLabel("Prix vente"), self.selling_price_field)
        formbox.addRow(FormLabel(u"Date"), self.date_field)
        formbox.addRow(butt, cancel_but)
        vbox.addLayout(formbox)
        self.setLayout(vbox)
Exemplo n.º 18
0
 def set_data_for(self, *args):
     rest = self.restor_pew_order()
     self.data = [(2 if prod.name in rest.keys() else 0,
                   rest[prod.name] if prod.name in rest.keys() else "",
                   prod.name, prod.code) for prod in Product.all()]