예제 #1
0
파일: cellar.py 프로젝트: chachun88/bodegas
    def ListProducts(self, page, items):

        rtn_data = []

        cur = self.connection.cursor(cursor_factory=psycopg2.extras.DictCursor)

        query = '''select distinct product_sku, size_id from "Kardex" where cellar_id = %(id)s order by product_sku, size_id'''
        parametros = {"id": self.id}
        cur.execute(query, parametros)
        pproduct_sku = cur.fetchall()

        kardex = Kardex()

        for p in pproduct_sku:
            product = Product()
            # print "SKU:{}".format(p["product_sku"])
            response_obj = product.InitBySku(p["product_sku"])

            if "error" not in response_obj:

                prod_print = response_obj["success"]

                response_obj = kardex.FindKardex(p["product_sku"], self.id,
                                                 p["size_id"])

                if "success" in response_obj:

                    size = Size()
                    size.id = kardex.size_id

                    res_size_id = size.initById()

                    if "success" in res_size_id:

                        prod_print["balance_units"] = kardex.balance_units
                        prod_print["balance_price"] = kardex.balance_price
                        prod_print["balance_total"] = kardex.balance_total
                        prod_print["size_id"] = kardex.size_id
                        prod_print["size"] = size.name

                        rtn_data.append(prod_print)

                    # else:
                    #     return res_size_id

                else:
                    return response_obj

            else:
                return response_obj

        return {"success": rtn_data}
예제 #2
0
    def updatePrice(self, detail, user):

        counter = 0

        for item in detail:
            product = Product()
            res_product = product.InitBySku(item["sku"])

            if "success" in res_product:

                price = item["price"]
                subtotal = item["subtotal"]

                if product.promotion_price != 0:
                    subtotal = int(product.promotion_price) * item["quantity"]
                    price = product.promotion_price
                else:
                    subtotal = int(product.sell_price) * item["quantity"]
                    price = product.sell_price

                if user:
                    if user["type_id"] == 4:
                        subtotal = int(product.bulk_price) * item["quantity"]
                        price = product.bulk_price

                if item["price"] != price:
                    cart = Cart()
                    cart.InitById(item["id"])
                    cart.price = price
                    cart.quantity = item["quantity"]
                    cart.subtotal = subtotal
                    res_edit = cart.Edit()

                    if "success" in res_edit:
                        counter += 1

        return self.ShowSuccessMessage(counter)
예제 #3
0
    def AddProduct(self, sku, main_category, categories, color, season):
        response = None
        p = Product()
        p.InitBySku(sku)
        s = Size()
        is_first = True

        image_skus = []

        create_requests = []
        update_requests = []

        for si in p.size_id:
            s.id = si
            s.initById()
            size = s.name

            if is_first:
                is_first = False
                new_sku = sku
            else:
                new_sku = "{}-{}".format(sku, size)

            image_skus.append(new_sku)

            # @todo:validate product here
            product_data = {
                "Gender" : "Femenino",
                "ColorNameBrand" : p.color,
                "Color" : p.color,
                "ColorFamily" : color,
                "Season" : season,
                "SeasonYear" : date.today().year - 1
            }

            # response = dafiti.Response()
            stock = self.getStock(sku, s.id)

            product_name = "{} {} {} Giani Da Firenze".format(
                p.category, p.name, p.color
            )

            if not self.ProductExist(new_sku):

                create_requests.append(
                    dafiti.ProductRequest(
                        SellerSku=new_sku, Name=self.nameFix(product_name), Description=p.description, 
                        Brand="Giani Da Firenze", Price=p.sell_price,
                        PrimaryCategory=main_category, Categories=categories.split(","),
                        Variation=size, ProductData=product_data,
                        Quantity=stock, ParentSku=sku))

            else:

                update_requests.append(
                    dafiti.ProductRequest(
                        SellerSku=new_sku, Name=self.nameFix(product_name), Description=p.description, 
                        Brand="Giani Da Firenze", Price=p.sell_price,
                        PrimaryCategory=main_category, Categories=categories.split(","),
                        Variation=size, ProductData=product_data,
                        Quantity=stock, ParentSku=sku, Status=dafiti.Status.Active))

            # save las sync
            self.insertSync(new_sku, stock)

        if len(create_requests) > 0:
            response = self.client.product.sendPOST(dafiti.EndPoint.ProductCreate, create_requests)
        if len(update_requests) > 0:
            response = self.client.product.sendPOST(dafiti.EndPoint.ProductUpdate, update_requests)

        # preparing images for dafiti
        images = [p.image, p.image_2, p.image_3, p.image_4, p.image_5, p.image_6]
        final_images = []

        for img in images:
            if img != '':
                final_images.append(
                    "http://bodegas.gianidafirenze.cl/image/dafiti/{}?mwh=1380,1160".format(img.replace(" ", "%20"))
                )

        for x in range(0,3):
            aux = final_images.pop(0)
            final_images.append(aux)

        # adding images to dafiti
        self.client.product.Image(
            image_skus,
            *final_images)

        return response
