Exemple #1
0
def createProduct():
    body = request.get_json()
    product = Product(name=body.get('name'),
                      price=body.get('price'),
                      quantity=body.get('quantity'))
    db.session.add(product)
    db.session.commit()
    return {"success": True, 'data': product.toDict()}
Exemple #2
0
class CreateProductController():
    def __init__(self, create_product):
        self.product = Product(connection())
        self.create_product = create_product

    def createProduct(self, cod, name, price, category, CreateProduct):
        if cod and name and price and category:
            self.product.insertProduct(cod, name, price, category)
            CreateProduct.hide()
Exemple #3
0
    def start(self):
        self.fillCategoryCatalog(self.root.find(TAG_CATEGORY))
        print('Убедитесь что уже имеются категории следующей вложенности:')
        self.__categoryCatalog.show()
        ImageDownloader.createDirectory(self.__directory + IMAGES_DIRECTORY +
                                        IMAGE_PREFIX)

        product_list = self.root.find(TAG_PRODUCT)
        count_products = len(product_list)
        for index, product_item in enumerate(product_list, 1):
            product = Product(
                id=ProductFillingTools.getId(product_item),
                name=ProductFillingTools.getName(product_item),
                category=ProductFillingTools.getCategory(
                    product_item, self.categoryCatalog),
                price=ProductFillingTools.getPrice(product_item),
                image=ProductFillingTools.getImage(
                    product_item,
                    IMAGES_DIRECTORY,
                    IMAGE_PREFIX,
                    IMAGE_PREFIX_FOR_SERVER,
                    root_directory=self.__directory),
                manufacturer=ProductFillingTools.getManufacturer(product_item),
                description=ProductFillingTools.getDescription(product_item))
            self.__creatorXML.writeProduct(product)
            print(f'Загружено {index} товаров из {count_products}')
        self.__creatorXML.prettify()
        sys.exit(99)
 def post(self):
     try:
         data = request.get_json(force=True)
         order = Order(int(data["id_supplier"]),
                       int(data["id_client"]),
                       datetime.datetime.strptime(data["expected_delivery_date"], "%Y-%m-%d").date(),
                       str(data["payment_type"]),
                       str(data["l_dips"]),
                       str(data["appro_ship_sample"]),
                       str(data["appro_s_off"]),
                       str(data["ship_sample_2h"]))
         products = []
         total_amount = 0
         for p in data["products"]:
             product = Product(int(order.get_id_order()),
                               str(p["reference"]),
                               str(p["color"]),
                               float(p["meter"]),
                               float(p["price"]),
                               float(p["commission"]))
             products.append(product)
             self.product_db.add_product(product)
             total_amount += float(p["commission"]) * float(p["price"]) * float(p["meter"])
         order.set_total_amount(total_amount)
         self.order_db.add_order(order)
         return HttpResponse(HttpStatus.OK).get_response()
     except (ValueError, WritingDataBaseError, KeyError, werkzeug.exceptions.BadRequest) as e:
         return HttpResponse(HttpStatus.Bad_Request, message=str(e)).get_response()
def add_product():

    json = request.get_json()
    name = json['name']
    code = json['code']
    ean = json['ean']
    description = None
    if 'description' in json:
        description = json['description']
    price = json['price']
    producent_id = json['producentID']
    category_id = json['categoryID']
    vat_id = json['VatID']

    try:
        new_product = Product(name, code, ean, description, price, producent_id, category_id, vat_id)
        db.session.add(new_product)
        db.session.commit()
    except Exception as e:
        db.session.rollback()
        return jsonify(error=400, text=str(e.message))

    return jsonify(new_product.serialize()), 201
 def __init__(self, principal):
     self.product = Product(connection())
     self.principal = principal
class PrincipalController():

    def __init__(self, principal):
        self.product = Product(connection())
        self.principal = principal
    
    def listProducts(self):
        table = self.principal.table_product
        products = self.product.getProducts()
        table.setRowCount(0)
        for row_number, row_data in enumerate(products):
            table.insertRow(row_number)
            for column_number, data in enumerate(row_data):
                table.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data)))

    def showProduct(self):
        table = self.principal.table_product
        if table.currentItem() != None:
            cod = table.currentItem().text()
            print(cod)
            product = self.product.getProduct(cod)
            if product:
                print(product)
                msg = QMessageBox()
                msg.setWindowTitle(product[1])
                msg.setText(product[1])

                msg.setIcon(QMessageBox.Information)

                msg.setStandardButtons(QMessageBox.Ok)
                msg.setDefaultButton(QMessageBox.Ok)
                msg.setInformativeText('Codigo: '+product[0]+'\nNombre: '+product[1]+'\nPrecio: '+product[2]+'\nCategoria: '+product[3])

                x = msg.exec_()
    
    def updateProducs(self):
        table = self.principal.table_product
        products = []
        fila = []
        for row_number in range(table.rowCount()):
            for column_number in range(table.columnCount()):
                if table.item(row_number,column_number) != None:
                    fila.append(table.item(row_number,column_number).text())
            if len(fila)>0:
                products.append(fila)
            fila = []
        
        if len(products)>0:
            for prod in products:
                self.product.updateProduct(prod[0],prod[1],prod[2],prod[3])
        
        self.listProducts()
    
    def deleteProduct(self):
        table = self.principal.table_product
        if table.currentItem() != None:
            cod = table.currentItem().text()
            product = self.product.getProduct(cod)
            if product:
                self.product.deleteProduct(cod)
        self.listProducts()
    
    def openCreate(self, Ui_CreateProduct):
        self.principal.Form = QtWidgets.QWidget()
        self.principal.ui = Ui_CreateProduct()
        self.principal.ui.setupUi(self.principal.Form)
        self.principal.Form.show()
