Example #1
0
 def validate_python(self, value, state):
     p = Product.find_by_id(int(value))
     for product in Product.find_by_category(p.category.id):
         if product.id == int(value):
             check_product_availability(product, value, state)
             return # All good!
     raise Invalid("Product " + value + " is not allowed in category " + self.category.name, value, state)
Example #2
0
 def validate_python(self, value, state):
     p = Product.find_by_id(int(value))
     for product in Product.find_by_category(p.category.id):
         if product.id == int(value):
             check_product_availability(product, value, state)
             return # All good!
     raise Invalid("Product " + value + " is not allowed in category " + self.category.name, value, state)
Example #3
0
    def _new(self):
        results = self.form_result['invoice']
        del(results['item_count'])

        items = results['items']
        results['items'] = []
        c.invoice = Invoice(**results)

        for i in items:
            item = InvoiceItem()
            if i['description'] != "":
                item.description = i['description']
            else:
                product = Product.find_by_id(i['product'].id)
                category = product.category
                item.product = i['product']
                item.description = product.category.name + ' - ' + product.description
            item.cost = i['cost']
            item.qty = i['qty']
            c.invoice.items.append(item)

        c.invoice.manual = True
        c.invoice.void = None
        meta.Session.add(c.invoice)
        meta.Session.commit()

        h.flash("Manual invoice created")
        return redirect_to(action='view', id=c.invoice.id)
Example #4
0
    def _new(self):
        data = json.loads(request.params['invoice'])

        person_id = int(data['person_id'])
        due_date = datetime.datetime.strptime(data['due_date'], '%d/%m/%Y')

        invoice = Invoice(person_id=person_id,
                          due_date=due_date,
                          manual=True,
                          void=None)
        for item in data['items']:
            invoice_item = InvoiceItem()
            if item.has_key('product_id') and item['product_id']:
                product = Product.find_by_id(item['product_id'])
                category = product.category
                invoice_item.product = product
                invoice_item.description = product.category.name + ' - ' + product.description
            else:
                invoice_item.description = item['description']
            invoice_item.cost = int(item['cost'])
            invoice_item.qty = int(item['qty'])
            invoice.items.append(invoice_item)

        meta.Session.add(invoice)
        meta.Session.commit()

        return dict(r=dict(invoice_id=invoice.id))
Example #5
0
    def save_new_invoice(self):
        """
        """
        import json
        debug = ""
        data = request.params['invoice']
        data = json.loads(data)

        person_id = int(data['person_id'],10)
        due_date = datetime.datetime.strptime(data['due_date'], '%d/%m/%Y')

        invoice = Invoice(person_id=person_id, due_date=due_date, manual=True, void=None)
        for invoice_item in data['invoice_items']:
            item = InvoiceItem()

            if invoice_item.has_key('description') and invoice_item['description']:
                item.description = invoice_item['description']
            else:
                product = Product.find_by_id(invoice_item['product_id'])
                category = product.category
                item.product = product
                item.description = product.category.name + ' - ' + product.description

            item.cost = float(invoice_item['cost'])
            item.qty = int(invoice_item['qty'],10)
            invoice.items.append(item)

        meta.Session.add(invoice)
        meta.Session.commit()

        debug += str(invoice.id)
        return debug
Example #6
0
    def _new(self):
        results = self.form_result['invoice']
        del(results['item_count'])

        items = results['items']
        results['items'] = []
        c.invoice = Invoice(**results)

        for i in items:
            item = InvoiceItem()
            if i['description'] != "":
                item.description = i['description']
            else:
                product = Product.find_by_id(i['product'].id)
                category = product.category
                item.product = i['product']
                item.description = product.category.name + ' - ' + product.description
            item.cost = i['cost']
            item.qty = i['qty']
            c.invoice.items.append(item)

        c.invoice.manual = True
        c.invoice.void = None
        meta.Session.add(c.invoice)
        meta.Session.commit()

        h.flash("Manual invoice created")
        return redirect_to(action='view', id=c.invoice.id)
