# main code # Create next invoice if last was paid and organization is not suspension for x in Invoice.objects.filter(end_date=end, status__gt=0, organization__suspension=False): """ contratos - seram avisados um mes antes de vencer - nao gera fatura mensal boleto termina em um mês ou menos """ # non exist if Invoice.objects.filter(end_date=end + relativedelta(months=1), organization=x.organization).count() == 0: i = Invoice() # new invoice i.organization = x.organization i.start_date = end i.end_date = end + relativedelta(months=1) i.payment_type = x.organization.payment_type i.ammount = x.organization.prefered_plan.value i.plan = x.organization.prefered_plan i.status = 0 # pendente i.save() to = [] # send mail to bcc = [] bcc.append("*****@*****.**") """ send mail just to user is_active = True
def register(request, success_url=None, form_class=RegistrationForm, template_name='registration/registration_form.html', extra_context=None): if request.method == 'POST': #the full process of registration is done here form = form_class(data=request.POST) error_found = False # remember state and city if form error form.fields['city'].initial = request.POST.get('city') form.fields['state'].initial = request.POST.get('state') # check organization name if Organization.objects.filter(short_name__iexact = slugify(request.POST.get('shortname'))): error_msg = _(u"Informed organization is already registered. Please choose another name here or login with an existing account") form.errors["organization"] = ErrorList([error_msg]) error_found = True # check password if not request.POST.get('password1') == request.POST.get('password2'): error_msg = _(u"The confirmation of the new password is wrong") form.errors["password1"] = ErrorList([error_msg]) form.errors["password2"] = ErrorList([error_msg]) error_found = True # form is valid and no errors found if form.is_valid() and not error_found: form.save(request) user = User.objects.get(username__iexact=form.cleaned_data['username']) profile = user.get_profile() person = profile.person # active automatic org = Organization.objects.filter(organization__isnull=True).filter(person=person)[0] org.active = True org.save() for p in org.person_set.all(): for rp in p.profile.user.registrationprofile_set.all(): activation_key = rp.activation_key.lower() # Normalize before trying anything with it. RegistrationProfile.objects.activate_user(activation_key) prof = ProfessionalResponsible() prof.organization = org prof.person = person prof.name = person.name prof.save() # invoice i = Invoice() i.organization = org i.status = 2 i.save() bcc_list = ADMINS_REGISTRATION msg = EmailMessage() msg.subject = u'Nova assinatura em %s' % URL_HOME msg.body = u'Uma nova organizacao se registrou no GestorPSI. Para mais detalhes acessar %s/gcm/\n\n' % URL_APP msg.body += u'Organização %s' % org msg.to = bcc_list msg.send() request.session['user_aux_id'] = user.id # message for client user = User.objects.get(id=request.session['user_aux_id']) msg = EmailMessage() msg.subject = u"Assinatura GestorPSI.com.br" msg.body = u"Olá, bom dia!\n\n" msg.body += u"Obrigado por assinar o GestorPsi.\nSua solicitação foi recebida pela nossa equipe. Sua conta está pronta para usar! " msg.body += u"Qualquer dúvida que venha ter é possível consultar os links abaixo ou então entrar em contato conosco através do formulário de contato.\n\n" msg.body += u"link funcionalidades: %s/funcionalidades/\n" % URL_HOME msg.body += u"link como usar: %s/como-usar/\n" % URL_HOME msg.body += u"link manual: %s/media/manual.pdf\n" % URL_DEMO msg.body += u"link contato: %s/contato/\n\n" % URL_HOME msg.body += u"Instruções no YouTube: https://www.youtube.com/channel/UC03EiqIuX72q-fi0MfWK8WA\n\n" msg.body += u"O periodo de teste inicia em %s e termina em %s.\n" % ( i.start_date.strftime("%d/%m/%Y"), i.end_date.strftime("%d/%m/%Y") ) msg.body += u"Antes do término do período de teste você deve optar por uma forma de pagamento aqui: %s/organization/signature/\n\n" % URL_APP msg.body += u"IMPORTANTE: As informações inseridas no sistema podem ser editadas mas não apagadas. Por isso, se for necessário fazer testes com informações fictícias para entender como o sistema funciona, utilize a nossa versão de demonstração: http://demo.gestorpsi.com.br\n\n" msg.body += u"Endereço do GestorPSI: %s\n" % URL_APP msg.body += u"Usuário/Login %s\n" % request.POST.get('username') msg.body += u"Senha %s\n\n" % request.POST.get('password1') msg.body += u"%s" % SIGNATURE msg.to = [ user.email, ] msg.bcc = bcc_list msg.send() return HttpResponseRedirect(success_url or reverse('registration-complete')) # mount form, new register else: form = form_class() # WHY THIS CODE ??? if extra_context is None: extra_context = {} context = RequestContext(request) for key, value in extra_context.items(): context[key] = callable(value) and value() or value return render_to_response( template_name, { 'form': form }, context_instance=RequestContext(request) )
sys.path.append('..') from gestorpsi.organization.models import Organization from gestorpsi.gcm.models.payment import PaymentType from gestorpsi.gcm.models.invoice import Invoice from gestorpsi.gcm.models.plan import Plan # main code for o in Organization.objects.filter(suspension=False, organization=None): # when client do register a automatic invoice will be created. # Org have no less than one invoice by default roles system invoice. try: last = Invoice.objects.filter(organization=o).latest('end_date') except: last = Invoice() last.start_date = date.today() - relativedelta(months=1) last.end_date = date.today() # can not be None if o.payment_type == None: o.payment_type = PaymentType.objects.get(pk=1) # credit card o.save() # can not be None / Check how many professional are subscribed. if o.prefered_plan == None: o.prefered_plan = Plan.objects.get(pk=2) # 1 professional o.save() """ contratos
# main code # Create next invoice if last was paid and organization is not suspension for x in Invoice.objects.filter(end_date=end, status__gt=0, organization__suspension=False): """ contratos - seram avisados um mes antes de vencer - nao gera fatura mensal boleto termina em um mês ou menos """ # non exist if Invoice.objects.filter( end_date=end+relativedelta(months=1), organization=x.organization ).count() == 0 : i = Invoice() # new invoice i.organization = x.organization i.start_date = end i.end_date = end + relativedelta(months=1) i.payment_type = x.organization.payment_type i.ammount = x.organization.prefered_plan.value i.plan = x.organization.prefered_plan i.status = 0 # pendente i.save() to = [] # send mail to ''' send mail just to user is_active = True ''' # administratror of org
from datetime import date from gestorpsi.organization.models import Organization from gestorpsi.gcm.models.payment import PaymentType from gestorpsi.gcm.models.invoice import Invoice from gestorpsi.gcm.models.plan import Plan # main code for o in Organization.objects.filter(suspension=False, organization=None): # when client do register a automatic invoice will be created. # Org have no less than one invoice by default roles system invoice. try: last = Invoice.objects.filter(organization=o).latest('end_date') except: last = Invoice() last.start_date = date.today() - relativedelta(months=1) last.end_date = date.today() # can not be None if o.payment_type == None: o.payment_type = PaymentType.objects.get(pk=1) # credit card o.save() # can not be None / Check how many professional are subscribed. if o.prefered_plan == None: o.prefered_plan = Plan.objects.get(pk=2) # 1 professional o.save() """ contratos
def register(request, success_url=None, form_class=RegistrationForm, template_name='registration/registration_organization_form.html', extra_context=None): if request.method == 'POST': #the full process of registration is done here form = form_class(data=request.POST) error_found = False # remember state and city if form error form.fields['city'].initial = request.POST.get('city') form.fields['state'].initial = request.POST.get('state') # check organization name if Organization.objects.filter( short_name__iexact=slugify(request.POST.get('shortname'))): error_msg = _( u"Informed organization is already registered. Please choose another name here or login with an existing account" ) form.errors["shortname"] = ErrorList([error_msg]) error_found = True # check password if not request.POST.get('password1') == request.POST.get('password2'): error_msg = _(u"The confirmation of the new password is wrong") form.errors["password1"] = ErrorList([error_msg]) form.errors["password2"] = ErrorList([error_msg]) error_found = True # form is valid and no errors found if form.is_valid() and not error_found: form.save(request) user = User.objects.get( username__iexact=form.cleaned_data['username']) profile = user.get_profile() person = profile.person # active automatic org = Organization.objects.filter( organization__isnull=True).filter(person=person)[0] org.active = True org.save() for p in org.person_set.all(): for rp in p.profile.user.registrationprofile_set.all(): activation_key = rp.activation_key.lower( ) # Normalize before trying anything with it. RegistrationProfile.objects.activate_user(activation_key) prof = ProfessionalResponsible() prof.organization = org prof.person = person prof.name = person.name prof.save() # invoice i = Invoice() i.organization = org i.status = 2 # free i.save() bcc_list = ADMINS_REGISTRATION msg = EmailMessage() msg.subject = u'Nova assinatura em %s' % URL_HOME msg.body = u'Uma nova organizacao se registrou no GestorPSI. Para mais detalhes acessar %s/gcm/\n\n' % URL_APP msg.body += u'Organização %s' % org msg.to = bcc_list msg.send() request.session['user_aux_id'] = user.id # message for client user = User.objects.get(id=request.session['user_aux_id']) msg = EmailMessage() msg.subject = u"Assinatura GestorPSI.com.br" msg.body = u"Olá, bom dia!\n\n" msg.body += u"Obrigado por assinar o GestorPsi.\nSua solicitação foi recebida pela nossa equipe. Sua conta está pronta para usar! " msg.body += u"Qualquer dúvida que venha ter é possível consultar os links abaixo ou então entrar em contato conosco através do formulário de contato.\n\n" msg.body += u"link funcionalidades: %s/funcionalidades/\n" % URL_HOME msg.body += u"link como usar: %s/como-usar/\n" % URL_HOME msg.body += u"link manual: %s/media/manual.pdf\n" % URL_DEMO msg.body += u"link contato: %s/contato/\n\n" % URL_HOME msg.body += u"Instruções no YouTube: https://www.youtube.com/channel/UC03EiqIuX72q-fi0MfWK8WA\n\n" msg.body += u"O periodo de teste inicia em %s e termina em %s.\n" % ( i.start_date.strftime("%d/%m/%Y"), i.end_date.strftime("%d/%m/%Y")) msg.body += u"Antes do término do período de teste você deve optar por uma forma de pagamento aqui: %s/organization/signature/\n\n" % URL_APP msg.body += u"IMPORTANTE: As informações inseridas no sistema podem ser editadas mas não apagadas. Por isso, se for necessário fazer testes com informações fictícias para entender como o sistema funciona, utilize a nossa versão de demonstração: http://demo.gestorpsi.com.br\n\n" msg.body += u"Endereço do GestorPSI: %s\n" % URL_APP msg.body += u"Usuário/Login %s\n" % request.POST.get('username') msg.body += u"Senha %s\n\n" % request.POST.get('password1') msg.body += u"%s" % SIGNATURE msg.to = [ user.email, ] msg.bcc = bcc_list msg.send() return HttpResponseRedirect(reverse('registration-complete')) # mount form, new register else: form = form_class() # WHY THIS CODE ??? if extra_context is None: extra_context = {} context = RequestContext(request) for key, value in extra_context.items(): context[key] = callable(value) and value() or value return render_to_response(template_name, {'form': form}, context_instance=RequestContext(request))
Organization.date_created >= 12 09 2016 """ print "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # " print "# Invoice - Creating invoice new format" # main code for o in Organization.objects.filter(suspension=False, organization=None, date_created__gte=new_format): inv = [] # invoices to print resume # last invoice li = Invoice.objects.filter(organization=o).latest('id') while li.end_date < date.today()+relativedelta(months=1) and li.start_date < date.today(): i = Invoice() # new invoice i.organization = li.organization i.start_date = li.end_date i.end_date = li.end_date + relativedelta(months=1) i.expiry_date = i.start_date + relativedelta(days=7) i.payment_type = li.organization.payment_type i.ammount = li.organization.prefered_plan.value i.plan = li.organization.prefered_plan i.status = 0 # pendente i.save() li = i # check end_date of new invoice inv.append(i) # print resume to email admin if len(inv) > 0 :
print "# Invoice - Creating invoice new format" # main code for o in Organization.objects.filter(suspension=False, organization=None, date_created__gte=new_format): inv = [] # invoices to print resume # last invoice li = Invoice.objects.filter(organization=o).latest('id') while li.end_date < date.today() + relativedelta( months=1) and li.start_date < date.today(): i = Invoice() # new invoice i.organization = li.organization i.start_date = li.end_date i.end_date = li.end_date + relativedelta(months=1) i.expiry_date = i.start_date + relativedelta(days=7) i.payment_type = li.organization.payment_type i.ammount = li.organization.prefered_plan.value i.plan = li.organization.prefered_plan i.status = 0 # pendente i.save() li = i # check end_date of new invoice inv.append(i) # print resume to email admin if len(inv) > 0:
def create_invoice(org, status=None, paytype=None, bank=None, details=None): # new invoice i = Invoice() i.organization = org i.plan = org.prefered_plan if status: i.status = status i.bank = bank i.payment_type = PaymentType.objects.get(pk=paytype) i.date_payed = date.today() i.start_date = i.date_payed i.end_date = i.start_date + relativedelta(years=5) i.expiry_date = i.start_date + relativedelta(years=5) i.payment_detail = u"gateway code: %s" % details else: i.status = 2 # free i.save() return i