|
@@ -305,10 +305,17 @@ def department_list(request):
|
|
result = []
|
|
result = []
|
|
rows = Department.objects.filter()
|
|
rows = Department.objects.filter()
|
|
for row in rows:
|
|
for row in rows:
|
|
|
|
+ isCompany = False
|
|
|
|
+ if row.id == row.company_id:
|
|
|
|
+ isCompany = True
|
|
item = {
|
|
item = {
|
|
'id': row.id,
|
|
'id': row.id,
|
|
|
|
+ 'company': row.company_id,
|
|
|
|
+ 'product_range': row.product_range,
|
|
|
|
+ 'product_range_text': row.product_range and Department.PRODUCT_RANGE_CHOICES[row.product_range - 1][1] or '',
|
|
'name': row.name,
|
|
'name': row.name,
|
|
'notes': row.notes,
|
|
'notes': row.notes,
|
|
|
|
+ 'isCompany': isCompany,
|
|
'parent_id': row.parent_id or 0,
|
|
'parent_id': row.parent_id or 0,
|
|
}
|
|
}
|
|
result.append(item)
|
|
result.append(item)
|
|
@@ -324,18 +331,20 @@ def department_save(request):
|
|
try:
|
|
try:
|
|
with transaction.atomic():
|
|
with transaction.atomic():
|
|
if id:
|
|
if id:
|
|
- dep = Department.getById(id)
|
|
|
|
- dep.name = data['name']
|
|
|
|
- dep.notes = data['notes']
|
|
|
|
- dep.save()
|
|
|
|
- BizLog.objects.addnew(request.user, BizLog.UPDATE, u"修改部门[%s],id=%d" % (data['name'], dep.id))
|
|
|
|
|
|
+ department = Department.getById(id)
|
|
|
|
+ department.name = data['name']
|
|
|
|
+ department.notes = data['notes']
|
|
|
|
+ department.save()
|
|
|
|
+ BizLog.objects.addnew(request.user, BizLog.UPDATE, u"修改部门[%s],id=%d" % (data['name'], department.id))
|
|
else:
|
|
else:
|
|
if parent_id:
|
|
if parent_id:
|
|
parent = Department.getById(parent_id)
|
|
parent = Department.getById(parent_id)
|
|
|
|
+ company_id = parent.company_id
|
|
parent_id = parent.id
|
|
parent_id = parent.id
|
|
else:
|
|
else:
|
|
parent = None
|
|
parent = None
|
|
parent_id = None
|
|
parent_id = None
|
|
|
|
+ company_id = None
|
|
lft = Department.getLft(parent)
|
|
lft = Department.getLft(parent)
|
|
|
|
|
|
Department.objects.filter(rgt__gt=lft).update(rgt=F('rgt') + 2)
|
|
Department.objects.filter(rgt__gt=lft).update(rgt=F('rgt') + 2)
|
|
@@ -345,11 +354,22 @@ def department_save(request):
|
|
name=data['name'],
|
|
name=data['name'],
|
|
notes=data['notes'],
|
|
notes=data['notes'],
|
|
parent_id=parent_id,
|
|
parent_id=parent_id,
|
|
|
|
+ company_id=company_id,
|
|
lft=lft+1,
|
|
lft=lft+1,
|
|
rgt=lft+2
|
|
rgt=lft+2
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ if department.company_id == None:
|
|
|
|
+ department.company_id = department.id
|
|
|
|
+ department.save()
|
|
|
|
+
|
|
BizLog.objects.addnew(request.user, BizLog.INSERT, u"添加部门[%s],id=%d" % (data['name'], department.id))
|
|
BizLog.objects.addnew(request.user, BizLog.INSERT, u"添加部门[%s],id=%d" % (data['name'], department.id))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if department.id == department.company_id and data['product_range']:
|
|
|
|
+ department.product_range = int(data['product_range'])
|
|
|
|
+ department.save()
|
|
|
|
+
|
|
except CustomError, e:
|
|
except CustomError, e:
|
|
return JSONError(e.get_error_msg())
|
|
return JSONError(e.get_error_msg())
|
|
except Exception, e:
|
|
except Exception, e:
|