def contract(request): """Creates a view to save the contract details.""" contracts = Contract.objects.all() if request.method == "POST": form = ContractForm(request.POST) if form.is_valid(): from_date = form.cleaned_data["from_date"] to_date = form.cleaned_data["to_date"] list_size = form.cleaned_data["list_size"] total_email = form.cleaned_data["total_email"] try: contract = Contract() contract.from_date = from_date contract.to_date = to_date contract.list_size = list_size contract.total_email = total_email contract.save() except: pass return HttpResponseRedirect(reverse("index")) else: form = ContractForm() context = {"contracts": contracts, "form": form} return render(request, "contracts/contract.html", context)
def contract(request): '''Creates a view to save the contract details.''' contracts = Contract.objects.all() if request.method == 'POST': form = ContractForm(request.POST) if form.is_valid(): from_date = form.cleaned_data['from_date'] to_date = form.cleaned_data['to_date'] list_size = form.cleaned_data['list_size'] total_email = form.cleaned_data['total_email'] try: contract = Contract() contract.from_date = from_date contract.to_date = to_date contract.list_size = list_size contract.total_email = total_email contract.save() except: pass return HttpResponseRedirect(reverse('index')) else: form = ContractForm() context = {'contracts': contracts, 'form': form} return render(request, 'contracts/contract.html', context)
def testContractCreation(self): student, teacher = self.createStudentTeacher() ''' Test creation of contract between student and teacher ''' contract = Contract(teacher=teacher, student=student) contract.save() self.assertIsInstance(contract, Contract)
def testSearch(self): student, teacher = self.createStudentTeacher() contract = Contract(teacher=teacher, student=student) contract.save() foundContract = Contract.objects.filter(student=student, teacher=teacher) assert (contract == foundContract[0])
def handle(self, *args, **options): data_file = csv.reader(open(os.path.join(settings.BASE_DIR, 'contracts/docs/hourly_prices.csv'), 'r')) #skip header row next(data_file) for line in data_file: try: if line[0]: #create contract record, unique to vendor, labor cat idv_piid = line[0] vendor_name = line[3] labor_category = line[4].strip().replace('\n', ' ') try: contract = Contract.objects.get(idv_piid=idv_piid, labor_category=labor_category, vendor_name=vendor_name) except Contract.DoesNotExist: contract = Contract() contract.idv_piid = idv_piid contract.labor_category = labor_category contract.vendor_name = vendor_name contract.education_level = contract.get_education_code(line[5]) if line[1] != '': contract.contract_start = datetime.strptime(line[1], '%m/%d/%Y').date() if line[2] != '': contract.contract_end = datetime.strptime(line[2], '%m/%d/%Y').date() if line[6].strip() != '': contract.min_years_experience = line[6] else: contract.min_years_experience = 0 if line[7] and line[7] != '': contract.hourly_rate_year1 = contract.normalize_rate(line[7]) else: #there's no pricing info continue for count, rate in enumerate(line[8:12]): if rate and rate.strip() != '': setattr(contract, 'hourly_rate_year' + str(count+2), contract.normalize_rate(rate)) contract.contractor_site = line[12] contract.save() except Exception as e: print(e) print(line) break
def __init__(self): Contract.objects.all().delete() for contract in CONTRACTS: new_contract = Contract( contract_number=contract['contract_number'], sign_date=contract['sign_date'], contract_type=contract['contract_type'], tax=contract['tax'], cancel_date=contract['cancel_date'], broadcast=contract['broadcast'], unit_price=contract['unit_price'], ) new_contract.save()
def approve(self, user): ''' Approve this SubmittedPriceList. This causes its rows of pricing data to be converted to Contract models, which are then accessible via CALC's API and in the Data Explorer. ''' self._change_status(self.STATUS_APPROVED, user) for row in self.rows.filter(is_muted=False): if row.contract_model is not None: raise AssertionError() contract = Contract( idv_piid=self.contract_number, contract_start=self.contract_start, contract_end=self.contract_end, vendor_name=self.vendor_name, labor_category=row.labor_category, education_level=row.education_level, min_years_experience=row.min_years_experience, contractor_site=self.contractor_site, schedule=self.get_schedule_title(), business_size=self.get_business_size_string(), sin=row.sin, keywords=row.keywords, certifications=row.certifications, security_clearance=row.security_clearance, ) contract.adjust_contract_year() # Assuming the rate in the price list is the 'base rate' # Escalate the hourly_rate_yearX fields contract.escalate_hourly_rate_fields(row.base_year_rate, self.escalation_rate) # Update current/next/second year price fields contract.update_price_fields() contract.full_clean(exclude=['piid']) contract.save() row.contract_model = contract row.save() self.save()
def approve(self, user): ''' Approve this SubmittedPriceList. This causes its rows of pricing data to be converted to Contract models, which are then accessible via CALC's API and in the Data Explorer. ''' self._change_status(self.STATUS_APPROVED, user) for row in self.rows.filter(is_muted=False): if row.contract_model is not None: raise AssertionError() contract = Contract( idv_piid=self.contract_number, contract_start=self.contract_start, contract_end=self.contract_end, vendor_name=self.vendor_name, labor_category=row.labor_category, education_level=row.education_level, min_years_experience=row.min_years_experience, contractor_site=self.contractor_site, schedule=self.get_schedule_title(), business_size=self.get_business_size_string(), sin=row.sin, ) contract.adjust_contract_year() # Assuming the rate in the price list is the 'base rate' # Escalate the hourly_rate_yearX fields contract.escalate_hourly_rate_fields( row.base_year_rate, self.escalation_rate) # Update current/next/second year price fields contract.update_price_fields() contract.full_clean(exclude=['piid']) contract.save() row.contract_model = contract row.save() self.save()
def testContractVerification(self): student, teacher = self.createStudentTeacher() contract = Contract(teacher=teacher, student=student) contract.save() # Case: Neither accepted # Expected: Acceptance Error Raised with self.assertRaises(AcceptenceError) as context: contract.start_contract() self.assertTrue('This is broken' in str(context.AcceptanceError)) assert (contract.status == contract.PENDING) # Case: Student not accepted # Expected: Acceptance Error Raised contract.teacher_accepted = True contract.student_accepted = False contract.save() with self.assertRaises(AcceptenceError) as context: contract.start_contract() self.assertTrue('This is broken' in str(context.AcceptanceError)) assert (contract.status == contract.PENDING) # Case: Teacher not accepted # Expected: Acceptance Error Raised contract.teacher_accepted = False contract.student_accepted = True contract.save() with self.assertRaises(AcceptenceError) as context: contract.start_contract() self.assertTrue('This is broken' in str(context.AcceptanceError)) assert (contract.status == contract.PENDING) # Case: Both accepted contract.teacher_accepted = True contract.student_accepted = True contract.start_contract() contract.save() assert (contract.student_accepted == True) assert (contract.teacher_accepted == True) assert (contract.status == contract.ACTIVE)