Exemple #8
0
 def __init__(self, create_product):
     self.product = Product(connection())
     self.create_product = create_product
 def setUpClass(self):
     self.shampoo = Product("Coconut Oil Shampoo", "7.99",
                            "silky smoothe hair treatment shampoo")
Exemple #10
0
    def get(self):
        if request.args.get("id_order"):
            id_order = request.args.get("id_order")
            order_db = self.order_db.get_order(id_order)
            if order_db is not None:
                total_amount = 0
                order = Order(int(order_db["supplier"]),
                              int(order_db["client"]),
                              str(order_db["expected_delivery_date"]),
                              str(order_db["payment_type"]),
                              str(order_db["l_dips"]),
                              str(order_db["appro_ship_sample"]),
                              str(order_db["appro_s_off"]),
                              str(order_db["ship_sample_2h"]),
                              total_amount=str(order_db["total_amount"]),
                              creation_date=(order_db["creation_date"]),
                              id_order=int(order_db["id_order"]))

                order_db["products"] = self.product_db.get_products(id_order)
                products = []
                for p in order_db["products"]:
                    product = Product(
                        int(id_order),
                        str(p["reference"]),
                        str(p["color"]),
                        float(p["meter"]),
                        float(p["price"]),
                        float(p["commission"]),
                        #id_shipment=int(p["id_shipment"]),
                        id_product=p["id_product"])
                    total_amount += float(p["commission"]) * float(
                        p["price"]) * float(p["meter"])
                    products.append(product)
                order.set_products(products)
                order.set_total_amount(
                    total_amount)  # NOTRE TOTAL AMOUNT EST DEJA DANS LA BDD
                client_db = self.partner_db.get_partner(int(
                    order_db["client"]))
                client = Partner(str(client_db["partner_type"]),
                                 str(client_db["company"]),
                                 id_partner=int(client_db["id_partner"]))
                supplier_db = self.partner_db.get_partner(
                    int(order_db["supplier"]))
                supplier = Partner(str(supplier_db["partner_type"]),
                                   str(supplier_db["company"]),
                                   id_partner=int(supplier_db["id_partner"]))
                # If we need shipment information
                #shipment_db = self.shipment_db.get_shipments_id_order(id_order)
                #shipment_obj = Shipment(shipment_db["expedition_date"],
                #                        shipment_db["transportation"],
                #                        shipment_db["departure_location"],
                #                        shipment_db["arrival_location"],
                #                        products=shipment_db["products"],
                #                        id_shipment=shipment_db["id_shipment"])
                filename = "Excel_order_" + str(id_order) + ".xlsx"
                uploads = os.path.join("public", "excels")
                excel = GenerateExcel()
                excel.generate_excel(order, client, supplier,
                                     uploads + "/" + filename,
                                     order.get_number_of_products())
                return send_from_directory(directory=uploads,
                                           filename=filename)

            else:
                raise NotImplementedError(
                    "error, please type a valid id_order")
Exemple #11
0
 def __init__(self):
     super().__init__()
     self.prodList = []
     self.prodList.append(
         Product('Lentejas', 2.80, 4, 351, 1.80, 54.0, 23.8))
     self.prodList.append(Product('Atun', 4.50, 4, 102, 2.40, 0.00, 18.9))
     self.prodList.append(
         Product('Tallarines', 2.20, 2, 301, 2.40, 57.3, 11.8))
     self.prodList.append(Product('Leche', 3.50, 4, 149, 7.90, 11.7, 7.70))
     self.prodList.append(Product('Arroz', 5.33, 3, 205, 0.40, 44.5, 4.30))
     self.prodList.append(Product('Avena', 2.00, 5, 607, 10.8, 103.4, 26.3))
     self.prodList.append(Product('Aceite', 7.50, 2, 120, 13.6, 0.00, 0.00))
     self.prodList.append(Product('Azucar', 3.50, 3, 16.0, 0.00, 4.10,
                                  0.08))
     self.prodList.append(
         Product('Frijoles', 7.00, 4, 44.0, 0.40, 9.90, 2.40))
     self.prodList.append(
         Product('Salsa roja', 2.30, 2, 176, 1.10, 35.8, 5.60))
     self.prodList.append(
         Product('Mantequilla', 7.50, 2, 102, 11.5, 0.10, 0.10))
     self.prodList.append(
         Product('Sobre de pure de papa', 3.80, 3, 237, 8.90, 35.3, 3.90))
     self.prodList.append(Product('Harina', 3.90, 4, 349, 2.26, 69.1, 10.4))
     self.prodList.append(
         Product('Aceitunas', 15.0, 2, 10.0, 0.90, 0.50, 0.08))
     self.prodList.append(Product('Yogurt', 6.20, 4, 149, 8.00, 11.4, 8.50))