def checkout_remove(request, code): """ Checkout. Order cart """ context_instance = RequestContext(request) products = ProductProduct.objects.filter(code=code) if len(products) > 0: partner_id = checkPartnerID(request) if not partner_id: error = _( 'Are you a customer? Please, contact us. We will create a new role.' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _( 'Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) order = check_order(conn, partner_id, OERP_SALE) order_lines = conn.SaleOrderLine.filter(order_id=order.id, product_id=products[0].id) if len(order_lines) > 0: order_line = conn.SaleOrderLine.get(order_lines[0].id) order_line.delete() return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI']))
def order(request, order): """ Order. Order Detail Partner """ partner_id = checkPartnerID(request) if not partner_id: error = _('Are you a customer? Please, contact us. We will create a new role.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _('Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) values = conn.SaleOrder.filter(partner_id=partner_id, name=order, shop_id__in=OERP_SALES) if len(values) == 0: error = _('It is not allowed to view this section or not found. Use navigation menu.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) value = values[0] title = _(u'Order %s') % (value.name) metadescription = _(u'Details order %s') % (value.name) currency = value.pricelist_id.currency_id.symbol return render_to_response("sale/order.html", { 'title': title, 'metadescription': metadescription, 'value': value, 'currency': currency, 'show_vat': ORDER_SHOW_VAT, }, context_instance=RequestContext(request))
def checkout_remove(request, code): """ Checkout. Order cart """ context_instance=RequestContext(request) products = ProductProduct.objects.filter(code=code) if len(products) > 0: partner_id = checkPartnerID(request) if not partner_id: error = _('Are you a customer? Please, contact us. We will create a new role.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _('Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) order = check_order(conn, partner_id, OERP_SALE) order_lines = conn.SaleOrderLine.filter(order_id=order.id, product_id=products[0].id) if len(order_lines) > 0: order_line = conn.SaleOrderLine.get(order_lines[0].id) order_line.delete() return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI']))
def payment(request, order): """ Payment. Payment Order """ partner_id = checkPartnerID(request) if not partner_id: error = _( 'Are you a customer? Please, contact us. We will create a new role.' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _( 'Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) values = conn.SaleOrder.filter(partner_id=partner_id, name=order, shop_id__in=OERP_SALES) if len(values) == 0: error = _( 'It is not allowed to view this section or not found. Use navigation menu.' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) value = values[0] if value.state != 'draft' or value.payment_state != 'draft': error = _('Your order is in progress or this order was payed') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) sale_shop = conn.SaleShop.filter(id=OERP_SALE)[0] payments = sale_shop.zoook_payment_types title = _(u'Payment Order %s') % (value.name) metadescription = _(u'Payment Order %s') % (value.name) currency = value.pricelist_id.currency_id.symbol return render_to_response("sale/payment.html", { 'title': title, 'metadescription': metadescription, 'value': value, 'payments': payments, 'currency': currency, }, context_instance=RequestContext(request))
def profile(request): """Profile page""" site_configuration = siteConfiguration(SITE_ID) full_name = checkFullName(request) title = _(u'Profile %(full_name)s') % {'full_name':full_name} metadescription = _(u'Account frontpage of %(site)s') % {'site':site_configuration.site_title} return render_to_response("partner/profile.html", locals(), context_instance=RequestContext(request))
def orders(request): """ Orders. All Orders Partner Available """ partner_id = checkPartnerID(request) if not partner_id: error = _( 'Are you a customer? Please, contact us. We will create a new role.' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _( 'Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) values = {} total = len( conn.SaleOrder.filter(partner_id=partner_id, shop_id__in=OERP_SALES)) offset, page_previous, page_next = paginationOOOP(request, total, PAGINATOR_ORDER_TOTAL) values = conn.SaleOrder.filter(partner_id=partner_id, shop_id__in=OERP_SALES, offset=offset, limit=PAGINATOR_ORDER_TOTAL, order='date_order DESC, name DESC') orders = [] for order in values: num_lines = len(conn.SaleOrderLine.filter(order_id=order.id)) if num_lines > 0: orders.append(order) title = _(u'All Orders') metadescription = _(u'List all orders of %s') % full_name return render_to_response("sale/orders.html", { 'title': title, 'metadescription': metadescription, 'values': orders, 'page_previous': page_previous, 'page_next': page_next, }, context_instance=RequestContext(request))
def profile(request): """Profile page""" site_configuration = siteConfiguration(SITE_ID) full_name = checkFullName(request) title = _(u'Profile %(full_name)s') % {'full_name': full_name} metadescription = _(u'Account frontpage of %(site)s') % { 'site': site_configuration.site_title } return render_to_response("partner/profile.html", locals(), context_instance=RequestContext(request))
def cancel(request, order): """ Order. Cancel Order """ partner_id = checkPartnerID(request) if not partner_id: error = _('Are you a customer? Please, contact us. We will create a new role.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _('Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) values = conn.SaleOrder.filter(partner_id=partner_id, name=order, shop_id__in=OERP_SALES) if len(values) == 0: error = _('It is not allowed to view this section or not found. Use navigation menu.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) value = values[0] if value.state != 'draft': error = _('Your order is in progress and it is not possible to cancel. Contact with us') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) #cancel order try: cancel = conn_webservice('sale.order','action_cancel', [[value.id]]) except: error = _('An error is getting when cancel this order. Try again or contact us') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) #drop session if exists if 'sale_order' in request.session: if request.session['sale_order'] == value.name: del request.session['sale_order'] value = conn.SaleOrder.get(value.id) #reload sale order values title = _(u'Order %s cancelled') % (value.name) metadescription = _(u'Order %s cancelled') % (value.name) return render_to_response("sale/order.html", { 'title': title, 'metadescription': metadescription, 'value': value, }, context_instance=RequestContext(request))
def order(request, order): """ Order. Order Detail Partner """ partner_id = checkPartnerID(request) if not partner_id: error = _( 'Are you a customer? Please, contact us. We will create a new role.' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _( 'Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) values = conn.SaleOrder.filter(partner_id=partner_id, name=order, shop_id__in=OERP_SALES) if len(values) == 0: error = _( 'It is not allowed to view this section or not found. Use navigation menu.' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) value = values[0] title = _(u'Order %s') % (value.name) metadescription = _(u'Details order %s') % (value.name) currency = value.pricelist_id.currency_id.symbol return render_to_response("sale/order.html", { 'title': title, 'metadescription': metadescription, 'value': value, 'currency': currency, 'show_vat': ORDER_SHOW_VAT, }, context_instance=RequestContext(request))
def invoices(request): partner_id = checkPartnerID(request) if not partner_id: error = _('Are you a customer? Please, contact us. We will create a new role.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _('Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) values = {} total = len(conn.AccountInvoice.filter(partner_id=partner_id, state__ne='draft', type='out_invoice', company_id=OERP_COMPANY)) offset, page_previous, page_next = paginationOOOP(request, total, PAGINATOR_INVOICE_TOTAL) values = conn.AccountInvoice.filter(partner_id=partner_id, state__ne='draft', type='out_invoice', company_id=OERP_COMPANY, offset=offset, limit=PAGINATOR_INVOICE_TOTAL, order='name DESC') title = _(u'All Invoices') metadescription = _(u'List all invoices of %s') % full_name return render_to_response("account/invoices.html", {'title':title, 'metadescription':metadescription, 'values':values, 'page_previous':page_previous, 'page_next':page_next}, context_instance=RequestContext(request))
def invoice(request, invoice): partner_id = checkPartnerID(request) if not partner_id: error = _('Are you a customer? Please, contact us. We will create a new role.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _('Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) values = conn.AccountInvoice.filter(partner_id=partner_id, number=invoice, company_id=OERP_COMPANY) if len(values) == 0: error = _('It is not allowed to view this section or not found. Use navigation menu.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) value = values[0] title = _(u'Invoice %s') % (value.number) metadescription = _(u'Details invoice %s') % (value.number) return render_to_response("account/invoice.html", {'title': title, 'metadescription': metadescription, 'value': value}, context_instance=RequestContext(request))
def payment(request, order): """ Payment. Payment Order """ partner_id = checkPartnerID(request) if not partner_id: error = _('Are you a customer? Please, contact us. We will create a new role.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _('Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) values = conn.SaleOrder.filter(partner_id=partner_id, name=order, shop_id__in=OERP_SALES) if len(values) == 0: error = _('It is not allowed to view this section or not found. Use navigation menu.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) value = values[0] if value.state != 'draft' or value.payment_state != 'draft': error = _('Your order is in progress or this order was payed') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) sale_shop = conn.SaleShop.filter(id=OERP_SALE)[0] payments = sale_shop.zoook_payment_types title = _(u'Payment Order %s') % (value.name) metadescription = _(u'Payment Order %s') % (value.name) currency = value.pricelist_id.currency_id.symbol return render_to_response("sale/payment.html", { 'title': title, 'metadescription': metadescription, 'value': value, 'payments': payments, 'currency': currency, }, context_instance=RequestContext(request))
def orders(request): """ Orders. All Orders Partner Available """ partner_id = checkPartnerID(request) if not partner_id: error = _('Are you a customer? Please, contact us. We will create a new role.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _('Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) values = {} total = len(conn.SaleOrder.filter(partner_id=partner_id, shop_id__in=OERP_SALES)) offset, page_previous, page_next = paginationOOOP(request, total, PAGINATOR_ORDER_TOTAL) values = conn.SaleOrder.filter(partner_id=partner_id, shop_id__in=OERP_SALES, offset=offset, limit=PAGINATOR_ORDER_TOTAL, order='date_order DESC, name DESC') orders = [] for order in values: num_lines = len(conn.SaleOrderLine.filter(order_id=order.id)) if num_lines > 0: orders.append(order) title = _(u'All Orders') metadescription = _(u'List all orders of %s') % full_name return render_to_response("sale/orders.html", { 'title':title, 'metadescription':metadescription, 'values':orders, 'page_previous':page_previous, 'page_next':page_next, }, context_instance=RequestContext(request))
def checkout_confirm(request): """ Checkout. Confirm """ context_instance=RequestContext(request) if 'sale_order' in request.session: return HttpResponseRedirect("%s/sale/order/%s" % (context_instance['LOCALE_URI'],request.session['sale_order'])) if request.method == 'POST': partner_id = checkPartnerID(request) if not partner_id: error = _('Are you a customer? Please, contact us. We will create a new role.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _('Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) partner = conn.ResPartner.get(partner_id) order = check_order(conn, partner_id, OERP_SALE) if order.state != 'draft': return HttpResponseRedirect("%s/sale/" % (context_instance['LOCALE_URI'])) delivery = request.POST['delivery'] or False payment = request.POST['payment'] or False address_invoice = request.POST['address_invoice'] or False address_delivery = request.POST['address_delivery'] or False #delivery if delivery: delivery = delivery.split('|') carrier = conn.DeliveryCarrier.filter(code=delivery[0]) price_unit = float(re.sub(',','.',delivery[1])) if len(carrier) == 0: return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI'])) carrier = carrier[0] if partner.property_product_pricelist: pricelist = partner.property_product_pricelist.id else: shop = conn.SaleShop.get(OERP_SALE) pricelist = shop.pricelist_id.id if price_unit != 0.0: # Add delivery product in the order # if not free of charge values = [ [order.id], #ids pricelist, #pricelist carrier.product_id.id, #product 1, #qty False, #uom 0, #qty_uos False, #uos '', #name partner.id, #partner_id ] product_id_change = conn_webservice('sale.order.line','product_id_change', values) order_line = conn.SaleOrderLine.new() order_line.order_id = order order_line.name = carrier.product_id.name order_line.product_id = carrier.product_id order_line.product_uom_qty = 1 order_line.product_uom = carrier.product_id.product_tmpl_id.uom_id order_line.delay = product_id_change['value']['delay'] order_line.th_weight = product_id_change['value']['th_weight'] order_line.type = product_id_change['value']['type'] order_line.price_unit = price_unit order_line.tax_id = [conn.AccountTax.get(t_id) for t_id in product_id_change['value']['tax_id']] order_line.product_packaging = '' order_line.save() #delivery order.carrier_id = carrier #payment type payment_type = conn.ZoookSaleShopPaymentType.filter(app_payment=payment) if len(payment_type) > 0: if payment_type[0].commission: #add new order line payment = conn_webservice('zoook.sale.shop.payment.type','set_payment_commission', [order.id, payment]) order.payment_type = payment_type[0].payment_type_id order.picking_policy = payment_type[0].picking_policy order.order_policy = payment_type[0].order_policy order.invoice_quantity = payment_type[0].invoice_quantity else: return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI'])) #Replace invoice address and delivery address if address_invoice: #add new invoice address if address_invoice == 'add_invoice': address = conn.ResPartnerAddress.new() address.name = request.POST['invoice_name'] address.partner_id = conn.ResPartner.get(partner_id) address.type = 'invoice' address.street = request.POST['invoice_street'] address.zip = request.POST['invoice_zip'] address.city = request.POST['invoice_city'] countries = ResCountry.objects.filter(code=request.POST['invoice_country_code']) if len(countries)>0: country = countries[0].id address.country_id = conn.ResCountry.get(country) if request.user.email: address.email = request.user.email address.phone = request.POST['invoice_phone'] address_invoice = address.save() address_invoice = conn.ResPartnerAddress.get(int(address_invoice)) if address_invoice: order.partner_invoice_id = address_invoice else: return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI'])) if address_delivery: #add new delivery address if address_delivery == 'add_delivery': address = conn.ResPartnerAddress.new() address.name = request.POST['delivery_name'] address.partner_id = conn.ResPartner.get(partner_id) address.type = 'delivery' address.street = request.POST['delivery_street'] address.zip = request.POST['delivery_zip'] address.city = request.POST['delivery_city'] countries = ResCountry.objects.filter(code=request.POST['delivery_country_code']) if len(countries)>0: country = countries[0].id address.country_id = conn.ResCountry.get(country) if request.user.email: address.email = request.user.email address.phone = request.POST['delivery_phone'] address_delivery = address.save() address_delivery = conn.ResPartnerAddress.get(int(address_delivery)) if address_delivery: order.partner_shipping_id = address_delivery else: return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI'])) #cupon code / promotion code_promotion = request.POST['promotion'] if code_promotion: order.coupon_code = code_promotion #payment state order.payment_state = 'checking' order.save() #apply cupon code / promotion if code_promotion: promotion = conn_webservice('promos.rules','apply_promotions', [order.id]) logging.info('[%s] %s' % (time.strftime('%Y-%m-%d %H:%M:%S'), 'Apply promotion %s Order %s' % (code_promotion, order.name) )) logging.info('[%s] %s' % (time.strftime('%Y-%m-%d %H:%M:%S'), 'Payment %s Order %s' % (payment_type[0].app_payment, order.name) )) request.session['sale_order'] = order.name return HttpResponseRedirect("%s/payment/%s/" % (context_instance['LOCALE_URI'], payment_type[0].app_payment)) else: return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI']))
def checkout(request): """ Checkout. Order Cart """ context_instance=RequestContext(request) if 'sale_order' in request.session: return HttpResponseRedirect("%s/sale/order/%s" % (context_instance['LOCALE_URI'],request.session['sale_order'])) site_configuration = siteConfiguration(SITE_ID) message = False partner_id = checkPartnerID(request) if not partner_id: error = _('Are you a customer? Please, contact us. We will create a new role.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _('Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) order = check_order(conn, partner_id, OERP_SALE) if order == 'error': return HttpResponseRedirect("%s/partner/partner/" % (context_instance['LOCALE_URI'])) if request.method == 'POST' or request.GET.get('code'): if request.POST.get('code'): code = request.POST['code'] qty = int(request.POST['qty']) else: code = request.GET['code'] qty = int(request.GET['qty']) #check product is available to add to cart product = check_product(conn, code) if product: #check if this product exist product_line = conn.SaleOrderLine.filter(order_id=order.id, product_id=product.id) product = conn.ProductProduct.get(product.id) partner = conn.ResPartner.get(partner_id) if len(product_line) > 0: #product line exist -> update order_line = conn.SaleOrderLine.get(product_line[0].id) order_line.product_uom_qty = qty+product_line[0].product_uom_qty order_line.save() else: #product line not exist -> create if partner.property_product_pricelist: pricelist = partner.property_product_pricelist.id else: shop = conn.SaleShop.get(OERP_SALE) pricelist = shop.pricelist_id.id values = [ [order.id], #ids partner.property_product_pricelist.id, #pricelist product.id, #product qty, #qty False, #uom 0, #qty_uos False, #uos '', #name partner_id, #partner_id ] try: product_id_change = conn_webservice('sale.order.line','product_id_change', values) except Exception, e: logging.error("Error creating/modifying the order.\nValues: %s\nException: %s" % (str(values),str(e))) values = { 'title': _('Checkout Error'), 'error':_("Error creating/modifying the order. Try again, or contact with us."), } return render_to_response("sale/checkout.html", values, context_instance=RequestContext(request)) sale_order_add_product = True not_enought_stock = None if product_id_change['warning'] and SALE_ORDER_PRODUCT_CHECK: if SALE_ORDER_PRODUCE_PRODUCT_CHECK or product.supply_method != 'produce': not_enought_stock = _('Not enough stock !') sale_order_add_product = False if sale_order_add_product: product_value = product_id_change['value'] order_line = conn.SaleOrderLine.new() order_line.order_id = order order_line.name = product_id_change['value']['name'] if 'notes' in product_value: order_line.notes = product_id_change['value']['notes'] order_line.product_id = product order_line.product_uom_qty = qty order_line.product_uom = product.product_tmpl_id.uom_id order_line.delay = product_id_change['value']['delay'] order_line.th_weight = product_id_change['value']['th_weight'] order_line.type = product_id_change['value']['type'] order_line.price_unit = product_id_change['value']['price_unit'] order_line.purchase_price = product_id_change['value']['purchase_price'] order_line.tax_id = [conn.AccountTax.get(t_id) for t_id in product_id_change['value']['tax_id']] order_line.product_packaging = '' order_line.save() else: message = product_id_change['warning'] if message and 'title' in message: if not_enought_stock != None: message = not_enought_stock else: message = message['title'] #recalcule order (refresh amount) order = check_order(conn, partner_id, OERP_SALE)
def wishlist(request): """ Wishlist Favourites products customer """ partner_id = checkPartnerID(request) if not partner_id: error = _('Are you a customer? Please, contact us. We will create a new role.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _('Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) prod_wishlist = False partner = conn.ResPartner.get(partner_id) product_obj = partner.product_wishlist_ids path = request.path_info.split('/') if 'remove' in path: kwargs = { 'slug_'+get_language(): path[-1], #slug is unique } tplproduct = ProductTemplate.objects.filter(**kwargs) if tplproduct.count() > 0: try: for prod in product_obj: if prod.id == tplproduct[0].id: #exist this product wishlist prod_wishlist = conn_webservice('res.partner','write', [[partner_id], {'product_wishlist_ids':[(3, tplproduct[0].id)]}]) except: prod_wishlist = True if 'add' in path: kwargs = { 'slug_'+get_language(): path[-1], #slug is unique } tplproduct = ProductTemplate.objects.filter(**kwargs) if tplproduct.count() > 0: check_add = False if product_obj: for prod in product_obj: if prod.id == tplproduct[0].id: #exist this product wishlist check_add = True if not check_add: prod_wishlist = conn_webservice('res.partner','write', [[partner_id], {'product_wishlist_ids':[(4, tplproduct[0].id)]}]) title = _(u'Whislist') metadescription = _(u'Whislist of %s') % full_name if prod_wishlist: partner = conn.ResPartner.get(partner_id) #refresh product_wishlist_ids if add or remove product_obj = partner.product_wishlist_ids products = [] if product_obj: for prod in product_obj: prods = ProductProduct.objects.filter(product_tmpl=prod.id).order_by('price') tplproduct = ProductTemplate.objects.get(id=prod.id) i = 0 prod_images = [] while i<len(prods) and len(prod_images)==0: prod_images = ProductImages.objects.filter(product=prods[i].id,base_image=True) i+=1 base_image = False if prod_images.count() > 0: base_image = prod_images[0] products.append({'product': tplproduct, 'name': tplproduct.name, 'products': prods, 'base_image': base_image}) return render_to_response("catalog/wishlist.html", { 'title': title, 'metadescription': metadescription, 'products': products, 'currency': DEFAULT_CURRENCY, 'currency_position': CURRENCY_LABEL_POSITION, 'update_price': UPDATE_PRICE }, context_instance=RequestContext(request))
def checkout(request): """ Checkout. Order Cart """ context_instance = RequestContext(request) if 'sale_order' in request.session: return HttpResponseRedirect( "%s/sale/order/%s" % (context_instance['LOCALE_URI'], request.session['sale_order'])) site_configuration = siteConfiguration(SITE_ID) message = False partner_id = checkPartnerID(request) if not partner_id: error = _( 'Are you a customer? Please, contact us. We will create a new role.' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _( 'Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) order = check_order(conn, partner_id, OERP_SALE) if order == 'error': return HttpResponseRedirect("%s/partner/partner/" % (context_instance['LOCALE_URI'])) if request.method == 'POST' or request.GET.get('code'): if request.POST.get('code'): code = request.POST['code'] qty = int(request.POST['qty']) else: code = request.GET['code'] qty = int(request.GET['qty']) #check product is available to add to cart product = check_product(conn, code) if product: #check if this product exist product_line = conn.SaleOrderLine.filter(order_id=order.id, product_id=product.id) product = conn.ProductProduct.get(product.id) partner = conn.ResPartner.get(partner_id) if len(product_line) > 0: #product line exist -> update order_line = conn.SaleOrderLine.get(product_line[0].id) order_line.product_uom_qty = qty + product_line[ 0].product_uom_qty order_line.save() else: #product line not exist -> create if partner.property_product_pricelist: pricelist = partner.property_product_pricelist.id else: shop = conn.SaleShop.get(OERP_SALE) pricelist = shop.pricelist_id.id values = [ [order.id], #ids pricelist, #pricelist product.id, #product qty, #qty False, #uom 0, #qty_uos False, #uos '', #name partner_id, #partner_id ] try: product_id_change = conn_webservice( 'sale.order.line', 'product_id_change', values) except Exception, e: logging.error( "Error creating/modifying the order.\nValues: %s\nException: %s" % (str(values), str(e))) values = { 'title': _('Checkout Error'), 'error': _("Error creating/modifying the order. Try again, or contact with us." ), } return render_to_response( "sale/checkout.html", values, context_instance=RequestContext(request)) sale_order_add_product = True not_enought_stock = None if product_id_change['warning'] and SALE_ORDER_PRODUCT_CHECK: if SALE_ORDER_PRODUCE_PRODUCT_CHECK or product.supply_method != 'produce': not_enought_stock = _('Not enough stock !') sale_order_add_product = False if sale_order_add_product: product_value = product_id_change['value'] order_line = conn.SaleOrderLine.new() order_line.order_id = order order_line.name = product_value['name'] if 'notes' in product_value: order_line.notes = product_value['notes'] order_line.product_id = product order_line.product_uom_qty = qty order_line.product_uom = product.product_tmpl_id.uom_id order_line.delay = product_value['delay'] order_line.th_weight = product_value['th_weight'] order_line.type = product_value['type'] order_line.price_unit = product_value['price_unit'] if 'discount' in product_value: order_line.discount = product_value['discount'] order_line.purchase_price = product_value['purchase_price'] order_line.tax_id = [ conn.AccountTax.get(t_id) for t_id in product_value['tax_id'] ] order_line.product_packaging = '' order_line.save() else: message = product_id_change['warning'] if message and 'title' in message: if not_enought_stock != None: message = not_enought_stock else: message = message['title'] #recalcule order (refresh amount) order = check_order(conn, partner_id, OERP_SALE)
def cancel(request, order): """ Order. Cancel Order """ partner_id = checkPartnerID(request) if not partner_id: error = _( 'Are you a customer? Please, contact us. We will create a new role.' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _( 'Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) values = conn.SaleOrder.filter(partner_id=partner_id, name=order, shop_id__in=OERP_SALES) if len(values) == 0: error = _( 'It is not allowed to view this section or not found. Use navigation menu.' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) value = values[0] if value.state != 'draft': error = _( 'Your order is in progress and it is not possible to cancel. Contact with us' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) #cancel order try: cancel = conn_webservice('sale.order', 'action_cancel', [[value.id]]) except: error = _( 'An error is getting when cancel this order. Try again or contact us' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) #drop session if exists if 'sale_order' in request.session: if request.session['sale_order'] == value.name: del request.session['sale_order'] value = conn.SaleOrder.get(value.id) #reload sale order values title = _(u'Order %s cancelled') % (value.name) metadescription = _(u'Order %s cancelled') % (value.name) return render_to_response("sale/order.html", { 'title': title, 'metadescription': metadescription, 'value': value, }, context_instance=RequestContext(request))
def checkout_confirm(request): """ Checkout. Confirm """ context_instance = RequestContext(request) if 'sale_order' in request.session: return HttpResponseRedirect( "%s/sale/order/%s" % (context_instance['LOCALE_URI'], request.session['sale_order'])) if request.method == 'POST': partner_id = checkPartnerID(request) if not partner_id: error = _( 'Are you a customer? Please, contact us. We will create a new role.' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _( 'Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) partner = conn.ResPartner.get(partner_id) order = check_order(conn, partner_id, OERP_SALE) if order.state != 'draft': return HttpResponseRedirect("%s/sale/" % (context_instance['LOCALE_URI'])) delivery = request.POST['delivery'] or False payment = request.POST['payment'] or False address_invoice = request.POST['address_invoice'] or False address_delivery = request.POST['address_delivery'] or False #delivery if delivery: delivery = delivery.split('|') carrier = conn.DeliveryCarrier.filter(code=delivery[0]) price_unit = float(re.sub(',', '.', delivery[1])) if len(carrier) == 0: return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI'])) carrier = carrier[0] if partner.property_product_pricelist: pricelist = partner.property_product_pricelist.id else: shop = conn.SaleShop.get(OERP_SALE) pricelist = shop.pricelist_id.id if price_unit != 0.0: # Add delivery product in the order # if not free of charge values = [ [order.id], #ids pricelist, #pricelist carrier.product_id.id, #product 1, #qty False, #uom 0, #qty_uos False, #uos '', #name partner.id, #partner_id ] product_id_change = conn_webservice('sale.order.line', 'product_id_change', values) order_line = conn.SaleOrderLine.new() order_line.order_id = order order_line.name = carrier.product_id.name order_line.product_id = carrier.product_id order_line.product_uom_qty = 1 order_line.product_uom = carrier.product_id.product_tmpl_id.uom_id order_line.delay = product_value['delay'] order_line.th_weight = product_value['th_weight'] order_line.type = product_value['type'] order_line.price_unit = price_unit order_line.tax_id = [ conn.AccountTax.get(t_id) for t_id in product_value['tax_id'] ] order_line.product_packaging = '' order_line.save() #delivery order.carrier_id = carrier #payment type payment_type = conn.ZoookSaleShopPaymentType.filter( app_payment=payment) if len(payment_type) > 0: if payment_type[0].commission: #add new order line payment = conn_webservice('zoook.sale.shop.payment.type', 'set_payment_commission', [order.id, payment]) order.payment_type = payment_type[0].payment_type_id order.picking_policy = payment_type[0].picking_policy order.order_policy = payment_type[0].order_policy order.invoice_quantity = payment_type[0].invoice_quantity else: return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI'])) #Replace invoice address and delivery address if address_invoice: #add new invoice address if address_invoice == 'add_invoice': address = conn.ResPartnerAddress.new() address.name = request.POST['invoice_name'] address.partner_id = conn.ResPartner.get(partner_id) address.type = 'invoice' address.street = request.POST['invoice_street'] address.zip = request.POST['invoice_zip'] address.city = request.POST['invoice_city'] countries = ResCountry.objects.filter( code=request.POST['invoice_country_code']) if len(countries) > 0: country = countries[0].id address.country_id = conn.ResCountry.get(country) if request.user.email: address.email = request.user.email address.phone = request.POST['invoice_phone'] address_invoice = address.save() address_invoice = conn.ResPartnerAddress.get(int(address_invoice)) if address_invoice: order.partner_invoice_id = address_invoice else: return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI'])) if address_delivery: #add new delivery address if address_delivery == 'add_delivery': address = conn.ResPartnerAddress.new() address.name = request.POST['delivery_name'] address.partner_id = conn.ResPartner.get(partner_id) address.type = 'delivery' address.street = request.POST['delivery_street'] address.zip = request.POST['delivery_zip'] address.city = request.POST['delivery_city'] countries = ResCountry.objects.filter( code=request.POST['delivery_country_code']) if len(countries) > 0: country = countries[0].id address.country_id = conn.ResCountry.get(country) if request.user.email: address.email = request.user.email address.phone = request.POST['delivery_phone'] address_delivery = address.save() address_delivery = conn.ResPartnerAddress.get( int(address_delivery)) if address_delivery: order.partner_shipping_id = address_delivery else: return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI'])) #cupon code / promotion code_promotion = request.POST['promotion'] if code_promotion: order.coupon_code = code_promotion #payment state order.payment_state = 'checking' order.save() #apply cupon code / promotion if code_promotion: promotion = conn_webservice('promos.rules', 'apply_promotions', [order.id]) logging.info('[%s] %s' % (time.strftime('%Y-%m-%d %H:%M:%S'), 'Apply promotion %s Order %s' % (code_promotion, order.name))) logging.info( '[%s] %s' % (time.strftime('%Y-%m-%d %H:%M:%S'), 'Payment %s Order %s' % (payment_type[0].app_payment, order.name))) request.session['sale_order'] = order.name return HttpResponseRedirect( "%s/payment/%s/" % (context_instance['LOCALE_URI'], payment_type[0].app_payment)) else: return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI']))
def wishlist(request): """ Wishlist Favourites products customer """ partner_id = checkPartnerID(request) if not partner_id: error = _( 'Are you a customer? Please, contact us. We will create a new role.' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) full_name = checkFullName(request) conn = connOOOP() if not conn: error = _( 'Error when connecting with our ERP. Try again or cantact us.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) prod_wishlist = False partner = conn.ResPartner.get(partner_id) product_obj = partner.product_wishlist_ids path = request.path_info.split('/') if 'remove' in path: kwargs = { 'slug_' + get_language(): path[-1], #slug is unique } tplproduct = ProductTemplate.objects.filter(**kwargs) if tplproduct.count() > 0: try: for prod in product_obj: if prod.id == tplproduct[ 0].id: #exist this product wishlist prod_wishlist = conn_webservice( 'res.partner', 'write', [[partner_id], { 'product_wishlist_ids': [(3, tplproduct[0].id)] }]) except: prod_wishlist = True if 'add' in path: kwargs = { 'slug_' + get_language(): path[-1], #slug is unique } tplproduct = ProductTemplate.objects.filter(**kwargs) if tplproduct.count() > 0: check_add = False if product_obj: for prod in product_obj: if prod.id == tplproduct[ 0].id: #exist this product wishlist check_add = True if not check_add: prod_wishlist = conn_webservice( 'res.partner', 'write', [[partner_id], { 'product_wishlist_ids': [(4, tplproduct[0].id)] }]) title = _(u'Whislist') metadescription = _(u'Whislist of %s') % full_name if prod_wishlist: partner = conn.ResPartner.get( partner_id) #refresh product_wishlist_ids if add or remove product_obj = partner.product_wishlist_ids products = [] if product_obj: for prod in product_obj: prods = ProductProduct.objects.filter( product_tmpl=prod.id).order_by('price') tplproduct = ProductTemplate.objects.get(id=prod.id) i = 0 prod_images = [] while i < len(prods) and len(prod_images) == 0: prod_images = ProductImages.objects.filter(product=prods[i].id, base_image=True) i += 1 base_image = False if prod_images.count() > 0: base_image = prod_images[0] products.append({ 'product': tplproduct, 'name': tplproduct.name, 'products': prods, 'base_image': base_image }) return render_to_response("catalog/wishlist.html", { 'title': title, 'metadescription': metadescription, 'products': products, 'currency': DEFAULT_CURRENCY, 'currency_position': CURRENCY_LABEL_POSITION, 'update_price': UPDATE_PRICE }, context_instance=RequestContext(request))