def create_default_service(user, org): from apps.website.views import getGlobalVar actarium_customer = ActariumCustomers.objects.get_or_none(user=user) if actarium_customer: customer = actarium_customer.customer else: address = Addresses.objects.create(country="", province="", city="") payment_method = PaymentMethods.objects.get_or_none(code="P001") if payment_method == None: return False, _(u"No se encontro el metodo de pago") customer = Customers.objects.create(name=user.get_full_name(), email=user.email, address=address) customer.payment_methods.add(payment_method) ActariumCustomers.objects.create(user=user, customer=customer) order_status = OrderStatus.objects.get_or_none(code="002", is_active=True) if order_status == None: return False, _(u"No existe estado de orden con el codigo 002") # Default Service FREE_SERVICE = getGlobalVar("FREE_SERVICE") service = Services.objects.get_or_none(code=FREE_SERVICE) if service == None: return False, _(u"No existe un servicio con el codigo proporcionado") customer_order = CustomerOrders.objects.create(customer=customer, status=order_status) import datetime from apps.website.views import getGlobalVar number_of_periods = int(getGlobalVar('TRIAL_MONTH')) number_of_members = int(getGlobalVar('TRIAL_MEMBERS')) date_expiration = datetime.date.today() + datetime.timedelta( number_of_periods * 30, 0, 0) customer_service = CustomersServices.objects.create( quantity=number_of_members, date_expiration=date_expiration) OrderItems(service=service, order=customer_order, order_quantity=number_of_members, number_of_periods=number_of_periods, customer_service=customer_service, discount=0).save() try: OrganizationServices(organization=org, service=customer_service).save() except: return False, _( u"Error al intentar relacionar una organizacion con un servicio") return True, _(u"Se ha creado el servicio por defecto correctamente")
def __init__(self, *args, **kwargs): user_customer = kwargs.pop('user_customer',None) super(OrderMembersServiceForm, self).__init__(*args, **kwargs) if user_customer: self.fields['payment_method'].queryset = user_customer.actariumcustomers_user.all()[0].customer.payment_methods.all() from apps.website.views import getGlobalVar FREE_PACKAGE_ID = getGlobalVar("FREE_PACKAGE_ID") queryset_packages = Packages.objects.filter(is_active = True).exclude(id=FREE_PACKAGE_ID) self.fields['packages'] = forms.ModelChoiceField(label=_(u"Paquete"), queryset=queryset_packages, empty_label=None)
def createOrg(request): from actarium_apps.core.forms import PackagesForm from actarium_apps.core.models import Packages saveViewsLog(request, "apps.groups_app.views_groups.createOrg") ref = request.GET.get('ref') if 'ref' in request.GET else "" if request.method == "POST": package_form = PackagesForm(1, request.POST) form = OrganizationForm(request.POST, request.FILES) if form.is_valid() and form.is_multipart(): org = form.save() org.set_role(request.user, is_admin=True, is_member=True, is_creator=True) is_created, response = create_default_service(request.user, org) saveActionLog(request.user, 'NEW_ORG', "name: %s" % (org.name), request.META['REMOTE_ADDR']) if package_form.is_valid(): pf = package_form.cleaned_data['packages'] if pf.code == "5": return HttpResponseRedirect(org.get_absolute_url()) else: return HttpResponseRedirect( reverse("services:read_pricing", args=(org.slug, )) + "?id_package=" + str(pf.id)) else: id_package = request.GET.get("id_package") form = OrganizationForm() package_form = PackagesForm(1, initial={'packages': id_package}) TRIAL_MEMBERS = getGlobalVar("TRIAL_MEMBERS") TRIAL_MONTH = getGlobalVar("TRIAL_MONTH") return render(request, "organizations/create_org.html", locals())
def approve_order(request): # if request.is_ajax(): if request.user.is_staff: if request.method == "POST": order_id = request.POST.get('order_id') order_item = OrderItems.objects.get_or_none(id=order_id) if order_item: status_approve = OrderStatus.objects.get(code="002") status_defeated = OrderStatus.objects.get(code="006") last_order = order_item.customer_service.get_order_active() from apps.website.views import getGlobalVar FREE_SERVICE = getGlobalVar("FREE_SERVICE") if last_order.service.code==FREE_SERVICE: new_order = order_item if last_order: last_customer_order = last_order.order last_customer_order.status = status_defeated last_customer_order.save() new_customer_order = new_order.order new_customer_order.status = status_approve new_customer_order.save() customer_service = order_item.customer_service customer_service.quantity = new_order.order_quantity number_of_periods = new_order.number_of_periods date_expiration = datetime.date.today() + datetime.timedelta(number_of_periods*30,0,0) customer_service.date_expiration = date_expiration customer_service.save() message = {'is_done':True,'response':_("Modificado Correctamente")} else: message = {'Error': _(u"Opción no implementada, únicamente se puede actualizar la version trial" )} else: message = {'Error': _( "No hay orden disponible" )} else: message = {'Error': _( u"No tiene permiso para realizar esta acción" )} return HttpResponse(json.dumps(message), mimetype="application/json")
def get_global_var(p, name): print "p", p print "NOMBRE:", name return getGlobalVar(name) # register.filter('global_var', get_global_var)
def gloval_vars_url(request): from apps.website.views import getGlobalVar return {"URL_PRIVACY": getGlobalVar("URL_PRIVACY"), "URL_TERMS": getGlobalVar("URL_TERMS")}
from django.conf.urls import url, patterns from apps.website.views import getGlobalVar urlpatterns = patterns( 'apps.website.views', url(r'^$', 'home', name='home'), url(r'^tour$', 'home', name='tour'), url(r'^help/faq$', 'help', name="help"), url(r'^feed-back', 'sendFeedBack', name="send_feedback"), url(r'^' + getGlobalVar("URL_PRIVACY") + '$', 'privacy_', name="privacy"), url(r'^' + getGlobalVar("URL_TERMS") + '$', 'terms', name="terms"), url(r'^services.pdf$', 'services', name='services'), url(r'^como-funciona$', 'how_it_works', name='how_it_works'), url(r'^features.pdf$', 'services', name='features'), url(r'^about$', 'benefits', name='benefits'), url(r'^about', 'about', name="about"), url(r'^pricing', 'pricing', name="pricing"), url(r'^blog', 'blog', name="blog"), url(r'^landing', 'landing', name="landing"), url(r'^users', 'users', name="users"), url(r'^fixtures', 'get_initial_data', name="landing"), url(r'^quiero-la-plantilla-de-mi-empresa', 'send_template', name="send_template"), )
def read_pricing(request, slug_org): from apps.website.views import getGlobalVar if slug_org: org = request.user.organizationsuser_user.get_org(slug=slug_org) if org and org.has_user_role(request.user, 'is_creator'): is_creator = True id_package = request.GET.get("id_package") if id_package: show_modal = True FREE_PACKAGE_ID = getGlobalVar("FREE_PACKAGE_ID") packages = Packages.objects.get_all_active().order_by('code').exclude( id=FREE_PACKAGE_ID) services_list = Services.objects.filter( service_category__code="C001", is_active=True).order_by("-price_per_period") services_categories = ServicesCategories.objects.filter(is_active=True) if request.method == "POST": order_members_form = OrderMembersServiceForm( request.POST, user_customer=request.user) if order_members_form.is_valid(): payment_method = order_members_form.cleaned_data[ 'payment_method'] if payment_method.id == 1: package = order_members_form.cleaned_data['packages'] number_of_members = package.number_of_members number_of_months = order_members_form.cleaned_data[ 'number_of_months'] discount_code = order_members_form.cleaned_data['discount'] customer_services = org.organizationservices_organization.get_members_service_active( ) service = ServicesRanges.objects.get_service( number_of_members) discount_value_obj = DiscountCodes.objects.get_or_none( code=discount_code, is_active=True) discount_value = discount_value_obj.value if discount_value_obj else 0 if int(number_of_months) >= 12: base = float( number_of_members) * service.price_per_period base = base * float(number_of_months) discount_value = discount_value + base * 0.05 order_id, message = OrderItems.objects.create_members_order( number_of_members=number_of_members, number_of_months=number_of_months, customer_services=customer_services, service=service, discount_value=discount_value, user=request.user) if order_id: if discount_value_obj: discount_value_obj.is_active = False discount_value_obj.save() return HttpResponseRedirect( reverse("core:read_organization_services", args=(org.slug, )) + "?order=" + str(order_id)) else: error = message else: error = _(u"El método de pago seleccionado no existe") else: show_modal = True else: order_members_form = OrderMembersServiceForm( initial={ "organization": org.id, "payment_method": '1', "packages": id_package, "number_of_months": 12 }, user_customer=request.user) return render(request, 'pricing.html', locals()) raise Http404