예제 #1
0
    def Remove(self):

        is_empty = True

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

        query = '''select * from "Kardex" where cellar_id = %(cellar_id)s'''

        parametros = {"cellar_id": self.id}

        cur.execute(query, parametros)

        kardex = cur.fetchall()

        for k in kardex:

            query = '''select * from "Kardex" where product_sku = %(product_sku)s and cellar_id = %(cellar_id)s and size_id = %(size_id)s order by date desc, id desc limit 1'''

            parametros = {
                "product_sku": k["product_sku"],
                "cellar_id": self.id,
                "size_id": k["size_id"]
            }

            cur.execute(query, parametros)

            _kardex = cur.fetchone()

            if _kardex:
                if int(_kardex["balance_units"]) >= 1:
                    is_empty = False

        if is_empty:

            query = '''update "User" set cellar_permissions = cellar_permissions - array[%(cellar_id)s]'''
            parametros = {"cellar_id": self.id}

            cur.execute(query, parametros)
            self.connection.commit()

            return BaseModel.Remove(self)

        else:
            return self.ShowError(
                "No se puede eliminar, aún contiene productos.")
예제 #2
0
파일: user.py 프로젝트: chachun88/gdf
 def Remove(self):
     try:
         return BaseModel.Remove(self)
     except Exception, e:
         return self.ShowError("error removing user, {}".format(str(e)))
예제 #3
0
from product import Product
from kardex import Kardex
from brand import Brand
from category import Category

####################################
########## basemodel.py ############
####################################

print "testing basemodel.py"

base_model = BaseModel()
base_model.identifier = ""

## remove empty
print "error : {}".format(base_model.Remove())

## adding item
print "adding: "
base_model.identifier = db.base_testing.save({"_id": "un_id"})
val_1 = db.base_testing.find().count()
message = base_model.Remove()
val_2 = db.base_testing.find().count()

status = "fail"

if val_1 == 1 and val_2 == 0:
    status = "ok"

print message
print "1: {} -- 2: {} -- status: {}".format(val_1, val_2, status)
예제 #4
0
    def Remove(self):
        # #validate if cellar still has products
        # data = self.db.kardex.find({ "cellar_identifier": self.identifier })
        # is_empty = True

        # for d in data:
        #   #detect if product exists
        #   product_data = self.db.kardex.find({"product_sku": d["product_sku"], "cellar_identifier": self.identifier}).sort("_id", -1).limit(1)

        #   for dat in product_data:

        #       if int(dat["balance_units"]) >=1:
        #           is_empty = False
        #   # if ( product_data.count() >= 1 ):
        #   #   ##validate
        #   #   is_empty = False
        # if (is_empty):

        #   ## remove permissions from user
        #   try:
        #       self.db.salesman.update({"permissions":self.name},{"$pull": { "permissions": self.name} }, multi=True);

        #   except Exception, e:
        #       self.ShowError(str( e ))

        #   return BaseModel.Remove(self)
        # else:
        #   return self.ShowError("No se puede eliminar, aún contiene productos.")

        is_empty = True

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

        query = '''select * from "Kardex" where cellar_id = %(cellar_id)s'''

        parametros = {"cellar_id": self.id}

        cur.execute(query, parametros)

        kardex = cur.fetchall()

        for k in kardex:

            query = '''select * from "Kardex" where product_sku = %(product_sku)s and cellar_id = %(cellar_id)s and size = %(size)s order by id desc limit 1'''

            parametros = {
                "product_sku": k["product_sku"],
                "cellar_id": self.id,
                "size": k["size"]
            }

            cur.execute(query, parametros)

            _kardex = cur.fetchone()

            if _kardex:
                if int(_kardex["balance_units"]) >= 1:
                    is_empty = False

        if is_empty:

            query = '''update "User" set cellar_permissions = cellar_permissions - array[%(cellar_id)s]'''
            parametros = {"cellar_id": self.id}

            cur.execute(query, parametros)
            self.connection.commit()

            return BaseModel.Remove(self)

        else:
            return self.ShowError(
                "No se puede eliminar, aún contiene productos.")