def post(self, request): if not hasattr(request, 'company') or not hasattr(request, 'employee'): raise Http404() bills_count = Invoice.objects.count({ 'expire_date': { '$gte': timezone.now() }, 'payer': request.company._id, 'status': InvoiceStatusEnum.CREATED }) if bills_count: return HttpResponse(simplejson.dumps({ 'error': True, 'error_message': "Такой счет уже существует." }), mimetype='application/javascript') rekvizitka_bank_account = SettingsManager.get_property( 'rekvizitka_bank_account') bill_data = { 'payer': request.company._id, 'number': u'КЦ-%d' % SettingsManager.inc_and_return_property('bill_auto_index'), 'position': u'Верификация в информационной системе', 'status': InvoiceStatusEnum.CREATED, 'duration_days': 30, 'price': SettingsManager.get_property('verify_bill_price') } bill_data.update(rekvizitka_bank_account) new_bill = Invoice(bill_data) new_bill.save() employee = request.employee employee_tz = employee.get_tz() issued = new_bill.create_date.astimezone(employee_tz) return HttpResponse(simplejson.dumps({ 'error': False, 'bill': { 'id': unicode(new_bill._id), 'service_title': bill_data['position'], 'price': bill_data['price'], 'status': bill_data['status'], 'issued': issued.strftime('%d.%m.%Y %H:%M'), 'number': new_bill.number } }), mimetype='application/javascript')
def post(self, request): if not hasattr(request, 'company') or not hasattr(request, 'employee'): raise Http404() bills_count = Invoice.objects.count({'expire_date' : {'$gte' : timezone.now()}, 'payer' : request.company._id, 'status' : InvoiceStatusEnum.CREATED}) if bills_count: return HttpResponse(simplejson.dumps({'error' : True, 'error_message' : "Такой счет уже существует."}), mimetype='application/javascript') rekvizitka_bank_account = SettingsManager.get_property('rekvizitka_bank_account') bill_data = { 'payer' : request.company._id, 'number' : u'КЦ-%d' % SettingsManager.inc_and_return_property('bill_auto_index'), 'position' : u'Верификация в информационной системе', 'status' : InvoiceStatusEnum.CREATED, 'duration_days':30, 'price' : SettingsManager.get_property('verify_bill_price') } bill_data.update(rekvizitka_bank_account) new_bill = Invoice(bill_data) new_bill.save() employee = request.employee employee_tz = employee.get_tz() issued = new_bill.create_date.astimezone(employee_tz) return HttpResponse(simplejson.dumps({'error' : False, 'bill' : {'id' : unicode(new_bill._id), 'service_title' : bill_data['position'], 'price' : bill_data['price'], 'status' : bill_data['status'], 'issued' : issued.strftime('%d.%m.%Y %H:%M'), 'number' : new_bill.number}}), mimetype='application/javascript')
def generate_rek_id(): if settings.TEST_RUN: return 'CK1' return integer_to_code(SettingsManager.inc_and_return_property('company_auto_index'))
def generate_rek_id(): if settings.TEST_RUN: return 'CK1' return integer_to_code( SettingsManager.inc_and_return_property('company_auto_index'))