def index(request): """ Bank Transfer OpenERP Payment Type App is: banktransfer """ title = _('Payment Bank Transfer') if not 'sale_order' in request.session: error = _('Order number is not available. Use navigation menu.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(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)) payment_type = conn.ZoookSaleShopPaymentType.filter( app_payment='banktransfer') orders = conn.SaleOrder.filter(name=request.session['sale_order']) if (len(payment_type) > 0) and len(orders) > 0: #change payment_type = done order = orders[0] order.payment_state = 'done' order.save() payment_order = conn_webservice('sale.order', 'sale_order_payment', [order.name, 'check']) values = { 'order': request.session['sale_order'], 'payment_type': payment_type[0] } del request.session['sale_order'] #send email sale order mailresult = SaleOrderEmail(order.id) if mailresult: values['error'] = mailresult logging.info('Order %s: check payment finish' % order.name) return render_to_response("banktransfer/banktransfer.html", values, context_instance=RequestContext(request)) else: error = _( 'Error payment this order or is null. Contact Us or use navigation menu' ) return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request))
def pasat4b_confirm(request): """ Confirmation Pasat 4b view """ if not 'sale_order' in request.session: error = _('Order number is not available. Use navigation menu.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) conn = connOOOP() order = request.session['sale_order'] payment_pasat4b = pasat4bResponse.objects.filter(pszPurchorderNum=order) payment = False if len(payment_pasat4b) > 0: if (payment_pasat4b[0].result == 0): #0 -> transaccin autorizada payment = True orders = conn.SaleOrder.filter(name=request.session['sale_order']) if payment and len(orders) > 0: order = orders[0] payment_order = conn_webservice('sale.order', 'sale_order_payment', [order.name, 'pasat4b']) title = _(u'Confirmation Payment Credit Card Pasat 4b') values = {'order': request.session['sale_order'], 'title': title} del request.session['sale_order'] #send email sale order SaleOrderEmail(order.id) logging.info(_('Order %s: Pasat 4b payment finish') % order.name) return HttpResponse( render_to_response('pasat4b/confirm.html', values, context_instance=RequestContext(request))) else: error = _( 'Error return 4b (Pasat Internet 4b) Payment. Contact us to check payment' ) return HttpResponse( render_to_response('pasat4b/error.html', {'error': error}, 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 update_prices(request, product_ids): partner_id = request.user.get_profile().partner_id if request.user.user_profile_s.count() > 0 else False data = '' if partner_id: products = [] for product in product_ids: try: product = int(product) products.append({'product_id':int(product),'quantity':1}) except: pass # values => {"1":{"regularPrice":"50"},"2":{"regularPrice":"100"}} values = conn_webservice('product.product','zoook_compute_price', [OERP_SALE, products, partner_id]) for k in values.keys(): values[k]['regularPrice'] = money_format(values[k]['regularPrice']) data = json.dumps(values) return data
def sermepa_confirm(request): """ Confirmation Sermepa view """ title = _(u'Confirmation Credit Card Servired') conn = connOOOP() order = request.session['sale_order'] #TODO: check real IPN and test this code payment_sermepa = SermepaResponse.objects.filter(Ds_Order=order) payment = False if len(payment_sermepa) > 0: if (payment_sermepa[0].Ds_Signature): payment = True orders = conn.SaleOrder.filter(name=request.session['sale_order']) if payment and len(orders) > 0: order = orders[0] payment_order = conn_webservice('sale.order', 'sale_order_payment', [order.name, 'sermepa']) values = {'order': request.session['sale_order']} del request.session['sale_order'] #send email sale order SaleOrderEmail(order.id) logging.info(_('Order %s: servired payment finish') % order.name) return HttpResponse( render_to_response('sermepa/confirm.html', values, context_instance=RequestContext(request))) else: error = _('Error return Servired Payment. Contact us to check payment') return HttpResponse( render_to_response('sermepa/error.html', {'error': error}, context_instance=RequestContext(request)))
def index(request): """ Cashondelivery OpenERP Payment Type App is: cashondelivery """ title = _(u'Payment Cash On Delivery') if not 'sale_order' in request.session: error = _('Order number is not available. Use navigation menu.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(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)) payment_type = conn.ZoookSaleShopPaymentType.filter(app_payment='cashondelivery') orders = conn.SaleOrder.filter(name=request.session['sale_order']) if (len(payment_type) > 0) and len(orders) > 0: #change payment_type = done order = orders[0] order.payment_state = 'done' order.save() payment_order = conn_webservice('sale.order', 'sale_order_payment', [order.name, 'cashondelivery']) values = {'order':request.session['sale_order'],'payment_type':payment_type[0]} del request.session['sale_order'] #send email sale order mailresult = SaleOrderEmail(order.id) if mailresult: values['error'] = mailresult logging.info('Order %s: cashondelivery payment finish' % order.name) return render_to_response("cashondelivery/cashondelivery.html", values, context_instance=RequestContext(request)) else: error = _('Error payment this order or is null. Contact Us or use navigation menu') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request))
def SaleOrderEmail(order): """ Send email Order order Int (ID) Return True/False """ conn = connOOOP() shop = conn.SaleShop.get(OERP_SALE) context = {} context['active_id'] = shop.email_sale_order.id values = [ [], #ids order, #rel_model_ref context, #context ] body_template = conn_webservice('poweremail.preview','on_change_ref', values) customer_email = body_template['value']['to'] bcc=None if body_template['value']['bcc'] and body_template['value']['bcc'] != 'False': bcc = [body_template['value']['bcc']] if customer_email != 'False': subject = body_template['value']['subject'] if body_template['value']['body_html']: body = body_template['value']['body_html'] else: body = body_template['value']['body_text'] email = EmailMessage(subject, body, EMAIL_FROM, to=[customer_email], bcc=bcc, headers = {'Reply-To': EMAIL_REPPLY}) if body_template['value']['body_html']: email.content_subtype = "html" try: email.send() return None except Exception, e: logging.warn('SaleOrderEmail: Order ID %s - Error sending email: %s' % (order, str(e))) error = _("Your order is in process but we don't send email. Check in your order customer section.") return error
def pasat4b_confirm(request): """ Confirmation Pasat 4b view """ if not 'sale_order' in request.session: error = _('Order number is not available. Use navigation menu.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(request)) conn = connOOOP() order = request.session['sale_order'] payment_pasat4b = pasat4bResponse.objects.filter(pszPurchorderNum=order) payment = False if len(payment_pasat4b) > 0: if (payment_pasat4b[0].result == 0): #0 -> transaccin autorizada payment = True orders = conn.SaleOrder.filter(name=request.session['sale_order']) if payment and len(orders) > 0: order = orders[0] payment_order = conn_webservice('sale.order', 'sale_order_payment', [order.name, 'pasat4b']) title = _(u'Confirmation Payment Credit Card Pasat 4b') values = {'order':request.session['sale_order'], 'title':title} del request.session['sale_order'] #send email sale order SaleOrderEmail(order.id) logging.info(_('Order %s: Pasat 4b payment finish') % order.name) return HttpResponse(render_to_response('pasat4b/confirm.html', values, context_instance=RequestContext(request))) else: error = _('Error return 4b (Pasat Internet 4b) Payment. Contact us to check payment') return HttpResponse(render_to_response('pasat4b/error.html', {'error':error}, context_instance=RequestContext(request)))
def sermepa_confirm(request): """ Confirmation Sermepa view """ title = _(u'Confirmation Credit Card Servired') conn = connOOOP() order = request.session['sale_order'] #TODO: check real IPN and test this code payment_sermepa = SermepaResponse.objects.filter(Ds_Order=order) payment = False if len(payment_sermepa)>0: if (payment_sermepa[0].Ds_Signature): payment = True orders = conn.SaleOrder.filter(name=request.session['sale_order']) if payment and len(orders) > 0: order = orders[0] payment_order = conn_webservice('sale.order', 'sale_order_payment', [order.name, 'sermepa']) values = {'order':request.session['sale_order']} del request.session['sale_order'] #send email sale order SaleOrderEmail(order.id) logging.info(_('Order %s: servired payment finish') % order.name) return HttpResponse(render_to_response('sermepa/confirm.html', values, context_instance=RequestContext(request))) else: error = _('Error return Servired Payment. Contact us to check payment') return HttpResponse(render_to_response('sermepa/error.html', {'error':error}, context_instance=RequestContext(request)))
def update_prices(request, product_ids): partner_id = request.user.get_profile( ).partner_id if request.user.user_profile_s.count() > 0 else False data = '' if partner_id: products = [] for product in product_ids: try: product = int(product) products.append({ 'product_id': int(product), 'quantity': 1 }) except: pass # values => {"1":{"regularPrice":"50"},"2":{"regularPrice":"100"}} values = conn_webservice('product.product', 'zoook_compute_price', [OERP_SALE, products, partner_id]) for k in values.keys(): values[k]['regularPrice'] = money_format( values[k]['regularPrice']) data = json.dumps(values) return data
def paypal_confirm(request): """ Confirmation Paypal view """ title = _(u'Confirm Payment Paypal') conn = connOOOP() order = request.session['sale_order'] #TODO: check real IPN and test this code payment_paypal = PayPalIPN.objects.filter(invoice=order) payment = False if len(payment_paypal)>0: if (payment_paypal[0].verify_sign): payment = True orders = conn.SaleOrder.filter(name=request.session['sale_order']) if payment and len(orders) > 0: order = orders[0] payment_order = conn_webservice('sale.order', 'sale_order_payment', [order.name, 'paypal']) values = {'order':request.session['sale_order']} del request.session['sale_order'] #send email sale order SaleOrderEmail(order.id) logging.info('Order %s: paypal payment finish' % (order.name)) return HttpResponse(render_to_response('paypal/confirm.html', values, context_instance=RequestContext(request))) else: error = _('Error return Paypal Payment. Contact us to check payment') return HttpResponse(render_to_response('paypal/error.html', {'error':error}, context_instance=RequestContext(request)))
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_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 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))
from config_path import zoook_root sys.path.insert(0, zoook_root) os.environ['DJANGO_SETTINGS_MODULE'] = 'django_zoook.settings' import django_zoook.logconfig from django_zoook.settings import * from django.utils.translation import ugettext as _ from django_zoook.catalog.models import ProductCategory from django_zoook.tools.conn import conn_webservice from django.core.exceptions import ObjectDoesNotExist logging.info(_('Sync. Categories. Running')) results = conn_webservice('sale.shop', 'dj_export_categories', [[OERP_SALE]]) langs = conn_webservice('sale.shop', 'zoook_sale_shop_langs', [[OERP_SALE]]) langs = langs[str(OERP_SALE)] context = {} django_product_category_fields = [ field.name for field in ProductCategory._meta.fields ] if len(results) == 0: logging.info(_('Sync. Categories. Not categories news or modified')) cat2 = [] for result in results: # minicalls with one id (step to step) because it's possible return a big dicctionay and broken memory.
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 register(request): """Registration page. If exists session, redirect profile""" context_instance=RequestContext(request) if request.user.is_authenticated(): #redirect profile return HttpResponseRedirect("%s/partner/profile/" % context_instance['LOCALE_URI']) site_configuration = siteConfiguration(SITE_ID) title = _(u'Create an Account') metadescription = _(u'Create an Account of %(site)s') % {'site':site_configuration.site_title} partner_vat_required = PARTNER_VAT_REQUIRED country_default = COUNTRY_DEFAULT title_default = '' if request.method == "POST": message = [] users = '' emails = '' error = [] country = False form = UserCreationForm(request.POST) data = request.POST.copy() username = data['username'] email = data['email'] password = data['password1'] name = data['name'] vat_code = data['vat_code'] country_default = vat_code title = data['title'] title_default = title vat = data['vat'] street = data['street'] zip = data['zip'] city = data['city'] phone = data['phone'] #mobile = data['mobile'] same_address = 'delivery-same-address' in data if not same_address: delivery_street = data['delivery_street'] delivery_zip = data['delivery_zip'] delivery_city = data['delivery_city'] delivery_phone = data['delivery_phone'] #delivery_mobile = data['delivery_mobile'] countries = ResCountry.objects.filter(code=vat_code) if len(countries)>0: country = countries[0].id if (data['password1'] == data['password2']) and country: if form.is_valid(): if len(username) < USER_LENGHT: msg = _('Username is short. Minimum %(size)s characters') % {'size': USER_LENGHT} message.append(msg) if len(password) < KEY_LENGHT: msg = _('Password is short. Minimum %(size)s characters') % {'size': KEY_LENGHT} message.append(msg) if is_valid_email(email): # check if user not exist users = User.objects.filter(username__exact=username) emails = User.objects.filter(email__exact=email) else: msg = _('Sorry. The email is not valid. Try again.') message.append(msg) if RECAPTCHA_PUB_KEY != '': check_captcha = captcha.submit(request.POST['recaptcha_challenge_field'], request.POST['recaptcha_response_field'], RECAPTCHA_PRIVATE_KEY, request.META['REMOTE_ADDR']) if check_captcha.is_valid is False: # captcha not valid msg = _('Error with captcha number. Copy same number.') message.append(msg) if users: msg = _('Sorry. This user already exists. Use another username.') message.append(msg) if emails: msg = _('Sorry. This email already exists. Use another email or remember password.') message.append(msg) #check if this vat exists ERP if not message: 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)) if partner_vat_required or vat: partner = conn.ResPartner.filter(vat__ilike = vat_code+vat) if len(partner) > 0: msg = _('Sorry. This VAT already exists our ERP. Contact Us for create a new user.') message.append(msg) #check if this vat valid if not message and (partner_vat_required or vat): checkvat = vat_code + vat checkvat = checkvat.upper() check_vat = conn_webservice('res.partner', 'dj_check_vat', [checkvat, OERP_SALE]) if not check_vat: msg = _('Vat not valid. Check if vat is correct') message.append(msg) #create new partner and user if len(message) == 0: # create partner partner = conn.ResPartner.new() partner.name = name if vat: partner.vat = checkvat partner.dj_username = username partner.dj_email = email if title: res_partner_title = conn.ResPartnerTitle.get(int(title)) partner.title = res_partner_title if res_partner_title.default_pricelist_id: partner.property_product_pricelist = res_partner_title.default_pricelist_id partner_id = partner.save() # Create contact invoice address partner address = conn.ResPartnerAddress.new() address.name = name address.partner_id = conn.ResPartner.get(partner_id) address.street = street address.zip = zip address.city = city address.phone = phone #address.mobile = mobile address.country_id = conn.ResCountry.get(country) address.email = email if not same_address: address.type = 'invoice' else: address.type = 'default' address_id = address.save() if not same_address: # Create contact delivery address partner address = conn.ResPartnerAddress.new() address.name = name address.partner_id = conn.ResPartner.get(partner_id) address.street = delivery_street address.zip = delivery_zip address.city = delivery_city address.phone = delivery_phone #address.mobile = delivery_mobile address.country_id = conn.ResCountry.get(country) address.email = email address.type = 'delivery' address_id = address.save() # create user # split name: first_name + last name if len(name.split(' ')) > 1: name = name.split(' ') first_name = name[0] del name[0] last_name = ' '.join(name) else: first_name = name last_name = '' user = User.objects.create_user(username, email, password) user.first_name = first_name user.last_name = last_name user.is_staff = False user.save() # create authProfile authProfile = AuthProfile(user=user,partner_id=partner_id) authProfile.save() try: # send email subject = _('New user is added - %(name)s') % {'name':site_configuration.site_title} body = _("This email is generated automatically from %(site)s\n\nUsername: %(username)s\nPassword: %(password)s\n\n%(live_url)s\n\nPlease, don't answer this email") % {'site':site_configuration.site_title,'username':username,'password':password,'live_url':get_live_url(request)} emailobj = EmailMessage(subject, body, to=[email]) emailobj.send() finally: # authentification / login user user = authenticate(username=username, password=password) auth_login(request, user) if 'redirect' in request.POST: redirect = base64.b64decode(request.POST['redirect']) return HttpResponseRedirect(redirect) return HttpResponseRedirect("%s/partner/profile/" % context_instance['LOCALE_URI']) else: for field in form: for error in field.errors: message.append(error) else: msg = _("Sorry. Passwords do not match. Try again.") message.append(msg) form = UserCreationForm() if RECAPTCHA_PUB_KEY != '': html_captcha = captcha.displayhtml(RECAPTCHA_PUB_KEY) if request.POST.get('redirect'): redirect = request.POST.get('redirect') if request.GET.get('next'): if request.GET.get('qty'): redirect = base64.b64encode(request.GET.get('next') + '&qty=' + request.GET.get('qty')) else: redirect = base64.b64encode(request.GET.get('next')) countries = ResCountry.objects.all() titles = ResPartnerTitle.objects.all() return render_to_response("partner/register.html", locals(), context_instance=RequestContext(request))
import django_zoook.logconfig from django_zoook.settings import * from django.utils.translation import ugettext as _ from django_zoook.catalog.models import ProductProduct, ProductTemplate, ResManufacturer from django_zoook.tools.conn import conn_webservice logging.info(_('Sync. Products. Running')) """ for product.template for product.product if product.attributes """ results = conn_webservice('sale.shop', 'dj_export_products', [[OERP_SALE]]) langs = conn_webservice('sale.shop', 'zoook_sale_shop_langs', [[OERP_SALE]]) langs = langs[str(OERP_SALE)] context = {} django_product_template_fields = [field.name for field in ProductTemplate._meta.fields] django_product_product_fields = [field.name for field in ProductProduct._meta.fields] if len(results) == 0: logging.info(_('Sync. Products Template. Not products template news or modified')) for result in results: # minicalls with one id (step to step) because it's possible return a big dicctionay and broken memory. try: values = conn_webservice('base.external.mapping', 'get_oerp_to_external', ['zoook.product.template',[result['product_template']],context,langs]) except Exception, e:
import django_zoook.logconfig from django_zoook.settings import * from django.utils.translation import ugettext as _ from django_zoook.catalog.models import ProductProduct, ProductTemplate, ResManufacturer from django_zoook.tools.conn import conn_webservice logging.info(_('Sync. Products. Running')) """ for product.template for product.product if product.attributes """ results = conn_webservice('sale.shop', 'dj_export_products', [[OERP_SALE]]) langs = conn_webservice('sale.shop', 'zoook_sale_shop_langs', [[OERP_SALE]]) langs = langs[str(OERP_SALE)] context = {} django_product_template_fields = [ field.name for field in ProductTemplate._meta.fields ] django_product_product_fields = [ field.name for field in ProductProduct._meta.fields ] if len(results) == 0: logging.info( _('Sync. Products Template. Not products template news or modified'))
parser = optparse.OptionParser(usage) parser.add_option("-r", "--resource", dest="resources", default=False, help="Get product list.") options, args = parser.parse_args() """Get Attachment to import at Django""" resources = [] if options.resources: resources = options.resources.split(',') conn = connOOOP() if not conn: logging.error(_('Error connecting to ERP')) results = conn_webservice('sale.shop', 'dj_export_attachments', [[OERP_SALE], resources]) logging.info('Total: %s' % len(results)) if len(results) == 0: logging.info(_('Sync. Not resources news or modified')) for res in results: result = conn.IrAttachment.get(res) values = { 'id': result.id, 'name': result.name, 'description': result.description and result.description or '', 'res_name': result.res_name, 'res_model': result.res_model, 'res_id': result.res_id,
def register(request): """Registration page. If exists session, redirect profile""" context_instance = RequestContext(request) if request.user.is_authenticated(): #redirect profile return HttpResponseRedirect("%s/partner/profile/" % context_instance['LOCALE_URI']) site_configuration = siteConfiguration(SITE_ID) title = _(u'Create an Account') metadescription = _(u'Create an Account of %(site)s') % { 'site': site_configuration.site_title } partner_vat_required = PARTNER_VAT_REQUIRED country_default = COUNTRY_DEFAULT title_default = '' if request.method == "POST": message = [] users = '' emails = '' error = [] country = False form = UserCreationForm(request.POST) data = request.POST.copy() username = data['username'] email = data['email'] password = data['password1'] name = data['name'] vat_code = data['vat_code'] country_default = vat_code title = data['title'] title_default = title vat = data['vat'] street = data['street'] zip = data['zip'] city = data['city'] phone = data['phone'] #mobile = data['mobile'] same_address = 'delivery-same-address' in data if not same_address: delivery_street = data['delivery_street'] delivery_zip = data['delivery_zip'] delivery_city = data['delivery_city'] delivery_phone = data['delivery_phone'] #delivery_mobile = data['delivery_mobile'] countries = ResCountry.objects.filter(code=vat_code) if len(countries) > 0: country = countries[0].id if (data['password1'] == data['password2']) and country: if form.is_valid(): if len(username) < USER_LENGHT: msg = _( 'Username is short. Minimum %(size)s characters') % { 'size': USER_LENGHT } message.append(msg) if len(password) < KEY_LENGHT: msg = _( 'Password is short. Minimum %(size)s characters') % { 'size': KEY_LENGHT } message.append(msg) if is_valid_email(email): # check if user not exist users = User.objects.filter(username__exact=username) emails = User.objects.filter(email__exact=email) else: msg = _('Sorry. The email is not valid. Try again.') message.append(msg) if RECAPTCHA_PUB_KEY != '': check_captcha = captcha.submit( request.POST['recaptcha_challenge_field'], request.POST['recaptcha_response_field'], RECAPTCHA_PRIVATE_KEY, request.META['REMOTE_ADDR']) if check_captcha.is_valid is False: # captcha not valid msg = _('Error with captcha number. Copy same number.') message.append(msg) if users: msg = _( 'Sorry. This user already exists. Use another username.' ) message.append(msg) if emails: msg = _( 'Sorry. This email already exists. Use another email or remember password.' ) message.append(msg) #check if this vat exists ERP if not message: 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)) if partner_vat_required or vat: partner = conn.ResPartner.filter(vat__ilike=vat_code + vat) if len(partner) > 0: msg = _( 'Sorry. This VAT already exists our ERP. Contact Us for create a new user.' ) message.append(msg) #check if this vat valid if not message and (partner_vat_required or vat): checkvat = vat_code + vat checkvat = checkvat.upper() check_vat = conn_webservice('res.partner', 'dj_check_vat', [checkvat, OERP_SALE]) if not check_vat: msg = _('Vat not valid. Check if vat is correct') message.append(msg) #create new partner and user if len(message) == 0: # create partner partner = conn.ResPartner.new() partner.name = name if vat: partner.vat = checkvat partner.dj_username = username partner.dj_email = email if title: res_partner_title = conn.ResPartnerTitle.get( int(title)) partner.title = res_partner_title if res_partner_title.default_pricelist_id: partner.property_product_pricelist = res_partner_title.default_pricelist_id partner_id = partner.save() # Create contact invoice address partner address = conn.ResPartnerAddress.new() address.name = name address.partner_id = conn.ResPartner.get(partner_id) address.street = street address.zip = zip address.city = city address.phone = phone #address.mobile = mobile address.country_id = conn.ResCountry.get(country) address.email = email if not same_address: address.type = 'invoice' else: address.type = 'default' address_id = address.save() if not same_address: # Create contact delivery address partner address = conn.ResPartnerAddress.new() address.name = name address.partner_id = conn.ResPartner.get(partner_id) address.street = delivery_street address.zip = delivery_zip address.city = delivery_city address.phone = delivery_phone #address.mobile = delivery_mobile address.country_id = conn.ResCountry.get(country) address.email = email address.type = 'delivery' address_id = address.save() # create user # split name: first_name + last name if len(name.split(' ')) > 1: name = name.split(' ') first_name = name[0] del name[0] last_name = ' '.join(name) else: first_name = name last_name = '' user = User.objects.create_user(username, email, password) user.first_name = first_name user.last_name = last_name user.is_staff = False user.save() # create authProfile authProfile = AuthProfile(user=user, partner_id=partner_id) authProfile.save() try: # send email subject = _('New user is added - %(name)s') % { 'name': site_configuration.site_title } body = _( "This email is generated automatically from %(site)s\n\nUsername: %(username)s\nPassword: %(password)s\n\n%(live_url)s\n\nPlease, don't answer this email" ) % { 'site': site_configuration.site_title, 'username': username, 'password': password, 'live_url': get_live_url(request) } emailobj = EmailMessage(subject, body, to=[email]) emailobj.send() finally: # authentification / login user user = authenticate(username=username, password=password) auth_login(request, user) if 'redirect' in request.POST: redirect = base64.b64decode( request.POST['redirect']) return HttpResponseRedirect(redirect) return HttpResponseRedirect( "%s/partner/profile/" % context_instance['LOCALE_URI']) else: for field in form: for error in field.errors: message.append(error) else: msg = _("Sorry. Passwords do not match. Try again.") message.append(msg) form = UserCreationForm() if RECAPTCHA_PUB_KEY != '': html_captcha = captcha.displayhtml(RECAPTCHA_PUB_KEY) if request.POST.get('redirect'): redirect = request.POST.get('redirect') if request.GET.get('next'): if request.GET.get('qty'): redirect = base64.b64encode( request.GET.get('next') + '&qty=' + request.GET.get('qty')) else: redirect = base64.b64encode(request.GET.get('next')) countries = ResCountry.objects.all() titles = ResPartnerTitle.objects.all() return render_to_response("partner/register.html", locals(), context_instance=RequestContext(request))
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))
metadescription = _(u'Checkout order %s') % (site_configuration.site_title) values = { 'title': title, 'metadescription': metadescription, 'message':message, 'order':order, 'lines': lines, 'currency_position': CURRENCY_LABEL_POSITION, 'show_vat': ORDER_SHOW_VAT, } if len(lines)>0: #delivery try: values['deliveries'] = conn_webservice('sale.order','delivery_cost', [order.id]) delivery = True except: logging.warn('Need configure grid delivery in this shop or delivery grid not available') values['deliveries'] = [] #Address invoice/delivery values['address_invoices'] = conn.ResPartnerAddress.filter(partner_id=partner_id,type='invoice') values['address_deliveries'] = conn.ResPartnerAddress.filter(partner_id=partner_id,type='delivery') sale_shop = conn.SaleShop.filter(id=OERP_SALE)[0] #order payment by sequence payments = [] if sale_shop.zoook_payment_types: payment_commission = False for payment_type in sale_shop.zoook_payment_types:
def confirm(request): """ Debit OpenERP Payment Type App is: debit """ title = _(u'Payment Debit Bank') context_instance=RequestContext(request) if not 'sale_order' in request.session: error = _('Order number is not available. Use navigation menu.') return render_to_response("partner/error.html", locals(), context_instance=RequestContext(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)) payment_type = conn.ZoookSaleShopPaymentType.filter(app_payment='debit') orders = conn.SaleOrder.filter(name=request.session['sale_order']) bank_number = request.POST.get('number', '') if not bank_number: return HttpResponseRedirect("%s/sale/checkout/" % (context_instance['LOCALE_URI'])) if (len(payment_type) > 0) and len(orders) > 0: order = orders[0] partner_banks = conn.ResPartnerBank.filter(acc_number=bank_number,partner_id=order.partner_id.id) #add bank number res_partner_bank if not len(partner_banks)>0: country_id = order.partner_invoice_id.country_id.id bank_code = bank_number[:4] banks = conn.ResBank.filter(country=country_id,code=bank_code) # not bank available if not len(banks)>0: banks = conn.ResBank.all() #get first bank available. TODO: get on_change/country try: res_partner_bank = conn.ResPartnerBank.new() res_partner_bank.acc_number = str(bank_number) res_partner_bank.partner_id = order.partner_id res_partner_bank.bank = banks[0] res_partner_bank.state = 'bank' res_partner_bank.default_bank = 0 res_partner_bank.country_id = '' res_partner_bank.state_id = '' res_partner_bank.save() except: logging.info('[%s] %s' % (time.strftime('%Y-%m-%d %H:%M:%S'), 'Bank Partner error: %s' % (bank_number))) #change payment_type = done order.payment_state = 'done' order.save() payment_order = conn_webservice('sale.order', 'sale_order_payment', [order.name, 'debit']) values = {'order':request.session['sale_order'],'payment_type':payment_type[0]} del request.session['sale_order'] #send email sale order SaleOrderEmail(order.id) logging.info('[%s] %s' % (time.strftime('%Y-%m-%d %H:%M:%S'), 'Order %s: debit payment finish' % (order.name) )) return render_to_response("debit/confirm.html", values, context_instance=RequestContext(request)) else: error = _('Error payment this order or is null. Contact Us or use navigation menu') return render_to_response("partner/error.html", locals(), 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 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)
metadescription = _(u'Checkout order %s') % (site_configuration.site_title) values = { 'title': title, 'metadescription': metadescription, 'message': message, 'order': order, 'lines': lines, 'currency_position': CURRENCY_LABEL_POSITION, 'show_vat': ORDER_SHOW_VAT, } if len(lines) > 0: #delivery try: values['deliveries'] = conn_webservice('sale.order', 'delivery_cost', [order.id]) delivery = True except: logging.warn( 'Need configure grid delivery in this shop or delivery grid not available' ) values['deliveries'] = [] #Address invoice/delivery values['address_invoices'] = conn.ResPartnerAddress.filter( partner_id=partner_id, type__in=['invoice', 'default', False]) values['address_deliveries'] = conn.ResPartnerAddress.filter( partner_id=partner_id, type__in=['delivery', 'default', False]) sale_shop = conn.SaleShop.filter(id=OERP_SALE)[0] #order payment by sequence
from django_zoook.tools.conn import conn_webservice logging.info(_('Sync. Images. Running')) usage = "usage: %prog [options]" parser = optparse.OptionParser(usage) parser.add_option("-p", "--products", dest="products", default=False, help="Get product list.") options, args = parser.parse_args() products = [] if options.products: products = options.products.split(',') results = conn_webservice('sale.shop', 'dj_export_images', [[OERP_SALE], products]) langs = conn_webservice('sale.shop', 'zoook_sale_shop_langs', [[OERP_SALE]]) langs = langs[str(OERP_SALE)] context = {} django_product_images_fields = [field.name for field in ProductImages._meta.fields] if len(results) == 0: logging.info(_('Sync. Images. Not images news or modified')) for result in results: # minicalls with one id (step to step) because it's possible return a big dicctionay and broken memory. try: values = conn_webservice('base.external.mapping', 'get_oerp_to_external', ['zoook.product.images',[result],context,langs]) except Exception, e: logging.error(_('Sync. Images. Error getting image ID %s from OpenERP') % result)
from config_path import zoook_root sys.path.insert(0, zoook_root) os.environ['DJANGO_SETTINGS_MODULE'] = 'django_zoook.settings' import django_zoook.logconfig from django_zoook.settings import * from django.utils.translation import ugettext as _ from django_zoook.base.models import ResCountry, ResCountryState from django_zoook.partner.models import ResPartnerTitle from django_zoook.tools.conn import conn_webservice logging.info(_('Sync. Configuration. Running')) langs = conn_webservice('sale.shop', 'zoook_sale_shop_langs', [[OERP_SALE]]) langs = langs[str(OERP_SALE)] context = {} """ countries / states """ countries = conn_webservice('sale.shop', 'dj_export_countries', [[OERP_SALE]]) for country in countries: # minicalls with one id (step to step) because it's possible return a big dicctionay and broken memory. values = conn_webservice('base.external.mapping', 'get_oerp_to_external', ['zoook.res.country',[country],context,langs]) logging.debug(str(values)) if len(values) > 0: count = values[0]