Example #7
0
    def _new(self):
        results = self.form_result['voucher']
        count = results['count']  # Number of voucher codes to generate
        del (results['count'])

        for i in xrange(count):
            if 'products' in results:
                del (results['products'])
            c.voucher = Voucher(**results)
            if c.voucher.code != '':
                c.voucher.code += '-'  #add a dash between prefix and random
            c.voucher.code += generate_code()
            meta.Session.add(c.voucher)  # save voucher to DB

            results['products'] = self.form_result['products']

            for category in c.product_categories:
                # depending on "display" type of product, handle the input appropriately
                if category.display == 'radio':
                    if 'category_' + str(category.id) in results[
                            'products'] and results['products'][
                                'category_' + str(category.id)] != None:
                        product = Product.find_by_id(
                            results['products']['category_' +
                                                str(category.id)])
                        vproduct = VoucherProduct()
                        vproduct.voucher = c.voucher
                        vproduct.product = product
                        vproduct.qty = 1
                        vproduct.percentage = results['products'][
                            'category_' + str(category.id) + '_percentage']
                        meta.Session.add(vproduct)  # Save product to DB
                        c.voucher.products.append(
                            vproduct
                        )  # Assign individual product discount to voucher
                else:
                    for product in category.products_nonfree:
                        if 'product_' + str(
                                product.id) + '_qty' in results['products']:
                            if results['products']['product_' +
                                                   str(product.id) +
                                                   '_qty'] not in (0, None):
                                vproduct = VoucherProduct()
                                vproduct.voucher = c.voucher
                                vproduct.product = product
                                vproduct.qty = results['products'][
                                    'product_' + str(product.id) + '_qty']
                                vproduct.percentage = results['products'][
                                    'product_' + str(product.id) +
                                    '_percentage']
                                meta.Session.add(vproduct)
                                c.voucher.products.append(vproduct)

        meta.Session.commit()  #save all updates
        h.flash("Voucher created")
        return redirect_to(controller='voucher', action='index')
Example #8
0
    def _new(self):
        results = self.form_result['voucher']
        count = results['count'] # Number of voucher codes to generate
        del(results['count'])

        for i in xrange(count):
            if 'products' in results:
                del(results['products'])
            c.voucher = Voucher(**results)
            if c.voucher.code !='':
                c.voucher.code += '-' #add a dash between prefix and random
            c.voucher.code += generate_code()
            meta.Session.add(c.voucher) # save voucher to DB

            results['products'] = self.form_result['products']

            for category in c.product_categories:
                if category.name in allowed_categories:
                    # depending on "display" type of product, handle the input appropriately
                    if category.display == 'radio':
                        if 'category_' + str(category.id) in results['products']:
                            product = Product.find_by_id(results['products']['category_' + str(category.id)])
                            vproduct = VoucherProduct()
                            vproduct.voucher = c.voucher
                            vproduct.product = product
                            vproduct.qty = 1
                            vproduct.percentage = results['products']['category_' + str(category.id) + '_percentage']
                            meta.Session.add(vproduct) # Save product to DB
                            c.voucher.products.append(vproduct) # Assign individual product discount to voucher
                    elif category.display == 'checkbox':
                        for product in category.products:
                            if 'product_' + str(product.id) in results['products']:
                                vproduct = VoucherProduct()
                                vproduct.voucher = c.voucher
                                vproduct.product = product
                                vproduct.qty = 1
                                vproduct.percentage = results['products']['product_' + str(product.id) + '_percentage']
                                meta.Session.add(vproduct)
                                c.voucher.products.append(vproduct)
                    else:
                        for product in category.products:
                            if 'product_' + str(product.id) + '_qty' in results['products']:
                                if results['products']['product_' + str(product.id) + '_qty'] not in (0, None):
                                    vproduct = VoucherProduct()
                                    vproduct.voucher = c.voucher
                                    vproduct.product = product
                                    vproduct.qty = results['products']['product_' + str(product.id) + '_qty']
                                    vproduct.percentage = results['products']['product_' + str(product.id) + '_percentage']
                                    meta.Session.add(vproduct)
                                    c.voucher.products.append(vproduct)

        meta.Session.commit() #save all updates
        h.flash("Voucher created")
        return redirect_to(controller='voucher', action='index')
