Example #1
0
 def get(self):
     db = get_connection()
     try:
         cart_id = int(self.get_argument("cart_id"))
         print("cart_id", cart_id)
         cart = get_model("ecom.cart").browse(cart_id)
         set_active_company(1)
         user_id = get_active_user()
         website = self.context["website"]
         ctx = self.context
         ctx["cart"] = cart
         if not cart.is_paid and website.payment_slip_template_id and (
                 cart.pay_method_id.id == website.bank_method_id.id):
             tmpl_name = website.payment_slip_template_id.name
             url = "/report?type=report_jasper&model=ecom.cart&convert=pdf&ids=[%d]&template=%s" % (
                 cart.id, tmpl_name)
             ctx["payment_slip_report_url"] = url
         content = render("ecom_order_confirmed", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #2
0
 def get(self):
     db=get_connection()
     try:
         ctx=self.context
         page_code=self.get_argument("page")
         res=get_model("cms.page").search([["code","=",page_code]])
         if not res:
             self.redirect("/cms_page_not_found")
             return
         page_id=res[0]
         page=get_model("cms.page").browse(page_id)
         if page.state=="inactive":
             self.redirect("/cms_page_not_found")
             return
         ctx["page"]=page
         tmpl_name=page.template or "cms_page"
         content=render(tmpl_name,ctx)
         ctx["content"]=content
         html=render("cms_layout",ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #3
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         edit_form_vals = {}
         for addr in ctx["customer"].addresses:
             edit_form_vals[addr.id] = {
                 "first_name": addr.first_name,
                 "last_name": addr.last_name,
                 "company": addr.company,
                 "address": addr.address,
                 "address2": addr.address2,
                 "province": addr.province,
                 "province_id": addr.province_id.id,
                 "district_id": addr.district_id.id,
                 "subdistrict_id": addr.subdistrict_id.id,
                 "postal_code": addr.postal_code,
                 "country": addr.country_id.name,
                 "phone": addr.phone,
             }
         ctx["edit_form_vals"] = edit_form_vals
         content = render("ecom_addresses", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #4
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         categ_id=self.get_argument("categ_id",None)
         if categ_id:
             categ_id = int(categ_id)
         else:
             categ_code=self.get_argument("categ_code",None)
             res=get_model("product.categ").search([["code","=",categ_code]])
             if not res:
                 raise Exception("Product categ not found: '%s'"%categ_code)
             categ_id=res[0]
         res = get_model("product.categ").browse([categ_id])
         if not res:
             raise Exception("Can't find product category id: ",categ_id)
         categ = res[0]
         ctx["product_categ"] = categ
         ctx["parent_categ_list"] = list_categ_parent(categ, categ_list=[])
         content = render("ecom_product_categ", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         self.redirect("/cms_page_not_found")
         import traceback
         traceback.print_exc()
         db.rollback()
Example #5
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         brand_id=self.get_argument("brand_id",None)
         if brand_id:
             brand_id = int(brand_id)
         else:
             brand_code=self.get_argument("brand_code",None)
             res=get_model("product.brand").search([["code","=",brand_code]])
             if not res:
                 raise Exception("Product brand not found: '%s'"%brand_code)
             brand_id=res[0]
         res = get_model("product.brand").browse([brand_id])
         if not res:
             raise Exception("Can't find product brand id: ",brand_id)
         brand = res[0]
         ctx["product_brand"] = brand
         ctx["parent_brand_list"] = list_brand_parent(brand, brand_list=[])
         content = render("ecom_product_brand", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         self.redirect("/cms_page_not_found")
         import traceback
         traceback.print_exc()
         db.rollback()
Example #6
0
 def post(self):
     db=get_connection()
     try:
         ctx=self.context
         coupon_id=int(self.get_argument("coupon_id"))
         action=self.get_argument("action")
         try:
             if action=="use_coupon":
                 coupon=get_model("sale.coupon").browse(coupon_id)
                 coupon.use_coupon()
                 db.commit()
                 self.redirect("/ecom_coupon?coupon_id=%s"%coupon.id)
         except Exception as e:
             ctx["error_message"]=str(e)
             coupon=get_model("sale.coupon").browse(coupon_id)
             ctx["coupon"]=coupon
             content=render("ecom_coupon",ctx)
             ctx["content"]=content
             html=render("cms_layout",ctx)
             self.write(html)
             db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #7
0
 def get(self):
     db = get_connection()
     try:
         user_id = self.get_cookie("user_id", None)
         if user_id:
             user_id = int(user_id)
             user = get_model("base.user").browse(user_id)
             ctx = self.context
             ctx["coupons_available"] = get_model(
                 "sale.coupon").search_browse(
                     [["contact_id", "=", user.contact_id.id],
                      ["state", "=", "available"]])
             ctx["coupons_in_use"] = get_model("sale.coupon").search_browse(
                 [["contact_id", "=", user.contact_id.id],
                  ["state", "=", "in_use"]])
             ctx["coupons_used"] = get_model("sale.coupon").search_browse(
                 [["contact_id", "=", user.contact_id.id],
                  ["state", "=", "used"]])
             ctx["coupons_expired"] = get_model(
                 "sale.coupon").search_browse(
                     [["contact_id", "=", user.contact_id.id],
                      ["state", "=", "expired"]])
             content = render("ecom_coupons", ctx)
             ctx["content"] = content
             html = render("cms_layout", ctx)
             self.write(html)
         else:
             self.redirect("cms_login")
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #8
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         seller_id = int(self.get_argument("seller_id"))
         comp = get_model("company").browse(seller_id)
         #products=get_model("product").search_browse([["company_id","=",seller_id]])
         res = get_model("product.group").search_browse([["code","=","seller_new"],["company_id","=",seller_id]])
         if not res:
             raise Exception("No product group code 'seller_new' in company: ",comp.name)
         new_product_group = res[0]
         res = get_model("product.group").search_browse([["code","=","seller_rec"],["company_id","=",seller_id]])
         if not res:
             raise Exception("No product group code 'seller_new' in company: ",comp.name)
         rec_product_group = res[0]
         ctx["seller"]={
             "name": comp.name,
             "new_product_group": new_product_group,
             "rec_product_group": rec_product_group,
         }
         content = render("ecom_seller", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         self.redirect("/cms_page_not_found")
         import traceback
         traceback.print_exc()
         db.rollback()
 def get(self):
     db = get_connection()
     try:
         cart_id = int(self.get_argument("cart_id"))
         print("cart_id", cart_id)
         cart = get_model("ecom.cart").browse(cart_id)
         set_active_company(1)
         user_id = get_active_user()
         website = self.context["website"]
         ctx = self.context
         ctx["cart"] = cart
         if not cart.is_paid and website.payment_slip_template_id and (cart.pay_method_id.id == website.bank_method_id.id):
             tmpl_name = website.payment_slip_template_id.name
             url = "/report?type=report_jasper&model=ecom.cart&convert=pdf&ids=[%d]&template=%s" % (
                 cart.id, tmpl_name)
             ctx["payment_slip_report_url"] = url
         content = render("ecom_order_confirmed", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #10
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         edit_form_vals = {}
         for addr in ctx["customer"].addresses:
             edit_form_vals[addr.id] = {
                 "first_name": addr.first_name,
                 "last_name": addr.last_name,
                 "company": addr.company,
                 "address": addr.address,
                 "address2": addr.address2,
                 "province": addr.province,
                 "province_id": addr.province_id.id,
                 "district_id": addr.district_id.id,
                 "subdistrict_id": addr.subdistrict_id.id,
                 "postal_code": addr.postal_code,
                 "country": addr.country_id.name,
                 "phone": addr.phone,
             }
         ctx["edit_form_vals"] = edit_form_vals
         content = render("ecom_addresses", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #11
0
    def get(self):
        db = get_connection()
        try:
            ctx = self.context
            brand_id = self.get_argument("brand_id", None)
            if brand_id:
                brand_id = int(brand_id)
            else:
                brand_code = self.get_argument("brand_code", None)
                res = get_model("product.brand").search([["code", "=", brand_code]])
                if not res:
                    raise Exception("Product brand not found: '%s'" % brand_code)
                brand_id = res[0]
            res = get_model("product.brand").browse([brand_id])
            if not res:
                raise Exception("Can't find product brand id: ", brand_id)
            brand = res[0]
            ctx["product_brand"] = brand
            ctx["parent_brand_list"] = list_brand_parent(brand, brand_list=[])
            content = render("ecom_product_brand", ctx)
            ctx["content"] = content
            html = render("cms_layout", ctx)
            self.write(html)
            db.commit()
        except:
            self.redirect("/cms_page_not_found")
            import traceback

            traceback.print_exc()
            db.rollback()
Example #12
0
    def get(self):
        db = get_connection()
        try:
            ctx = self.context
            page_code = self.get_argument("page")
            res = get_model("cms.page").search([["code", "=", page_code]])
            if not res:
                self.redirect("/cms_page_not_found")
                return
            page_id = res[0]
            page = get_model("cms.page").browse(page_id)
            if page.state == "inactive":
                self.redirect("/cms_page_not_found")
                return
            ctx["page"] = page
            tmpl_name = page.template or "cms_page"
            content = render(tmpl_name, ctx)
            ctx["content"] = content
            html = render("cms_layout", ctx)
            self.write(html)
            db.commit()
        except:
            import traceback

            traceback.print_exc()
            db.rollback()
Example #13
0
 def post(self):
     db = get_connection()
     try:
         try:
             fields = ["old_password", "new_password", "re_password"]
             field_errors = {}
             form_vals = {}
             for n in fields:
                 v = self.get_argument(n, None)
                 form_vals[n] = v
                 if not v:
                     field_errors[n] = True
             if field_errors:
                 raise Exception("Some required fields are missing")
             user_id = get_active_user()
             if not user_id:
                 raise Exception("No user")
             user = get_model("base.user").browse(user_id)
             user_id = get_model("base.user").check_password(
                 user.email, form_vals["old_password"])
             if not user_id:
                 raise Exception("Wrong password")
             if len(form_vals["new_password"]) < 6:
                 raise Exception(
                     "New password must be more than 6 character")
             if form_vals["new_password"] != form_vals["re_password"]:
                 raise Exception(
                     "New password does not match confirmed password")
             get_model("base.user").write(
                 [user_id], {"password": form_vals["new_password"]})
             get_model("base.user").trigger(
                 [user_id],
                 "change_password",
                 context={"new_password": form_vals["new_password"]})
             self.redirect(
                 "/cms_account?message=Your%20password%20has%20been%20changed"
             )
             db.commit()
         except Exception as e:
             db = get_connection()
             error_message = str(e)
             ctx = self.context
             ctx["form_vals"] = form_vals
             ctx["error_message"] = error_message
             ctx["field_errors"] = field_errors
             content = render("cms_change_pass", ctx)
             ctx["content"] = content
             html = render("cms_layout", ctx)
             self.write(html)
             db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #14
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         cart = ctx.get("cart")
         if not cart:
             db.commit()
             self.redirect("/cms_index")
             return
         fnames = [
             "email",
             "bill_first_name",
             "bill_last_name",
             "bill_company",
             "bill_address",
             "bill_address2",
             "bill_city",
             "bill_postal_code",
             "bill_country_id",
             "bill_province_id",
             "bill_district_id",
             "bill_subdistrict_id",
             "bill_phone",
             "ship_to_bill",
             "ship_first_name",
             "ship_last_name",
             "ship_company",
             "ship_address",
             "ship_address2",
             "ship_city",
             "ship_postal_code",
             "ship_country_id",
             "ship_province_id",
             "ship_district_id",
             "ship_subdistrict_id",
             "ship_phone",
         ]
         form_vals = {}
         for n in fnames:
             v = cart[n]
             f = get_model("ecom.cart")._fields[n]
             if v and isinstance(f, fields.Many2One):
                 v = v.id
             form_vals[n] = v
         ctx["form_vals"] = form_vals
         content = render("ecom_checkout", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #15
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         cart = ctx.get("cart")
         if not cart:
             db.commit()
             self.redirect("/cms_index")
             return
         fnames = [
             "email",
             "bill_first_name",
             "bill_last_name",
             "bill_company",
             "bill_address",
             "bill_address2",
             "bill_city",
             "bill_postal_code",
             "bill_country_id",
             "bill_province_id",
             "bill_district_id",
             "bill_subdistrict_id",
             "bill_phone",
             "ship_to_bill",
             "ship_first_name",
             "ship_last_name",
             "ship_company",
             "ship_address",
             "ship_address2",
             "ship_city",
             "ship_postal_code",
             "ship_country_id",
             "ship_province_id",
             "ship_district_id",
             "ship_subdistrict_id",
             "ship_phone",
         ]
         form_vals = {}
         for n in fnames:
             v = cart[n]
             f = get_model("ecom.cart")._fields[n]
             if v and isinstance(f, fields.Many2One):
                 v = v.id
             form_vals[n] = v
         ctx["form_vals"] = form_vals
         content = render("ecom_checkout", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #16
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         content = render("ecom_cart", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #17
0
 def get(self):
     db=get_connection()
     try:
         ctx=self.context
         content=render("cms_page_not_found",ctx)
         ctx["content"]=content
         html=render("cms_layout",ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #18
0
 def post(self):
     db = get_connection()
     try:
         try:
             print("CHECK protocol XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
             print(self.request.protocol)
             print("CHECK protocol XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
             fields = ["email", "password"]
             field_errors = {}
             form_vals = {}
             for n in fields:
                 v = self.get_argument(n, None)
                 form_vals[n] = v
                 if not v:
                     field_errors[n] = True
             if field_errors:
                 raise Exception("Some required fields are missing")
             user_id = get_model("base.user").check_password(
                 form_vals["email"], form_vals["password"])
             if not user_id:
                 raise Exception("Invalid login")
             set_active_user(user_id)
             dbname = get_active_db()
             token = new_token(dbname, user_id)
             self.set_cookie("user_id", str(user_id))
             self.set_cookie("token", token)
             cart_id = self.get_cookie("cart_id")
             if cart_id:
                 cart_id = int(cart_id)
                 get_model("ecom.cart").set_default_address([cart_id])
             db.commit()
             url = self.get_argument("return_url", None)
             if not url:
                 url = "/cms_account"
             self.redirect(url)
         except Exception as e:
             db = get_connection()
             error_message = str(e)
             ctx = self.context
             ctx["form_vals"] = form_vals
             ctx["error_message"] = error_message
             ctx["field_errors"] = field_errors
             content = render("cms_login", ctx)
             ctx["content"] = content
             html = render("cms_layout", ctx)
             self.write(html)
             db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #19
0
 def post(self):
     db=get_connection()
     try:
         try:
             print("CHECK protocol XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
             print(self.request.protocol)
             print("CHECK protocol XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
             fields=["email","password"]
             field_errors={}
             form_vals={}
             for n in fields:
                 v=self.get_argument(n,None)
                 form_vals[n]=v
                 if not v:
                     field_errors[n]=True
             if field_errors:
                 raise Exception("Some required fields are missing")
             user_id=get_model("base.user").check_password(form_vals["email"],form_vals["password"])
             if not user_id:
                 raise Exception("Invalid login")
             set_active_user(user_id)
             dbname=get_active_db()
             token=new_token(dbname,user_id)
             self.set_cookie("user_id",str(user_id))
             self.set_cookie("token",token)
             cart_id=self.get_cookie("cart_id")
             if cart_id:
                 cart_id=int(cart_id)
                 get_model("ecom.cart").set_default_address([cart_id])
             db.commit()
             url=self.get_argument("return_url",None)
             if not url:
                 url="/cms_account"
             self.redirect(url)
         except Exception as e:
             db=get_connection()
             error_message=str(e)
             ctx=self.context
             ctx["form_vals"]=form_vals
             ctx["error_message"]=error_message
             ctx["field_errors"]=field_errors
             content=render("cms_login",ctx)
             ctx["content"]=content
             html=render("cms_layout",ctx)
             self.write(html)
             db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #20
0
    def get(self):
        db = get_connection()
        try:
            ctx = self.context
            group_id = self.get_argument("group_id", None)
            website = ctx["website"]
            browse_ctx = {
                "pricelist_id":
                website.sale_channel_id.pricelist_id.id
                if website.sale_channel_id else None,
            }

            user_id = self.get_cookie("user_id", None)
            if user_id:
                user_id = int(user_id)
                user = get_model("base.user").browse(user_id)
                contact = user.contact_id
                pricelist_ids = [website.sale_channel_id.pricelist_id.id]
                if contact.groups:
                    for group in contact.groups:
                        if group.sale_price_list_id:
                            pricelist_ids.append(group.sale_price_list_id.id)
                browse_ctx["pricelist_ids"] = pricelist_ids

            if group_id:
                group_id = int(group_id)
            else:
                group_code = self.get_argument("group_code", None)
                res = get_model("product.group").search(
                    [["code", "=", group_code]])
                if not res:
                    raise Exception("Product group not found: '%s'" %
                                    group_code)
                group_id = res[0]
            res = get_model("product.group").browse([group_id], browse_ctx)
            if not res:
                raise Exception("Can't find product group id: ", group_id)
            group = res[0]
            ctx["product_group"] = group
            content = render("ecom_product_group", ctx)
            ctx["content"] = content
            html = render("cms_layout", ctx)
            self.write(html)
            db.commit()
        except:
            self.redirect("/cms_page_not_found")
            import traceback
            traceback.print_exc()
            db.rollback()
Example #21
0
 def get(self):
     db=get_connection()
     try:
         ctx=self.context
         ctx["return_url"]=self.get_argument("return_url",None)
         ctx["message"]=self.get_argument("message",None)
         content=render("cms_login",ctx)
         ctx["content"]=content
         html=render("cms_layout",ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #22
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         ctx["return_url"] = self.get_argument("return_url", None)
         ctx["message"] = self.get_argument("message", None)
         content = render("cms_login", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #23
0
    def post(self):
        db = get_connection()
        try:
            key = self.get_argument("key", None)
            if not key:
                raise Exception("Invalid key")
            new_password = self.get_argument("new_password", None)
            re_password = self.get_argument("re_password", None)
            if len(new_password) < 6:
                raise Exception("New password must be more than 6 character")
            if new_password != re_password:
                raise Exception(
                    "New password does not match confirmed password")
            res = get_model("cms.forgot.passwd").search([["key", "=", key]])
            if not res:
                raise Exception("Can not find email that match the key")
            forgot_obj = get_model("cms.forgot.passwd").browse(res[0])
            res = get_model("base.user").search(
                [["login", "=", forgot_obj.email]])
            if not res:
                raise Exception("Can not find user")
            user = get_model("base.user").browse(res[0])
            user.write({"password": new_password})
            user.trigger("change_password",
                         context={"new_password": new_password})

            for obj in get_model("cms.forgot.passwd").search_browse(
                [["email", "=", forgot_obj.email]]):
                obj.delete()
            db.commit()

            self.redirect(
                "cms_login?message=Your%20password%20has%20been%20reset")
        except Exception as e:
            try:
                ctx = self.context
                ctx["error"] = True
                ctx["message"] = str(e)
                ctx["key"] = key
                content = render("cms_reset_passwd", ctx)
                ctx["content"] = content
                html = render("cms_layout", ctx)
                self.write(html)
                db.commit()
            except:
                import traceback
                traceback.print_exc()
                db.rollback()
Example #24
0
 def post(self):
     db = database.get_connection()
     data = {}
     try:
         data["barcode"] = self.get_argument("barcode", None)
         data["qty"] = self.get_argument("qty", None)
         barcode = data["barcode"]
         if not barcode:
             raise Exception("Missing barcode!")
         barcode = int(barcode)
         qty = data["qty"]
         if not qty:
             raise Exception("Missing qty!")
         qty = int(qty)
         res = get_model("production.component").search(
             [["id", "=", barcode]])
         if not res:
             raise Exception("Invalid barcode")
         comp_id = res[0]
         # TODO: create goods issue for that component
         db.commit()
         self.redirect("/issue_rm")
     except Exception as e:
         data["error"] = "ERROR: %s" % e
         html = template.render("issue_rm", data)
         self.write(html)
         db.rollback()
         import traceback
         traceback.print_exc()
Example #25
0
 def get(self):
     db = get_connection()
     try:
         user_id = self.get_cookie("user_id", None)
         if not user_id:
             self.redirect("/cms_login")
         ctx = self.context
         content = render("ecom_wishlist", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #26
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         ctx["brands"] = get_model("product.brand").search_browse([])
         ctx["brand_groups"] = get_model("product.brand.group").search_browse([])
         content = render("ecom_brands", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         self.redirect("/cms_page_not_found")
         import traceback
         traceback.print_exc()
         db.rollback()
Example #27
0
    def post(self):
        db = database.get_connection()
        data = {}
        try:
            data["barcode"] = self.get_argument("barcode", None)
            data["qty"] = self.get_argument("qty", None)
            barcode = data["barcode"]
            if not barcode:
                raise Exception("Missing barcode!")
            barcode = int(barcode)
            qty = data["qty"]
            if not qty:
                raise Exception("Missing qty!")
            qty = int(qty)
            res = get_model("production.component").search([["id", "=", barcode]])
            if not res:
                raise Exception("Invalid barcode")
            comp_id = res[0]
            # TODO: create goods issue for that component
            db.commit()
            self.redirect("/issue_rm")
        except Exception as e:
            data["error"] = "ERROR: %s" % e
            html = template.render("issue_rm", data)
            self.write(html)
            db.rollback()
            import traceback

            traceback.print_exc()
Example #28
0
 def get(self):
     db=get_connection()
     try:
         user_id=self.get_cookie("user_id",None)
         if not user_id:
             self.redirect("/cms_login")
         ctx=self.context
         content=render("cms_change_pass",ctx)
         ctx["content"]=content
         html=render("cms_layout",ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #29
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         ctx["brands"] = get_model("product.brand").search_browse([])
         ctx["brand_groups"] = get_model(
             "product.brand.group").search_browse([])
         content = render("ecom_brands", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         self.redirect("/cms_page_not_found")
         import traceback
         traceback.print_exc()
         db.rollback()
Example #30
0
 def post(self):
     db=get_connection()
     try:
         try:
             fields=["old_password","new_password","re_password"]
             field_errors={}
             form_vals={}
             for n in fields:
                 v=self.get_argument(n,None)
                 form_vals[n]=v
                 if not v:
                     field_errors[n]=True
             if field_errors:
                 raise Exception("Some required fields are missing")
             user_id=get_active_user()
             if not user_id:
                 raise Exception("No user")
             user=get_model("base.user").browse(user_id)
             user_id=get_model("base.user").check_password(user.email,form_vals["old_password"])
             if not user_id:
                 raise Exception("Wrong password") 
             if len(form_vals["new_password"])<6:
                 raise Exception("New password must be more than 6 character")
             if form_vals["new_password"]!=form_vals["re_password"]:
                 raise Exception("New password does not match confirmed password")
             get_model("base.user").write([user_id],{"password":form_vals["new_password"]})
             get_model("base.user").trigger([user_id],"change_password",context={"new_password": form_vals["new_password"]})
             self.redirect("/cms_account?message=Your%20password%20has%20been%20changed")
             db.commit()
         except Exception as e:
             db=get_connection()
             error_message=str(e)
             ctx=self.context
             ctx["form_vals"]=form_vals
             ctx["error_message"]=error_message
             ctx["field_errors"]=field_errors
             content=render("cms_change_pass",ctx)
             ctx["content"]=content
             html=render("cms_layout",ctx)
             self.write(html)
             db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #31
0
    def get(self):
        db = get_connection()
        try:
            ctx = self.context
            group_id=self.get_argument("group_id",None)
            website=ctx["website"]
            browse_ctx={
                "pricelist_id": website.sale_channel_id.pricelist_id.id if website.sale_channel_id else None,
            }

            user_id=self.get_cookie("user_id",None)
            if user_id:
                user_id=int(user_id)
                user=get_model("base.user").browse(user_id)
                contact = user.contact_id
                pricelist_ids=[website.sale_channel_id.pricelist_id.id]
                if contact.groups:
                    for group in contact.groups:
                        if group.sale_price_list_id:
                            pricelist_ids.append(group.sale_price_list_id.id)
                browse_ctx["pricelist_ids"]=pricelist_ids

            if group_id:
                group_id = int(group_id)
            else:
                group_code=self.get_argument("group_code",None)
                res=get_model("product.group").search([["code","=",group_code]])
                if not res:
                    raise Exception("Product group not found: '%s'"%group_code)
                group_id=res[0]
            res = get_model("product.group").browse([group_id], browse_ctx)
            if not res:
                raise Exception("Can't find product group id: ",group_id)
            group = res[0]
            ctx["product_group"] = group
            content = render("ecom_product_group", ctx)
            ctx["content"] = content
            html = render("cms_layout", ctx)
            self.write(html)
            db.commit()
        except:
            self.redirect("/cms_page_not_found")
            import traceback
            traceback.print_exc()
            db.rollback()
Example #32
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         q = self.get_argument("q", "")
         minprice = self.get_argument("minprice", "")
         maxprice = self.get_argument("maxprice", "")
         website = ctx["website"]
         browse_ctx = {
             "pricelist_id":
             website.sale_channel_id.pricelist_id.id
             if website.sale_channel_id else None,
         }
         condition = [["state", "=", "approved"]]
         if minprice: condition.append(["sale_price", ">=", minprice])
         if maxprice: condition.append(["sale_price", "<=", maxprice])
         for word in q.split():
             condition.append([
                 "or", ["name", "ilike", word],
                 ["description", "ilike", word]
             ])
         results = []
         if condition:
             condition.append(["parent_id", "=", None])  #Filter out variant
             results = get_model("product").search_browse(
                 condition=condition, context=browse_ctx)
         for result in results:
             print("RES:", result.sale_price, result.name)
         ctx["search"] = {
             "query": q,
             "minprice": minprice,
             "maxprice": maxprice,
             "results": results,
         }
         content = render("ecom_search", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #33
0
    def post(self):
        db=get_connection()
        try:
            key=self.get_argument("key",None)
            if not key:
                raise Exception("Invalid key")
            new_password = self.get_argument("new_password",None)
            re_password = self.get_argument("re_password",None)
            if len(new_password)<6:
                raise Exception("New password must be more than 6 character")
            if new_password != re_password:
                raise Exception("New password does not match confirmed password")
            res = get_model("cms.forgot.passwd").search([["key","=",key]])
            if not res:
                raise Exception("Can not find email that match the key")
            forgot_obj = get_model("cms.forgot.passwd").browse(res[0])
            res = get_model("base.user").search([["login","=",forgot_obj.email]])
            if not res:
                raise Exception("Can not find user")
            user = get_model("base.user").browse(res[0])
            user.write({"password": new_password})
            user.trigger("change_password", context={"new_password": new_password})

            for obj in get_model("cms.forgot.passwd").search_browse([["email","=",forgot_obj.email]]):
                obj.delete()
            db.commit()

            self.redirect("cms_login?message=Your%20password%20has%20been%20reset")
        except Exception as e:
            try:
                ctx=self.context
                ctx["error"]=True
                ctx["message"]=str(e)
                ctx["key"] = key
                content=render("cms_reset_passwd",ctx)
                ctx["content"]=content
                html=render("cms_layout",ctx)
                self.write(html)
                db.commit()
            except:
                import traceback
                traceback.print_exc()
                db.rollback()
Example #34
0
 def get(self):
     db=get_connection()
     try:
         ctx=self.context
         blog_code=self.get_argument("blog")
         res=get_model("cms.blog").search([["code","=",blog_code]])
         if not res:
             self.redirect("/cms_page_not_found")
             return
         blog_id=res[0]
         ctx["blog"]=get_model("cms.blog").browse([blog_id])[0]
         content=render("cms_blog",ctx)
         ctx["content"]=content
         html=render("cms_layout",ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #35
0
 def get(self):
     db = database.get_connection()
     try:
         data = {}
         html = template.render("issue_rm", data)
         self.write(html)
         db.commit()
     except Exception as e:
         db.rollback()
         import traceback
         traceback.print_exc()
Example #36
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         key = self.get_argument("key", None)
         if not key:
             raise Exception("Invaid Key")
         if not get_model("cms.forgot.passwd").search([["key", "=", key]]):
             raise Exception("Invalid Key")
         ctx["key"] = key
         content = render("cms_reset_passwd", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         self.redirect("cms_page_not_found")
         import traceback
         traceback.print_exc()
         db.rollback()
Example #37
0
 def get(self):
     db=get_connection()
     try:
         ctx=self.context
         key=self.get_argument("key",None)
         if not key:
             raise Exception("Invaid Key")
         if not get_model("cms.forgot.passwd").search([["key","=",key]]):
             raise Exception("Invalid Key")
         ctx["key"] = key
         content=render("cms_reset_passwd",ctx)
         ctx["content"]=content
         html=render("cms_layout",ctx)
         self.write(html)
         db.commit()
     except:
         self.redirect("cms_page_not_found")
         import traceback
         traceback.print_exc()
         db.rollback()
Example #38
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         blog_code = self.get_argument("blog")
         res = get_model("cms.blog").search([["code", "=", blog_code]])
         if not res:
             self.redirect("/cms_page_not_found")
             return
         blog_id = res[0]
         ctx["blog"] = get_model("cms.blog").browse([blog_id])[0]
         content = render("cms_blog", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #39
0
 def get(self):
     db=get_connection()
     try:
         user_id=self.get_cookie("user_id",None)
         if not user_id:
             self.redirect("/cms_login")
         user_id = int(user_id)
         ctx=self.context
         ctx["message"] = self.get_argument("message",None)
         user = get_model("base.user").browse(user_id)
         ctx["coupons_can_print"] = get_model("sale.coupon").search_browse([["contact_id","=",user.contact_id.id],["state","in",("available","in_use")]])
         ctx["customer_carts"] = get_model("ecom.cart").search_browse([["contact_id","=",user.contact_id.id],["state","in",("confirmed","done","canceled")]])
         content=render("ecom_account",ctx)
         ctx["content"]=content
         html=render("cms_layout",ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #40
0
    def get(self):
        db = database.get_connection()
        try:
            data = {}
            html = template.render("issue_rm", data)
            self.write(html)
            db.commit()
        except Exception as e:
            db.rollback()
            import traceback

            traceback.print_exc()
Example #41
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         cart = ctx.get("cart")
         if not cart:
             db.commit()
             self.redirect("/cms_index")
             return
         if not cart.email or not cart.bill_first_name or not cart.bill_phone:  # XXX
             self.redirect("/cms_index")
             return
         ctx["ship_methods"] = cart.get_ship_methods()
         content = render("ecom_checkout2", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #42
0
 def get(self):
     db=get_connection()
     try:
         user_id=self.get_cookie("user_id",None)
         if user_id:
             user_id = int(user_id)
             user = get_model("base.user").browse(user_id)
             ctx=self.context
             ctx["coupons_available"] = get_model("sale.coupon").search_browse([["contact_id","=",user.contact_id.id],["state","=","available"]])
             ctx["coupons_in_use"] = get_model("sale.coupon").search_browse([["contact_id","=",user.contact_id.id],["state","=","in_use"]])
             ctx["coupons_used"] = get_model("sale.coupon").search_browse([["contact_id","=",user.contact_id.id],["state","=","used"]])
             ctx["coupons_expired"] = get_model("sale.coupon").search_browse([["contact_id","=",user.contact_id.id],["state","=","expired"]])
             content=render("ecom_coupons",ctx)
             ctx["content"]=content
             html=render("cms_layout",ctx)
             self.write(html)
         else:
             self.redirect("cms_login")
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #43
0
 def get(self):
     db=get_connection()
     try:
         ctx=self.context
         q = self.get_argument("q","")
         minprice = self.get_argument("minprice","")
         maxprice = self.get_argument("maxprice","")
         website=ctx["website"]
         browse_ctx = {
             "pricelist_id": website.sale_channel_id.pricelist_id.id if website.sale_channel_id else None,
         }
         condition = [["state","=","approved"]]
         if minprice: condition.append(["sale_price", ">=", minprice])
         if maxprice: condition.append(["sale_price", "<=", maxprice])
         for word in q.split():
             condition.append(["or",["name","ilike",word],["description","ilike",word]])
         results=[]
         if condition:
             condition.append(["parent_id","=",None]) #Filter out variant
             results=get_model("product").search_browse(condition=condition, context=browse_ctx)
         for result in results:
             print("RES:", result.sale_price, result.name)
         ctx["search"]={
             "query": q,
             "minprice": minprice,
             "maxprice": maxprice,
             "results": results,
         }
         content=render("ecom_search",ctx)
         ctx["content"]=content
         html=render("cms_layout",ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #44
0
 def post(self):
     db = get_connection()
     try:
         email = self.get_argument("email", None)
         if not email:
             raise Exception("Missing email")
         if not utils.check_email_syntax(email):
             raise Exception("Wrong Email syntax")
         res = get_model("base.user").search([["login", "=", email]])
         if not res:
             raise Exception("Email not found")
         forgot_id = get_model("cms.forgot.passwd").create({"email": email})
         forgot_obj = get_model("cms.forgot.passwd").browse(forgot_id)
         forgot_obj.trigger("forgot")
         ctx = self.context
         ctx["success"] = True
         ctx["message"] = "Reset password request was sent to your email. Please follow the instruction in email."
         content = render("cms_forgot_passwd", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except Exception as e:
         try:
             ctx = self.context
             ctx["error"] = True
             ctx["message"] = str(e)
             ctx["email"] = email
             content = render("cms_forgot_passwd", ctx)
             ctx["content"] = content
             html = render("cms_layout", ctx)
             self.write(html)
             db.commit()
         except:
             import traceback
             traceback.print_exc()
             db.rollback()
Example #45
0
 def post(self):
     db=get_connection()
     try:
         email=self.get_argument("email",None)
         if not email:
             raise Exception("Missing email")
         if not utils.check_email_syntax(email):
             raise Exception("Wrong Email syntax")
         res=get_model("base.user").search([["login","=",email]])
         if not res:
             raise Exception("Email not found")
         forgot_id = get_model("cms.forgot.passwd").create({"email": email})
         forgot_obj = get_model("cms.forgot.passwd").browse(forgot_id)
         forgot_obj.trigger("forgot")
         ctx=self.context
         ctx["success"]=True
         ctx["message"]="Reset password request was sent to your email. Please follow the instruction in email.";
         content=render("cms_forgot_passwd",ctx)
         ctx["content"]=content
         html=render("cms_layout",ctx)
         self.write(html)
         db.commit()
     except Exception as e:
         try:
             ctx=self.context
             ctx["error"]=True
             ctx["message"]=str(e)
             ctx["email"]=email
             content=render("cms_forgot_passwd",ctx)
             ctx["content"]=content
             html=render("cms_layout",ctx)
             self.write(html)
             db.commit()
         except:
             import traceback
             traceback.print_exc()
             db.rollback()
Example #46
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         seller_id = int(self.get_argument("seller_id"))
         comp = get_model("company").browse(seller_id)
         #products=get_model("product").search_browse([["company_id","=",seller_id]])
         res = get_model("product.group").search_browse(
             [["code", "=", "seller_new"], ["company_id", "=", seller_id]])
         if not res:
             raise Exception(
                 "No product group code 'seller_new' in company: ",
                 comp.name)
         new_product_group = res[0]
         res = get_model("product.group").search_browse(
             [["code", "=", "seller_rec"], ["company_id", "=", seller_id]])
         if not res:
             raise Exception(
                 "No product group code 'seller_new' in company: ",
                 comp.name)
         rec_product_group = res[0]
         ctx["seller"] = {
             "name": comp.name,
             "new_product_group": new_product_group,
             "rec_product_group": rec_product_group,
         }
         content = render("ecom_seller", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         self.redirect("/cms_page_not_found")
         import traceback
         traceback.print_exc()
         db.rollback()
Example #47
0
 def get(self):
     db = get_connection()
     try:
         cart_id = int(self.get_argument("cart_id"))
         print("cart_id", cart_id)
         cart = get_model("sale.order").browse(cart_id)
         ctx = self.context
         ctx["cart"] = cart
         html = render("ecom_order_cancelled", ctx)
         self.write(html)
         db.commit()
     except:
         import traceback
         traceback.print_exc()
         db.rollback()
Example #48
0
 def get(self):
     db=get_connection()
     try:
         ctx=self.context
         user_id = self.get_cookie("user_id")
         if not user_id:
             raise Exception("Can't access coupon page without login")
         user_id = int(user_id)
         user = get_model("base.user").browse(user_id)
         coupon_id=int(self.get_argument("coupon_id"))
         coupon=get_model("sale.coupon").browse(coupon_id)
         #if user.contact_id.id != coupon.contact_id.id:
             #raise Exception("Can't access coupon of other users")
         ctx["coupon"]=coupon
         content=render("ecom_coupon",ctx)
         ctx["content"]=content
         html=render("cms_layout",ctx)
         self.write(html)
         db.commit()
     except:
         self.redirect("cms_page_not_found")
         import traceback
         traceback.print_exc()
         db.rollback()
Example #49
0
 def get(self):
     #url="https://v5.inspection.in.th/inspectionreport/checkqr?id=1541844&password=f45681f1"
     current_local=get_active_locale()
     set_active_user(1) #admin
     set_active_locale('th_TH')
     db=get_connection() # prevent to error get transaction
     try:
         db.begin()
         id=self.get_argument("id")
         if not id:
             self.write("Missing ID")
             return
         password=self.get_argument("password")
         if not password:
             self.write("Missing Password")
             return
         ctx={
             'obj': None,
         }
         #res=db.query("select * from inspection where number=%s and password=%s",id,password)
         dom=[
             ['number','=', id],
             ['password','=', password]
         ]
         res=get_model("inspection").search_read(dom)
         if res:
             #t0=res[-1]['date']
             #t1=t0.split(" ")
             #res[-1]['date']='%s %s'%(sale_utils.date2thai(t1[0], format='%(d)s %(Tm)s %(BY)s'), t1[1])
             #res[-1]['date_register']=sale_utils.date2thai(res[-1]['date_register'], format='%(d)s %(Tm)s %(BY)s')
             ctx['obj']=res[-1]
         else:
             ctx['nothing']=True
         data=ctx['obj']
         html=render("checkqr",context=ctx, data=data)
         self.write(html)
     except Exception as e:
         self.write("ERROR : %s"%str(e))
     finally:
         if db:
             db.commit()
     set_active_locale(current_local)
Example #50
0
    def get(self):
        db = get_connection()
        try:
            website = self.context["website"]
            ctx = self.context
            cart_id = int(self.get_argument("cart_id"))
            cart = get_model("ecom.cart").browse(cart_id)
            ctx["cart"] = cart
            #if not cart.is_paid and website.payment_slip_template_id and (cart.pay_method_id.id == website.bank_method_id.id) and cart.state == "confirmed":
                #tmpl_name = website.payment_slip_template_id.name
                #url = "/report?type=report_jasper&model=ecom.cart&convert=pdf&ids=[%d]&template=%s" % (
                #    cart.id, tmpl_name)
                #ctx["payment_slip_report_url"] = url


            if not cart.is_paid and cart.state == "confirmed":

                meth=cart.pay_method_id
                if not meth:
                    raise Exception("Missing payment method")
                if meth.type == "bank":
                    if website.payment_slip_template_id:
                        tmpl_name = website.payment_slip_template_id.name
                        url = "/report?type=report_jasper&model=ecom.cart&convert=pdf&ids=[%d]&template=%s" % (
                            cart.id, tmpl_name)
                        ctx["payment_slip_report_url"] = url
                elif meth.type == "paypal":
                    if not meth.paypal_user:
                        raise Exception("Missing paypal user")
                    if not meth.paypal_password:
                        raise Exception("Missing paypal password")
                    if not meth.paypal_signature:
                        raise Exception("Missing paypal signature")
                    if not meth.paypal_url:
                        raise Exception("Missing paypal URL Server")
                    if meth.paypal_url == "test":
                        url = "https://api-3t.sandbox.paypal.com/nvp"
                    else:
                        url = "https://api-3t.paypal.com/nvp"
                    params = {
                        "method": "SetExpressCheckout",
                        "PAYMENTREQUEST_0_ITEMAMT": "%.2f" % (cart.amount_total - cart.amount_ship),
                        "PAYMENTREQUEST_0_AMT": "%.2f" % cart.amount_total,
                        "PAYMENTREQUEST_0_SHIPPINGAMT": "%.2f" % cart.amount_ship,
                        "PAYMENTREQUEST_0_CURRENCYCODE": "THB",
                        "PAYMENTREQUEST_0_PAYMENTACTION": "Sale",
                        "PAYMENTREQUEST_0_INVNUM": cart.number,
                        "returnUrl": "%s://%s/ecom_return_paypal?cart_id=%s" % (self.request.protocol, self.request.host, cart.id),
                        "cancelUrl": "%s://%s/ecom_order_cancelled?cart_id=%s" % (self.request.protocol, self.request.host, cart.id),
                        "version": "104.0",
                        "user": meth.paypal_user,
                        "pwd": meth.paypal_password,
                        "signature": meth.paypal_signature,
                    }
                    for i, line in enumerate(cart.lines):
                        params.update({
                            "L_PAYMENTREQUEST_0_NAME%d" % i: line.product_id.name,
                            "L_PAYMENTREQUEST_0_AMT%d" % i: "%.2f" % (line.amount / line.qty),
                            "L_PAYMENTREQUEST_0_QTY%d" % i: "%d" % line.qty,
                        })
                    try:
                        r = requests.get(url, params=params)
                        print("URL", r.url)
                        print("params", params)
                        res = urllib.parse.parse_qs(r.text)
                        print("RES", res)
                        token = res["TOKEN"][0]
                    except:
                        raise Exception("Failed start paypal transaction")
                    print("TOKEN", token)
                    if meth.paypal_url == "test":
                        url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=%s" % token
                    else:
                        url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=%s" % token
                    ctx["payment_url"] = url
                elif meth.type == "paysbuy":
                    psbID = meth.paysbuy_id
                    if not meth.paysbuy_username:
                        raise Exception("Missing paysbuy username")
                    username = meth.paysbuy_username
                    if not meth.paysbuy_securecode:
                        raise Exception("Missing paysbuy secure code")
                    secureCode = meth.paysbuy_securecode
                    if not meth.paysbuy_url:
                        raise Exception("Missing paysbuy server URL")
                    if meth.paysbuy_url == "test":
                        url = "http://demo.paysbuy.com/api_paynow/api_paynow.asmx/api_paynow_authentication_new"
                    else:
                        url = "https://paysbuy.com/api_paynow/api_paynow.asmx/api_paynow_authentication_new"
                    itm = " & ".join(["%s x %s" % (line.product_id.name, line.qty) for line in cart.lines])
                    data = {
                        "psbId": psbID,
                        "username": username,
                        "secureCode": secureCode,
                        "inv": cart.number,
                        "itm": itm,
                        "amt": "%.2f" % cart.amount_total,
                        "curr_type": "TH",
                        "method": 1,
                        "language": "T",
                        "resp_front_url": "%s://%s/ecom_return_paysbuy?cart_id=%s" % (self.request.protocol, self.request.host, cart.id),
                        "resp_back_url": "%s://%s/ecom_notif_paysbuy?cart_id=%s" % (self.request.protocol, self.request.host, cart.id),
                        "paypal_amt": "",
                        "com": "",
                        "opt_fix_redirect": "1",
                        "opt_fix_method": "",
                        "opt_name": "",
                        "opt_email": "",
                        "opt_mobile": "",
                        "opt_address": "",
                        "opt_detail": "",
                    }
                    print("url", url)
                    print("Data sent to paysbuy:")
                    pprint(data)
                    try:
                        r = requests.post(url, data=data)
                        print("Paysbuy response:", r.text)
                        res = r.text.encode(encoding="utf-8")
                        parser = etree.XMLParser(ns_clean=True, recover=True, encoding='utf-8')
                        tree = etree.fromstring(res, parser)
                        response = tree.text
                        code = response[0:2]
                        refid = response[2:]
                        print("refid: %s" % refid)
                    except:
                        raise Exception("Failed start paysbuy transaction")
                    if code == "00":
                        if meth.paysbuy_url == "test":
                            url = "http://demo.paysbuy.com/api_payment/paynow.aspx?refid=%s" % refid
                        else:
                            url = "https://paysbuy.com/api_payment/paynow.aspx?refid=%s" % refid
                    else:
                        raise Exception("Invalid paysbuy response code: %s" % code)
                    ctx["payment_url"] = url
                elif meth.type == "scb_gateway":
                    if not meth.scb_mid:
                        raise Exception("Missing SCB merchant ID")
                    mid = meth.scb_mid
                    if not meth.scb_terminal:
                        raise Exception("Missing SCB terminal ID")
                    terminal = meth.scb_terminal
                    if not meth.scb_url:
                        raise Exception("Missing SCB server URL")
                    sale_date = time.strptime(cart.date_created, '%Y-%m-%d %H:%M:%S')
                    date = time.strftime('%Y%m%d%H%M%S', sale_date)
                    params = [
                        ('mid', mid),
                        ('terminal', terminal),
                        ('command', 'CRAUTH'),
                        ('ref_no', cart.number),
                        ('ref_date', date),
                        ('service_id', 10),
                        ('cur_abbr', 'THB'),
                        ('amount', '%.2f' % float(cart.amount_total)),
                        ('backURL', 'http://%s/ecom_returnscb?cart_id=%s' % (self.request.host, cart.id))
                    ]
                    urlparams = '&'.join(['%s=%s' % (k, v) for (k, v) in params])
                    if meth.scb_url == "test":
                        url = 'https://nsips-test.scb.co.th:443/NSIPSWeb/NsipsMessageAction.do?' + urlparams
                    else:
                        url = 'https://nsips.scb.co.th/NSIPSWeb/NsipsMessageAction.do?' + urlparams
                    ctx["payment_url"] = url


            content = render("ecom_order_details", ctx)
            ctx["content"] = content
            html = render("cms_layout", ctx)
            self.write(html)
            db.commit()
        except:
            import traceback
            traceback.print_exc()
            db.rollback()
Example #51
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         website_id=self.request.headers.get("X-Website-ID")
         if website_id:
             website_id=int(website_id)
         else:
             res=get_model("website").search([["state","=","active"]])
             if not res:
                 raise Exception("No website found")
             website_id=res[0]
         self.website_id=website_id
         website=get_model("website").browse(website_id)
         browse_ctx={
             "website_id": website.id,
             "theme_id": website.theme_id.id,
             "sale_channel_id": website.sale_channel_id.id,
             "pricelist_id": website.sale_channel_id.pricelist_id.id if website.sale_channel_id else None,
         }
         user_id=self.get_cookie("user_id",None)
         if user_id:
             user_id=int(user_id)
             user=get_model("base.user").browse(user_id)
             contact = user.contact_id
             pricelist_ids=[website.sale_channel_id.pricelist_id.id]
             if contact.groups:
                 for group in contact.groups:
                     if group.sale_price_list_id:
                         pricelist_ids.append(group.sale_price_list_id.id)
             browse_ctx["pricelist_ids"]=pricelist_ids
         product_id = self.get_argument("product_id")
         product_id = int(product_id)
         prod = get_model("product").browse([product_id],context=browse_ctx)[0]
         if not prod.is_published and not access.check_permission_other("ecom_preview_product"):
             raise Exception("Product is not published")
         ctx["product"] = prod
         prod_vals = {
             "name": prod.name,
             "code": prod.code,
             "decription": prod.description,
             "image": prod.image,
             "sale_price": prod.customer_price,
             "variants": [],
             "images": [],
             "custom_options": [],
             "attributes": [],
             "type": prod.type,
         }
         if prod.customer_has_discount:
             prod_vals["old_price"] = prod.sale_price
         for img in prod.images:
             img_vals = {
                 "image": img.image,
                 "title": img.title,
             }
             prod_vals["images"].append(img_vals)
         for var in prod.variants:
             var_vals = {
                 "id": var.id,
                 "name": var.name,
                 "price": var.customer_price,
                 "stock_qty": var.stock_qty,
                 "image": var.image,
                 "images": [prod_image.image for prod_image in var.images],
                 "attributes": [],
             }
             if var.customer_has_discount:
                 var_vals["old_price"] = var.sale_price
             for attr in var.attributes:
                 attr_vals = {
                     "name": attr.attribute_id.name if attr.attribute_id else None,
                     "code": attr.attribute_id.code if attr.attribute_id else None,
                     "value": attr.option_id.code if attr.option_id else None,
                 }
                 var_vals["attributes"].append(attr_vals)
             prod_vals["variants"].append(var_vals)
         for attr in prod.attributes:
             attr_vals = {
                 "name": attr.attribute_id.name if attr.attribute_id else None,
                 "code": attr.attribute_id.code if attr.attribute_id else None,
                 "value": attr.option_id.code if attr.option_id else None,
             }
             prod_vals["attributes"].append(attr_vals)
         ctx["parent_categ_list"] = list_categ_parent(prod.categ_id, categ_list=[])
         ctx["product_json"] = utils.json_dumps(prod_vals)
         content = render("ecom_product", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         self.redirect("/cms_page_not_found")
         import traceback
         traceback.print_exc()
         db.rollback()
Example #52
0
 def post(self):
     website=self.context["website"]
     db = get_connection()
     try:
         if self.get_argument("commit", None):
             cart_id = self.get_argument("cart_id")
             cart_id = int(cart_id)
             fnames = [
                 "accept_marketing",
             ]
             vals = {}
             for n in fnames:
                 v = self.get_argument(n, None)
                 f = get_model("ecom.cart")._fields[n]
                 if v:
                     if isinstance(f, fields.Boolean):
                         v = v and True or False
                     elif isinstance(f, fields.Many2One):
                         v = int(v)
                 vals[n] = v
             if self.get_argument("check_tax", None):
                 if not self.get_argument("tax_no", None):
                     raise Exception("Please Enter Tax ID")
                 vals["tax_no"] = self.get_argument("tax_no", None)
             else:
                 vals["tax_no"] = ""
             if self.get_argument("tax_branch_no",None):
                 vals["tax_branch_no"]= self.get_argument("tax_branch_no",None)
             else:
                 vals["tax_branch_no"]= ""
             pay_method=self.get_argument("pay_method",None)
             if not pay_method:
                 raise Exception("Missing payment method")
             if pay_method=="bank_transfer":
                 pay_method_id=website.bank_method_id.id
             elif pay_method=="paypal":
                 pay_method_id=website.paypal_method_id.id
             elif pay_method=="paysbuy":
                 pay_method_id=website.paysbuy_method_id.id
             elif pay_method=="scb_gateway":
                 pay_method_id=website.scb_method_id.id
             else:
                 raise Exception("Invalid payment method")
             if not pay_method_id:
                 raise Exception("Payment method not configured")
             vals["pay_method_id"]=pay_method_id
             print("CART VALS", vals)
             get_model("ecom.cart").write([cart_id], vals)
             for arg in self.request.arguments:
                 if not arg.startswith("LINE_SHIP_METHOD_"):
                     continue
                 line_id=int(arg.replace("LINE_SHIP_METHOD_",""))
                 ship_method_code=self.get_argument(arg)
                 if ship_method_code:
                     res=get_model("ship.method").search([["code","=",ship_method_code]])
                     if not res:
                         raise Exception("Shipping method not found: %s"%ship_method_code)
                     ship_method_id=res[0]
                 else:
                     ship_method_id=None
                 vals={
                     "ship_method_id": ship_method_id,
                 }
                 print("line_id=%s => ship_method_id=%s"%(line_id,ship_method_id))
                 get_model("ecom.cart.line").write([line_id],vals)
             cart = get_model("ecom.cart").browse(cart_id)
             is_accept = self.get_argument("accept_marketing", None)
             if is_accept == 'on':
                 user_id = 1
                 res = get_model("sale.lead").search([["email", "=", cart.email]])
                 if not res:  # Check if this email already exist in Newsletter contact
                     vals = {
                         "state": "open",
                         "first_name": cart.bill_first_name,
                         "last_name": cart.bill_last_name,
                         "email": cart.email,
                         "user_id": user_id,
                     }
                     get_model("sale.lead").create(vals)
                 if not website.target_list_id:
                     raise Exception("No target list")
                 list_id = website.target_list_id.id
                 res = get_model("mkt.target").search([["email", "=", cart.email], ["list_id", "=", list_id]])
                 if not res:
                     target_vals = {
                         "list_id": list_id,
                         "first_name": cart.bill_first_name,
                         "last_name": cart.bill_last_name,
                         "email": cart.email,
                         "company": cart.bill_company,
                         "city": cart.bill_city,
                         "province_id": cart.bill_province_id.id,
                         "country_id": cart.bill_country_id.id,
                         "phone": cart.bill_phone,
                         "zip": cart.bill_postal_code,
                     }
                     get_model("mkt.target").create(target_vals)
             user_id = get_active_user()
             if not user_id and website.auto_create_account:
                 user_id = cart.create_account()
                 dbname = get_active_db()
                 token = new_token(dbname, user_id)
                 self.set_cookie("user_id", str(user_id))
                 self.set_cookie("token", token)
             set_active_user(1)
             set_active_company(1)
             cart.copy_to_contact({'force_write': False})
             if not user_id and website.auto_create_account: #First time create account
                 get_model("contact").trigger([cart.contact_id.id],"ecom_register")
             cart.copy_to_sale()
             cart = get_model("ecom.cart").browse(cart_id)
             db.commit()  # XXX: need otherwise browser redirect before commit?
             self.clear_cookie("cart_id")
             meth=cart.pay_method_id
             if not meth:
                 raise Exception("Missing payment method")
             if meth.type == "bank":
                 self.redirect("/ecom_order_confirmed?cart_id=%s" % cart.id)
             elif meth.type == "paypal":
                 if not meth.paypal_user:
                     raise Exception("Missing paypal user")
                 if not meth.paypal_password:
                     raise Exception("Missing paypal password")
                 if not meth.paypal_signature:
                     raise Exception("Missing paypal signature")
                 if not meth.paypal_url:
                     raise Exception("Missing paypal URL Server")
                 if meth.paypal_url == "test":
                     url = "https://api-3t.sandbox.paypal.com/nvp"
                 else:
                     url = "https://api-3t.paypal.com/nvp"
                 params = {
                     "method": "SetExpressCheckout",
                     "PAYMENTREQUEST_0_ITEMAMT": "%.2f" % (cart.amount_total - cart.amount_ship),
                     "PAYMENTREQUEST_0_AMT": "%.2f" % cart.amount_total,
                     "PAYMENTREQUEST_0_SHIPPINGAMT": "%.2f" % cart.amount_ship,
                     "PAYMENTREQUEST_0_CURRENCYCODE": "THB",
                     "PAYMENTREQUEST_0_PAYMENTACTION": "Sale",
                     "PAYMENTREQUEST_0_INVNUM": cart.number,
                     "returnUrl": "%s://%s/ecom_return_paypal?cart_id=%s" % (self.request.protocol, self.request.host, cart.id),
                     "cancelUrl": "%s://%s/ecom_order_cancelled?cart_id=%s" % (self.request.protocol, self.request.host, cart.id),
                     "version": "104.0",
                     "user": meth.paypal_user,
                     "pwd": meth.paypal_password,
                     "signature": meth.paypal_signature,
                 }
                 for i, line in enumerate(cart.lines):
                     params.update({
                         "L_PAYMENTREQUEST_0_NAME%d" % i: line.product_id.name,
                         "L_PAYMENTREQUEST_0_AMT%d" % i: "%.2f" % (line.amount / line.qty),
                         "L_PAYMENTREQUEST_0_QTY%d" % i: "%d" % line.qty,
                     })
                 try:
                     r = requests.get(url, params=params)
                     print("URL", r.url)
                     print("params", params)
                     res = urllib.parse.parse_qs(r.text)
                     print("RES", res)
                     token = res["TOKEN"][0]
                 except:
                     raise Exception("Failed start paypal transaction")
                 print("TOKEN", token)
                 if meth.paypal_url == "test":
                     url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=%s" % token
                 else:
                     url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=%s" % token
                 self.redirect(url)
             elif meth.type == "paysbuy":
                 psbID = meth.paysbuy_id
                 if not meth.paysbuy_username:
                     raise Exception("Missing paysbuy username")
                 username = meth.paysbuy_username
                 if not meth.paysbuy_securecode:
                     raise Exception("Missing paysbuy secure code")
                 secureCode = meth.paysbuy_securecode
                 if not meth.paysbuy_url:
                     raise Exception("Missing paysbuy server URL")
                 if meth.paysbuy_url == "test":
                     url = "http://demo.paysbuy.com/api_paynow/api_paynow.asmx/api_paynow_authentication_new"
                 else:
                     url = "https://paysbuy.com/api_paynow/api_paynow.asmx/api_paynow_authentication_new"
                 itm = " & ".join(["%s x %s" % (line.product_id.name, line.qty) for line in cart.lines])
                 data = {
                     "psbId": psbID,
                     "username": username,
                     "secureCode": secureCode,
                     "inv": cart.number,
                     "itm": itm,
                     "amt": "%.2f" % cart.amount_total,
                     "curr_type": "TH",
                     "method": 1,
                     "language": "T",
                     "resp_front_url": "%s://%s/ecom_return_paysbuy?cart_id=%s" % (self.request.protocol, self.request.host, cart.id),
                     "resp_back_url": "%s://%s/ecom_notif_paysbuy?cart_id=%s" % (self.request.protocol, self.request.host, cart.id),
                     "paypal_amt": "",
                     "com": "",
                     "opt_fix_redirect": "1",
                     "opt_fix_method": "",
                     "opt_name": "",
                     "opt_email": "",
                     "opt_mobile": "",
                     "opt_address": "",
                     "opt_detail": "",
                 }
                 print("url", url)
                 print("Data sent to paysbuy:")
                 pprint(data)
                 try:
                     r = requests.post(url, data=data)
                     print("Paysbuy response:", r.text)
                     res = r.text.encode(encoding="utf-8")
                     parser = etree.XMLParser(ns_clean=True, recover=True, encoding='utf-8')
                     tree = etree.fromstring(res, parser)
                     response = tree.text
                     code = response[0:2]
                     refid = response[2:]
                     print("refid: %s" % refid)
                 except:
                     raise Exception("Failed start paysbuy transaction")
                 if code == "00":
                     if meth.paysbuy_url == "test":
                         url = "http://demo.paysbuy.com/api_payment/paynow.aspx?refid=%s" % refid
                     else:
                         url = "https://paysbuy.com/api_payment/paynow.aspx?refid=%s" % refid
                 else:
                     raise Exception("Invalid paysbuy response code: %s" % code)
                 self.redirect(url)
             elif meth.type == "scb_gateway":
                 if not meth.scb_mid:
                     raise Exception("Missing SCB merchant ID")
                 mid = meth.scb_mid
                 if not meth.scb_terminal:
                     raise Exception("Missing SCB terminal ID")
                 terminal = meth.scb_terminal
                 if not meth.scb_url:
                     raise Exception("Missing SCB server URL")
                 sale_date = time.strptime(cart.date_created, '%Y-%m-%d %H:%M:%S')
                 date = time.strftime('%Y%m%d%H%M%S', sale_date)
                 params = [
                     ('mid', mid),
                     ('terminal', terminal),
                     ('command', 'CRAUTH'),
                     ('ref_no', cart.number),
                     ('ref_date', date),
                     ('service_id', 10),
                     ('cur_abbr', 'THB'),
                     ('amount', '%.2f' % float(cart.amount_total)),
                     ('backURL', 'http://%s/ecom_returnscb?cart_id=%s' % (self.request.host, cart.id))
                 ]
                 urlparams = '&'.join(['%s=%s' % (k, v) for (k, v) in params])
                 if meth.scb_url == "test":
                     url = 'https://nsips-test.scb.co.th:443/NSIPSWeb/NsipsMessageAction.do?' + urlparams
                 else:
                     url = 'https://nsips.scb.co.th/NSIPSWeb/NsipsMessageAction.do?' + urlparams
                 self.redirect(url)
             else:
                 raise Exception("Unsupported payment method")
         db.commit()
     except Exception as e:
         import traceback
         traceback.print_exc()
         error_message = str(e)
         ctx = self.context
         cart = ctx.get("cart")
         if not cart:
             db.commit()
             self.redirect("/index")
             return
         ctx["ship_methods"] = cart.get_ship_methods()
         website=self.context["website"]
         ctx["error_message"] = error_message
         content = render("ecom_checkout2", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.rollback()
Example #53
0
    def get(self):
        db = get_connection()
        try:
            description = ""
            ctx = self.context
            categ_id = self.get_argument("categ_id", None)
            if categ_id:
                categ_id = int(categ_id)
            categ_code = self.get_argument("categ_code", None)
            if categ_code and not categ_id:
                res = get_model("product.categ").search(
                    [["code", "=", categ_code]])
                if not res:
                    raise Exception("Product categ not found: '%s'" %
                                    categ_code)
                categ_id = res[0]
            brand_id = self.get_argument("brand_id", [])
            supp_id = self.get_argument("supp_id", [])
            if brand_id:
                bids = brand_id.split(",")
                brand_id = []
                for bid in bids:
                    bid = int(bid)
                    brand_id.append(bid)
            if supp_id:
                bids = supp_id.split(",")
                supp_id = []
                for bid in bids:
                    bid = int(bid)
                    supp_id.append(bid)
            ctx["brand_id"] = brand_id
            ctx["supp_id"] = supp_id
            price = self.get_argument("price", None)
            sort_by = self.get_argument("sort_by", None)
            cond = [["parent_id", "=", None], ["is_published", "=", True]]
            cond_filter_categ = cond[:]
            cond_filter_brand = cond[:]
            if categ_id:
                cond.append(["categ_id", "child_of", categ_id])
                ctx["list_parent_categ"] = list_parent(
                    get_model("product.categ").browse(categ_id), lst=[])  # XXX
                cond_filter_brand.append(["categ_id", "child_of", categ_id])
                categ = get_model("product.categ").browse(categ_id)
                categ_ctx = {
                    "name": categ.name,
                    "image": categ.image if categ.sub_categories else None,
                    "last_level_categs": get_last_level(categ),
                }

                if categ.description:
                    description = categ.description
                else:
                    desc = categ
                    while desc.parent_id:
                        desc = desc.parent_id
                        if desc.description:
                            description = desc.description
                            break
                if description:
                    ctx["title_description"] = description
                while categ.parent_id:
                    categ = categ.parent_id
                cond_filter_categ.append(["categ_id", "child_of", categ.id])
                ctx["categ"] = categ_ctx
            if brand_id:
                cond.append(["brand_id", "child_of", brand_id])
                cond_filter_categ.append(["brand_id", "child_of", brand_id])
            if supp_id:
                cond.append(["company_id", "child_of", supp_id])
                cond_filter_categ.append(["company_id", "child_of", supp_id])
                cond_filter_brand.append(["company_id", "child_of", supp_id])
            prices = ["0", "0"]
            if price:
                prices = price.split("-")
                if len(prices) != 2:
                    raise Exception("Incorrect Price format")
                if not prices[0].isdigit() or not prices[1].isdigit():
                    raise Exception("Min/Max prices is not digit")
                cond.append(["sale_price", ">=", prices[0]])
                cond.append(["sale_price", "<=", prices[1]])
                cond_filter_categ.append(["sale_price", ">=", prices[0]])
                cond_filter_categ.append(["sale_price", "<=", prices[1]])
                cond_filter_brand.append(["sale_price", ">=", prices[0]])
                cond_filter_brand.append(["sale_price", "<=", prices[1]])
            website = ctx["website"]
            browse_ctx = {
                "pricelist_id":
                website.sale_channel_id.pricelist_id.id
                if website.sale_channel_id else None,
                "product_filter":
                cond,
            }

            user_id = self.get_cookie("user_id", None)
            if user_id:
                user_id = int(user_id)
                user = get_model("base.user").browse(user_id)
                contact = user.contact_id
                pricelist_ids = [website.sale_channel_id.pricelist_id.id]
                if contact.groups:
                    for group in contact.groups:
                        if group.sale_price_list_id:
                            pricelist_ids.append(group.sale_price_list_id.id)
                browse_ctx["pricelist_ids"] = pricelist_ids
            products = get_model("product").search_browse(condition=cond,
                                                          order=sort_by,
                                                          context=browse_ctx)

            cond_filter_supp = cond[:]
            if supp_id:
                cond_filter_supp.remove(["company_id", "child_of", supp_id])

            ctx["products"] = products
            ctx["categs"] = get_categs(cond_filter_categ)
            ctx["brands"] = get_brands(cond_filter_brand)
            ctx["suppliers"] = get_supps(
                get_model("product").search_browse(condition=cond_filter_supp,
                                                   order=sort_by,
                                                   context=browse_ctx))
            ctx["events"] = get_events()
            ctx["pricerange"] = get_price_range(
                get_model("product").search_browse([], context=browse_ctx),
                prices)
            ctx["filter_product_groups"] = get_model(
                "product.group").search_browse([["code", "=", "recommended"]],
                                               context=browse_ctx)[0]
            data = {
                "categ_id": categ_id,
                "brand_id": brand_id,
                "price": price,
                "sort_by": sort_by,
                "supp_id": supp_id,
            }
            content = render("ecom_products", ctx, data=data)
            ctx["content"] = content
            html = render("cms_layout", ctx, data=data)
            self.write(html)
            db.commit()
        except:
            self.redirect("/cms_page_not_found")
            import traceback
            traceback.print_exc()
            db.rollback()
Example #54
0
 def get(self):
     db = get_connection()
     try:
         ctx = self.context
         website_id = self.request.headers.get("X-Website-ID")
         if website_id:
             website_id = int(website_id)
         else:
             res = get_model("website").search([["state", "=", "active"]])
             if not res:
                 raise Exception("No website found")
             website_id = res[0]
         self.website_id = website_id
         website = get_model("website").browse(website_id)
         browse_ctx = {
             "website_id":
             website.id,
             "theme_id":
             website.theme_id.id,
             "sale_channel_id":
             website.sale_channel_id.id,
             "pricelist_id":
             website.sale_channel_id.pricelist_id.id
             if website.sale_channel_id else None,
         }
         user_id = self.get_cookie("user_id", None)
         if user_id:
             user_id = int(user_id)
             user = get_model("base.user").browse(user_id)
             contact = user.contact_id
             pricelist_ids = [website.sale_channel_id.pricelist_id.id]
             if contact.groups:
                 for group in contact.groups:
                     if group.sale_price_list_id:
                         pricelist_ids.append(group.sale_price_list_id.id)
             browse_ctx["pricelist_ids"] = pricelist_ids
         product_id = self.get_argument("product_id")
         product_id = int(product_id)
         prod = get_model("product").browse([product_id],
                                            context=browse_ctx)[0]
         if not prod.is_published and not access.check_permission_other(
                 "ecom_preview_product"):
             raise Exception("Product is not published")
         ctx["product"] = prod
         prod_vals = {
             "name": prod.name,
             "code": prod.code,
             "decription": prod.description,
             "image": prod.image,
             "sale_price": prod.customer_price,
             "variants": [],
             "images": [],
             "custom_options": [],
             "attributes": [],
             "type": prod.type,
         }
         if prod.customer_has_discount:
             prod_vals["old_price"] = prod.sale_price
         for img in prod.images:
             img_vals = {
                 "image": img.image,
                 "title": img.title,
             }
             prod_vals["images"].append(img_vals)
         for var in prod.variants:
             var_vals = {
                 "id": var.id,
                 "name": var.name,
                 "price": var.customer_price,
                 "stock_qty": var.stock_qty,
                 "image": var.image,
                 "images": [prod_image.image for prod_image in var.images],
                 "attributes": [],
             }
             if var.customer_has_discount:
                 var_vals["old_price"] = var.sale_price
             for attr in var.attributes:
                 attr_vals = {
                     "name":
                     attr.attribute_id.name if attr.attribute_id else None,
                     "code":
                     attr.attribute_id.code if attr.attribute_id else None,
                     "value":
                     attr.option_id.code if attr.option_id else None,
                 }
                 var_vals["attributes"].append(attr_vals)
             prod_vals["variants"].append(var_vals)
         for attr in prod.attributes:
             attr_vals = {
                 "name":
                 attr.attribute_id.name if attr.attribute_id else None,
                 "code":
                 attr.attribute_id.code if attr.attribute_id else None,
                 "value": attr.option_id.code if attr.option_id else None,
             }
             prod_vals["attributes"].append(attr_vals)
         ctx["parent_categ_list"] = list_categ_parent(prod.categ_id,
                                                      categ_list=[])
         ctx["product_json"] = utils.json_dumps(prod_vals)
         content = render("ecom_product", ctx)
         ctx["content"] = content
         html = render("cms_layout", ctx)
         self.write(html)
         db.commit()
     except:
         self.redirect("/cms_page_not_found")
         import traceback
         traceback.print_exc()
         db.rollback()