def view(opportunite_id): title_page = 'Opportunites' data = Opportunite.objects.get(id=opportunite_id) if not current_user.has_roles([ ('super_admin', 'opportunite') ]) and data.vendeur_id.id != current_user.id: return redirect(url_for('opportunite.index')) form = FormOpportunite(obj=data) customer = Compagnie.objects.get(id=data.client_id.id) form_client = FormClient(obj=customer) form_client.idcategorie.data = [ str(cat.id) for cat in customer.idcategorie ] if customer.maincategorie: form_client.maincategorie.data = str(customer.maincategorie.id) contact = Users.objects.get(id=data.contact_id.id) form_contact = FormUser(obj=contact) form.vendeur_id.data = str(data.vendeur_id.id) form_client.id.data = str(customer.id) form.id.data = str(opportunite_id) devis_count = Document.objects(Q(opportunite_id=data) & Q(devisDoc=True)).count() from ..user.models_user import Roles admin_role = Roles.objects(valeur='super_admin').first() if current_user.has_roles(['super_admin']): all_vendeur = Users.objects(Q(user__gt=0) & Q(activated=True)) else: all_vendeur = Users.objects( Q(user__gt=0) & Q(activated=True) & Q(roles__role_id__ne=admin_role)) form.vendeur_id.choices = [('', ' ')] for choice in all_vendeur: form.vendeur_id.choices.append( (str(choice.id), choice.first_name + ' ' + choice.last_name)) etape_list = Etape.objects(actif=True).order_by('order') last_etape = Etape.objects(actif=True).order_by('-order').first() client_list = Compagnie.objects(activated=True) devis_count = Document.objects(Q(opportunite_id=data) & Q(devisDoc=True)).count() return render_template('opportunite/view.html', **locals())
def view(etape_id): title_page = 'Etape' data = Etape.objects().get(id=etape_id) form = FormEtape(obj=data) return render_template('opportunite/etape/view.html', **locals())
def unique_code_validator_etape(form, field): code_unique = Etape.objects(name=field.data).count() if code_unique: if not form.id.data: raise wtf.ValidationError('Ce nom est deja utilise.') else: code = Etape.objects.get(id=form.id.data) if code.name != field.data: raise wtf.ValidationError('Ce nom est deja utilise.')
def down(etape_id): current_etape = Etape.objects.get(id=etape_id) prev = current_etape.order + 1 precedent = Etape.objects(order=prev).first() if precedent: precedent.order = current_etape.order precedent.save() current_etape.order = prev current_etape.save() return redirect(url_for('etape.index'))
def deleted(): # from ..opportunite.models_opportunite import Suivie, Opportunite data = [] element = [] count = 0 for item in request.form.getlist('item_id'): info = {} item_found = Etape.objects().get(id=item) # opportunite = Opportunite.objects(etape_id=item_found) # if opportunite: # info['statut'] = 'NOK' # info['message'] = 'L\'etape "'+item_found.name+'" est utilise par '+str(opportunite.count())+' autre(s) opportunite(s)' # # exit_suivie = Suivie.objects(etape_id=item_found) # if exit_suivie: # info['statut'] = 'NOK' # info['message'] = 'L\'etape "'+item_found.name+'" est utilise par '+str(exit_suivie.count())+' autre(s) suivie(s)' if item_found.sigle: info['statut'] = 'NOK' info[ 'message'] = 'L\'etape "' + item_found.name + '" ne peut etre supprimer' # if not opportunite and not exit_suivie: if not item_found.sigle: item_found.delete() element.append(str(item_found.id)) count += 1 else: data.append(info) if count: info = {} info['statut'] = 'OK' info['message'] = str( count) + ' element(s) ont ete supprime avec success' info['element'] = element data.append(info) data = json.dumps(data) return data
def edit(etape_id=None): title_page = 'Etape' if etape_id: data = Etape.objects.get(id=etape_id) form = FormEtape(obj=data) form.id.data = etape_id else: data = Etape() form = FormEtape() if form.validate_on_submit(): data.proba = float(form.proba.data) data.name = form.name.data if not etape_id: exist = False position = 1 while not exist: etap = Etape.objects(order=position).get() if not etap: exist = True data.order = position position += 1 if form.sigle.data: data.sigle = form.sigle.data etape = data.save() flash('Enregistement effectue avec succes', 'success') if request.form['nouveau'] == '1': return redirect(url_for('etape.edit')) else: return redirect(url_for('etape.view', etape_id=etape.id)) return render_template('opportunite/etape/edit.html', **locals())
def edit(opportunite_id=None): title_page = 'Opportunites' if opportunite_id: data = Opportunite.objects.get(id=opportunite_id) if data.etape == global_etape[3]: return redirect( url_for('opportunite.view', opportunite_id=opportunite_id)) if not current_user.has_roles([ ('super_admin', 'opportunite') ], ['edit']) and data.vendeur_id.id != current_user.id: return redirect( url_for('opportunite.view', opportunite_id=opportunite_id)) form = FormOpportunite(obj=data) customer = Compagnie.objects.get(id=data.client_id.id) form_client = FormClient(prefix="client", obj=customer) form_client.idcategorie.data = [ str(cat.id) for cat in customer.idcategorie ] form_client.maincategorie.data = str(customer.maincategorie.id) if request.method == 'GET': form_client.maincategorie.choices = [ ('', 'Faite le choi de la categorie principale') ] for choice in customer.idcategorie: form_client.maincategorie.choices.append( (str(choice.id), choice.name)) contact = Users.objects.get(id=data.contact_id.id) form_contact = FormUser(obj=contact) form.vendeur_id.data = str(data.vendeur_id.id) form_client.id.data = str(customer.id) form.id.data = str(opportunite_id) devis_count = Document.objects( Q(opportunite_id=data) & Q(devisDoc=True)).count() flash( 'Vous ne pouvez plus modifier les informations du client et de contact du client. ', 'warning') else: data = Opportunite() form = FormOpportunite() customer = Compagnie() form_client = FormClient(prefix="client") contact = Users() form_contact = FormUser() if request.method == 'GET': form.vendeur_id.data = str(current_user.id) if 'client_exist' in request.form and request.form['client_exist']: form_client.id.data = request.form['client_exist'] if 'contact_exist' in request.form and request.form['contact_exist']: form_contact.id.data = request.form['contact_exist'] form_client.notCat.data = '1' from ..user.models_user import Roles admin_role = Roles.objects(valeur='super_admin').first() if current_user.has_roles(['super_admin']): all_vendeur = Users.objects(Q(user__gt=0) & Q(activated=True)) else: all_vendeur = Users.objects( Q(user__gt=0) & Q(activated=True) & Q(roles__role_id__ne=admin_role)) form.vendeur_id.choices = [('', ' ')] for choice in all_vendeur: form.vendeur_id.choices.append( (str(choice.id), choice.first_name + ' ' + choice.last_name)) form_client.idcategorie.data = '' form_client.idcategorie.choices = [('', '')] form_client.maincategorie.data = '' form_client.maincategorie.choices = [ ('', 'Faite le choix de la categorie principale') ] etape_list = Etape.objects(actif=True).order_by('order') client_list = Compagnie.objects() libelle = [] if not opportunite_id: libelle = Libelle_Opportunite.objects(actif=True) current_client = None if request.method == 'POST' and 'client_exist' in request.form and request.form[ 'client_exist']: current_client = Compagnie.objects.get(id=request.form['client_exist']) form_client.name.data = current_client.name form_client.email.data = current_client.email form_client.raison.data = current_client.raison form_client.phone.data = current_client.phone form_client.ville.data = current_client.ville form_client.quartier.data = current_client.quartier current_contact = None if request.method == 'POST' and 'contact_exist' in request.form and request.form[ 'contact_exist']: current_contact = Users.objects.get(id=request.form['contact_exist']) form_contact.id.data = current_contact.id form_contact.email.data = current_contact.email form_contact.first_name.data = current_contact.first_name form_contact.last_name.data = current_contact.last_name form_contact.fonction.data = current_contact.fonction form_contact.phone.data = current_contact.phone if form.validate_on_submit() and form_client.validate_on_submit( ) and form_contact.validate_on_submit(): if not opportunite_id: data.name = form.name.data if data.vendeur_id and data.vendeur_id.id != current_user.id: vendeur = Users.objects.get(id=form.vendeur_id.data) data.vendeur_id = vendeur else: vendeur = Users.objects.get(id=current_user.id) data.vendeur_id = vendeur data.note = form.note.data if 'client_exist' in request.form and request.form['client_exist']: data.client_id = current_client else: if not opportunite_id: customer.raison = form_client.raison.data customer.name = form_client.name.data customer.ville = form_client.ville.data customer.quartier = form_client.quartier.data customer.email = form_client.email.data customer.phone = form_client.phone.data customer.activated = False customer.verify = 0 customer.source = "opportunite" customer = customer.save() data.client_id = customer if 'contact_exist' in request.form and request.form['contact_exist']: data.contact_id = current_contact data.etape = global_etape[0] else: if not opportunite_id: contact.email = form_contact.email.data contact.first_name = form_contact.first_name.data contact.last_name = form_contact.last_name.data if form_contact.fonction.data: contact.fonction = form_contact.fonction.data contact.phone = form_contact.phone.data contact.activated = False contact.source = "opportunite" contact.user = 0 contact = contact.save() data.contact_id = contact data.etape = global_etape[0] # Sauvegarde du contact dans l'entreprise en cours. contact_compagnie = data.client_id.idcontact user_compagnie = data.client_id.iduser if contact not in contact_compagnie and contact not in user_compagnie: cli = Compagnie.objects.get(id=data.client_id.id) cli.idcontact.append(contact) cli.save() data = data.save() if not opportunite_id: suivie = Suivie() suivie.etape = global_etape[0] suivie.opportunite_id = data first_activite = Activite.objects(Q(sigle='faire_devis')).get() suivie.activite = first_activite.name suivie.sigle_activite = 'faire_devis' time_zones = tzlocal() date_auto_nows = datetime.datetime.now(time_zones).strftime( "%m/%d/%y") current_date = datetime.datetime.strptime(date_auto_nows, "%m/%d/%y") suivie.dateNext = current_date + datetime.timedelta( days=first_activite.jour) suivie.resume = first_activite.name suivie.description = first_activite.description suivie.status = False suivie = suivie.save() opp = Opportunite.objects.get(id=data.id) opp.suivie.append(suivie) opp.save() flash('Enregistement effectue avec succes', 'success') if request.form['nouveau'] == '1': return redirect( url_for('opportunite.edit', relance=request.args.get('relance'))) else: return redirect( url_for('opportunite.view', opportunite_id=data.id, relance=request.args.get('relance'))) return render_template('opportunite/edit.html', **locals())
def generate(): for mod in global_etape_gene: module_exite = Etape.objects(sigle=mod['sigle']).first() if not module_exite: module = Etape() module.name = mod['name'] module.order = mod['order'] module.proba = float(mod['proba']) module.sigle = mod['sigle'] module.save() else: module = module_exite module.name = mod['name'] module.order = mod['order'] module.proba = float(mod['proba']) module.sigle = mod['sigle'] module.save() return redirect(url_for('etape.index'))
def index(): title_page = 'Etape' datas = Etape.objects().order_by('order') return render_template('opportunite/etape/index.html', **locals())