Example #9
0
    def _new(self):
        results = self.form_result["voucher"]
        count = results["count"]  # Number of voucher codes to generate
        del (results["count"])

        for i in xrange(count):
            if "products" in results:
                del (results["products"])
            c.voucher = Voucher(**results)
            if c.voucher.code != "":
                c.voucher.code += "-"  # add a dash between prefix and random
            c.voucher.code += generate_code()
            meta.Session.add(c.voucher)  # save voucher to DB

            results["products"] = self.form_result["products"]

            for category in c.product_categories:
                # depending on "display" type of product, handle the input appropriately
                if category.display == "radio":
                    if (
                        "category_" + str(category.id) in results["products"]
                        and results["products"]["category_" + str(category.id)] != None
                    ):
                        product = Product.find_by_id(results["products"]["category_" + str(category.id)])
                        vproduct = VoucherProduct()
                        vproduct.voucher = c.voucher
                        vproduct.product = product
                        vproduct.qty = 1
                        vproduct.percentage = results["products"]["category_" + str(category.id) + "_percentage"]
                        meta.Session.add(vproduct)  # Save product to DB
                        c.voucher.products.append(vproduct)  # Assign individual product discount to voucher
                else:
                    for product in category.products_nonfree:
                        if "product_" + str(product.id) + "_qty" in results["products"]:
                            if results["products"]["product_" + str(product.id) + "_qty"] not in (0, None):
                                vproduct = VoucherProduct()
                                vproduct.voucher = c.voucher
                                vproduct.product = product
                                vproduct.qty = results["products"]["product_" + str(product.id) + "_qty"]
                                vproduct.percentage = results["products"]["product_" + str(product.id) + "_percentage"]
                                meta.Session.add(vproduct)
                                c.voucher.products.append(vproduct)

        meta.Session.commit()  # save all updates
        h.flash("Voucher created")
        return redirect_to(controller="voucher", action="index")
Example #10
0
    def _new(self):
        data = json.loads(request.params['invoice'])

        person_id = int(data['person_id'])
        due_date = datetime.datetime.strptime(data['due_date'], '%d/%m/%Y')

        invoice = Invoice(person_id=person_id, due_date=due_date, manual=True, void=None)
        for item in data['items']:
            invoice_item = InvoiceItem()
            if item.has_key('product_id') and item['product_id']:
                product = Product.find_by_id(item['product_id'])
                category = product.category
                invoice_item.product = product
                invoice_item.description = product.category.name + ' - ' + product.description
            else:
                invoice_item.description = item['description']
            invoice_item.cost = int(item['cost'])
            invoice_item.qty = int(item['qty'])
            invoice.items.append(invoice_item)

        meta.Session.add(invoice)
        meta.Session.commit()

        return dict(r=dict(invoice_id=invoice.id))
Example #11
0
    def _new(self):
        data = json.loads(request.params["invoice"])

        person_id = int(data["person_id"])
        due_date = datetime.datetime.strptime(data["due_date"], "%d/%m/%Y")

        invoice = Invoice(person_id=person_id, due_date=due_date, manual=True, void=None)
        for item in data["items"]:
            invoice_item = InvoiceItem()
            if item.has_key("product_id") and item["product_id"]:
                product = Product.find_by_id(item["product_id"])
                category = product.category
                invoice_item.product = product
                invoice_item.description = product.category.name + " - " + product.description
            else:
                invoice_item.description = item["description"]
            invoice_item.cost = int(item["cost"])
            invoice_item.qty = int(item["qty"])
            invoice.items.append(invoice_item)

        meta.Session.add(invoice)
        meta.Session.commit()

        return dict(r=dict(invoice_id=invoice.id))
Example #12
0
 def _to_python(self, value, state):
     return Product.find_by_id(value)
Example #13
0
 def _to_python(self, value, state):
     return Product.find_by_id(value)