parther check inn

feature/docker
Dmitriy Shesterkin 9 years ago
parent f03fc5f043
commit 7b75159aa2
  1. 2
      src/customer/decorators.py
  2. 15
      src/customer/helpers.py
  3. 1
      src/customer/utils.py
  4. 35
      src/customer/views/clients_ajax.py

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from django.contrib.auth.decorators import user_passes_test
from django.core.urlresolvers import reverse
def license_required(function=None, redirect_field_name=None, login_url='/my/license/'):
"""

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from customer.models import Client
def partner_already_exists(user_as_company, partner_inn):
"""
:param user_as_company:
:param partner_inn:
:return:
"""
if Client.objects.filter(company=user_as_company, inn=partner_inn):
return True
else:
return False

@ -5,7 +5,6 @@ from django.conf import settings
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
SUPPORT_EMAIL = getattr(settings, 'SUPPORT_EMAIL')

@ -11,8 +11,8 @@ from django.template.loader import render_to_string
from customer import models, forms
from docs.models import Invoice, Faktura, AktRabot, AktSverki, Nakladn, Platejka, Dover
from customer.decorators import license_required
from customer.utils import raise_if_no_profile
from customer.helpers import partner_already_exists
@login_required
@ -47,21 +47,35 @@ def clients_add_ajax(request):
raise_if_no_profile(request)
form_class = forms.ClientForm
new_client_id = None
new_client_str = None
form = form_class(data=request.POST)
new_client_id = None
html = ''
if form.is_valid():
new_client = form.save(commit=False)
new_client.company = request.user.profile
new_client_str = new_client.name
new_client.save()
new_client_id = new_client.id
html = render_to_string('customer/clients/list_item.html',
{'obj': new_client}, RequestContext(request))
# check company has in users clients
if partner_already_exists(request.user.profile, form.cleaned_data['inn']):
data = {
'success': False,
'field_errors': {'inn': []},
'form_errors': ['Контрагент с таким ИНН уже существует.'],
'reload': False,
'id': None,
'name': None,
'action': 'client-add',
'row_html': '',
}
return HttpResponse(json.dumps(data), content_type='application/json')
else:
new_client = form.save(commit=False)
new_client.company = request.user.profile
new_client_str = new_client.name
new_client.save()
new_client_id = new_client.id
html = render_to_string('customer/clients/list_item.html',
{'obj': new_client}, RequestContext(request))
non_field_errors = form.non_field_errors()
if not form.is_valid():
@ -71,7 +85,6 @@ def clients_add_ajax(request):
'success': form.is_valid(),
'field_errors': form.errors, # ошибки полей
'form_errors': non_field_errors, # ошибки формы
#'reload': form.is_valid() and 'reload_on_success' in request.GET
'reload': False,
'id': new_client_id,
'name': new_client_str,

Loading…
Cancel
Save