def handle(self, user, id, *args, **kwargs): employee = Employee.objects.get(user__first_name__icontains=user) nlp = NumLastProposal.objects.get(pk=1) # sempre pk=1 entry = Entry.objects.get(pk=id) if entry.is_entry == True: print('Já foi dado entrada.') else: proposal = Proposal( num_prop=nlp.num_last_prop + 1, type_prop='R', category=entry.category, description=entry.description, work=entry.work, person=entry.person, employee=employee, seller=entry.seller, ) proposal.save() ''' Define que foi dado entrada ''' entry.is_entry = True entry.save() ''' Incrementa o número do último orçamento ''' nlp.num_last_prop += 1 nlp.save() print('Orçamento criado com sucesso')
s = randint(1, 3) seller = Seller.objects.get(pk=s) sl = randint(0, 4) status = status_list[sl] if status == 'co' or status == 'a': date_conclusion = gen_date(min_year=2015, max_year=2015) price = gen_decimal(9, 2) else: date_conclusion = None price = 0 obj = Proposal( num_prop=i, type_prop='R', num_type_prop=0, category=category, description=description, work=work, person=person, employee=employee, seller=seller, status=status, date_conclusion=date_conclusion, price=price, ) obj.save() num_last_proposal = NumLastProposal.objects.get(pk=1) num_last_proposal.num_last_prop = REPEAT num_last_proposal.save() print('%d Proposals salvo com sucesso.' % REPEAT)
# from django.contrib.auth.models import User from orcamentos.core.models import Entry, Proposal, Employee, NumLastProposal employee = Employee.objects.get(pk=8) num_last_proposal = NumLastProposal.objects.get(pk=1) entry = Entry.objects.get(pk=1) obj = Proposal( num_prop=num_last_proposal.num_last_prop + 1, type_prop='R', category=entry.category, description=entry.description, work=entry.work, person=entry.person, employee=employee, seller=entry.seller, ) obj.save() entry.is_entry = True entry.save() num_last_proposal.num_last_prop = num_last_proposal.num_last_prop + 1 num_last_proposal.save()