def create(self, contract): try: if not self.user.has_perms( ContractConfig.gql_mutation_create_contract_perms): raise PermissionError("Unauthorized") c = ContractModel(**contract) c.state = ContractModel.STATE_DRAFT c.save(username=self.user.username) uuid_string = f"{c.id}" # check if the PH is set if "policy_holder_id" in contract: # run services updateFromPHInsuree and Contract Valuation cd = ContractDetails(user=self.user) result_ph_insuree = cd.update_from_ph_insuree( contract_details={ "policy_holder_id": contract["policy_holder_id"], "contract_id": uuid_string, "amendment": 0, }) total_amount = self.evaluate_contract_valuation( contract_details_result=result_ph_insuree, )["total_amount"] c.amount_notified = total_amount historical_record = c.history.all().last() c.json_ext = json.dumps(_save_json_external( user_id=historical_record.user_updated.id, datetime=historical_record.date_updated, message=f"create contract status {historical_record.state}"), cls=DjangoJSONEncoder) c.save(username=self.user.username) dict_representation = model_to_dict(c) dict_representation['id'], dict_representation['uuid'] = ( str(uuid_string), str(uuid_string)) except Exception as exc: return _output_exception(model_name="Contract", method="create", exception=exc) return _output_result_success(dict_representation=dict_representation)
def create_test_contract(policy_holder=None, custom_props={}): if not policy_holder: policy_holder = create_test_policy_holder() user = __get_or_create_simple_contract_user() object_data = { 'code': "CON", 'policy_holder': policy_holder, 'amount_notified': 0, 'amount_rectified': 0, 'amount_due': 0, 'date_payment_due': datetime.date(2011, 10, 31), 'state': 1, 'payment_reference': "Payment Reference", 'json_ext': json.dumps("{}"), **custom_props } contract = Contract(**object_data) contract.save(username=user.username) return contract
phone=phone, manager=manager) clnt.save() # clntsave += 1 finish_date = data[3].split('/') finish_date = date(int(finish_date[2]), int(finish_date[0]), int(finish_date[1]), ) rest_days = (finish_date - last_day).days # print datetime.now().date() + timedelta(days=rest_days) if rest_days < 1: print rest_days cnumber = int(data[1]) try: c = Contract.objects.get(number=cnumber, client=clnt) c.date_start = datetime.now().date() c.date_end = datetime.now().date() + timedelta(days=rest_days) except Contract.DoesNotExist: c = Contract(number=cnumber, client=clnt, payer=clnt, manager=manager, date_start=datetime.now().date(), date_end=datetime.now().date() + timedelta(days=rest_days), contract_type=ct, card=0, amount=0, payment_date=datetime.now(), payment_type=2, is_current=2 ) c.save() # print patronymic , last_name, first_name, phone f.close() l.write('total read lines: %d\r\n' % total) l.write('success load lines: %d\r\n' % cnt) l.write('finish\r\n') l.close()
date__year=cdate.year, date__month=cdate.month, client=cl) except Contract.DoesNotExist: cl_ct = Contract(contract_type=cts[0], date_start=s_date, date_end=e_date, date=cdate, client=cl, payer=cl, payment_date=cdate, number=data[2].strip(), amount=cts[0].price, manager=User.objects.get(pk=10)) try: cl_ct.save() except Exception, e: print e log_f.write('Contract add;%s;%s;%s\n' % (cdate, cname, ' '.join(full_name))) except Client.DoesNotExist: phone = data[13].strip() if len(phone) == 7: phone = '812' + phone elif len(phone) == 10: if int(phone[:3]) == 812: phone = phone elif int(phone[0]) == 9: phone = '7' + phone else: log_f.write(
if active: try: cnumber = Contract.objects.latest() cnumber = cnumber.pk + 1 except Contract.DoesNotExist: cnumber = 1 cnumber = u'm' + str(cnumber) print cnumber, r_date, amount, card ct = Contract(number=cnumber, date=r_date, manager=manager, date_start=s_date, date_end=e_date, contract_type=contract_type, card=card, amount=amount, payment_date=r_date, client=clnt, payer=clnt, is_current=1, payment_type=2) ct.save() activecontracts += 1 f.close() l.write('total read lines: %d\r\n' % total) l.write('active contracts load: %d\r\n' % activecontracts) l.write('Clients add: %d\r\n' % clntsave) l.write('finish\r\n') al.close() l.close()