예제 #4
0
product.name = "nuevo producto"
product.description = "a product description"
product.sku = "123"
product.brand = "a brand"
product.color = "red"
product.size = "10"
product.image = "an image"
product.manufacturer = "giani"
product.category = "zapatos"
product.brand = "giani"

print "product.py"
print "print : {}".format(product.Print())
print "save: {}".format(product.Save())
print "print : {}".format(product.Print())
print "init : {}".format(product.InitBySku("123"))
print "list : {}".format(product.GetList(0, 10))
#print "remove : {}".format(product.Remove())

print "\n\n"

####################################
########### kardex.py ##############
####################################

print "kardex"

kardex = Kardex()

## used sample https://www.youtube.com/watch?v=E03gTmKIEa0
예제 #5
0
    def ListProducts(self, page, items):
        # data = db.kardex.find({"cellar_identifier":self.identifier})

        # data = db.kardex.aggregate([
        #   {"$match":
        #       {"cellar_identifier":self.identifier}
        #   },{
        #       "$group":
        #           {"_id":{ "product_sku":"$product_sku"}}
        #   }])

        # rtn_data = []

        # kardex = Kardex()

        # for x in data["result"]:
        #   product = Product()
        #   product.InitBySku(str(x["_id"]["product_sku"]))
        #   #print "idddddddddd"+str(x["_id"]["product_sku"])
        #   prod_print = product.Print()
        #   #print "product print "+json_util.dumps(prod_print)

        #   if "error" not in prod_print:
        #       kardex.FindKardex(str(prod_print["sku"]), self.identifier)
        #       prod_print["balance_units"] = kardex.balance_units
        #       prod_print["balance_price"] = kardex.balance_price
        #       prod_print["balance_total"] = kardex.balance_total

        #       rtn_data.append(prod_print)

        # return rtn_data

        rtn_data = []

        cur = self.connection.cursor(cursor_factory=psycopg2.extras.DictCursor)

        query = '''select distinct product_sku, size from "Kardex" where cellar_id = %(id)s'''
        parametros = {"id": self.id}
        cur.execute(query, parametros)
        psku = cur.fetchall()

        kardex = Kardex()

        for p in psku:
            product = Product()
            # print "SKU:{}".format(p["product_sku"])
            response_obj = product.InitBySku(p["product_sku"])

            if "error" not in response_obj:

                prod_print = response_obj["success"]

                response_obj = kardex.FindKardex(p["sku"], self.id, p["size"])

                if "success" in response_obj:

                    prod_print["balance_units"] = kardex.balance_units
                    prod_print["balance_price"] = kardex.balance_price
                    prod_print["balance_total"] = kardex.balance_total
                    prod_print["size"] = kardex.size

                    rtn_data.append(prod_print)

                else:
                    print "error en findkardex"
                    return response_obj

            else:
                print response_obj["error"]
                # return response_obj

        return rtn_data