lyh 1 жил өмнө
parent
commit
7b1e9fd6de

+ 11 - 0
apps/account/models.py

@@ -163,9 +163,20 @@ class SubEmployee(models.Model):
         )
 
 class Department(models.Model):
+    MATERIAL = 1
+    CONSUMABLE = 2
+    ALLPRODUCT = 3
+    PRODUCT_RANGE_CHOICES = (
+        (MATERIAL, u'原料'),
+        (CONSUMABLE, u'耗材'),
+        (ALLPRODUCT, u'全部'),
+    )
+
     name = models.CharField(max_length=100, verbose_name=u"名称")
     notes = models.CharField(max_length=500, verbose_name=u"备注",blank=True,null=True)
     parent_id = models.IntegerField(verbose_name=u"父部门",null=True,blank=True)
+    company = models.ForeignKey('Department', verbose_name=u"公司节点")
+    product_range = models.IntegerField(verbose_name=u"产品范围",null=True,blank=True)
     lft = models.IntegerField(verbose_name=u"左值")
     rgt = models.IntegerField(verbose_name=u"右值")
 

+ 25 - 5
apps/account/views.py

@@ -305,10 +305,17 @@ def department_list(request):
     result = []
     rows = Department.objects.filter()
     for row in rows:
+        isCompany = False
+        if row.id == row.company_id:
+            isCompany = True
         item = {
             '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,
             'notes': row.notes,
+            'isCompany': isCompany,
             'parent_id': row.parent_id or 0,
         }
         result.append(item)
@@ -324,18 +331,20 @@ def department_save(request):
     try:
         with transaction.atomic():
             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:
                 if parent_id:
                     parent = Department.getById(parent_id)
+                    company_id = parent.company_id
                     parent_id = parent.id
                 else:
                     parent = None
                     parent_id = None
+                    company_id = None
                 lft = Department.getLft(parent)
 
                 Department.objects.filter(rgt__gt=lft).update(rgt=F('rgt') + 2)
@@ -345,11 +354,22 @@ def department_save(request):
                     name=data['name'],
                     notes=data['notes'],
                     parent_id=parent_id,
+                    company_id=company_id,
                     lft=lft+1,
                     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))
+
+
+            if department.id == department.company_id and data['product_range']:
+                department.product_range = int(data['product_range'])
+                department.save()
+
     except CustomError, e:
         return JSONError(e.get_error_msg())
     except Exception, e:

+ 9 - 1
apps/purchase/views.py

@@ -19,7 +19,7 @@ from libs.http import JSONResponse, JSONError, DataGridJSONResponse
 from apps.exceptions import CustomError, ExportChange
 from apps.account.decorators import token_required, permission_required, valid_permission, isHasPermissions
 
-from apps.account.models import User
+from apps.account.models import User, Department
 from apps.foundation.models import BizLog, Option
 from apps.product.models import ProductBase
 from apps.warehouse.models import WarehouseRecord, Warehouse, WarehouseStockRecord, WarehouseRecordDetail
@@ -1583,6 +1583,14 @@ def search_product(request):
     warehouse_id = request.GET.get('warehouse')
     rows = ProductBase.objects.filter(enabled=True, type__lt=ProductBase.GOODS)
 
+    user_department = Department.getById(request.user.department.id)
+
+    if user_department.company.product_range:
+        if user_department.company.product_range == Department.MATERIAL:
+            rows = rows.filter(type=ProductBase.MATERIAL)
+        elif user_department.company.product_range == Department.CONSUMABLE:
+            rows = rows.filter(type=ProductBase.CONSUMABLE)
+
     if type:
         rows = rows.filter(type=int(type))
 

+ 4 - 3
uis/views/account/department.html

@@ -78,6 +78,7 @@
             cols: [[
                 {type:'checkbox',width:50},
                 {field: 'name', title: '名称',width:170},
+                {field: 'product_range_text', title: '产品范围',width:170},
                 {field: 'notes', title: '备注', minWidth:150},
                 {width:100,align:'left', fixed: 'right',templet: '#datagrid-operate-bar'}
             ]],
@@ -100,7 +101,7 @@
             type: 2,
             title: '修改',
             shadeClose: false,
-            area: ['500px', '270px'],
+            area: ['40%', '60%'],
             btn: ['保存', '取消'],
             yes: function(index, dom){
                layui.onSubmitChild = function (data) {
@@ -132,7 +133,7 @@
           type: 2,
           title: '添加',
           shadeClose: false,
-          area: ['500px', '270px'],
+          area: ['40%', '60%'],
           btn: ['保存', '取消'],
           yes: function(index, dom){
              layui.onSubmitChild = function (data) {
@@ -159,7 +160,7 @@
           type: 2,
           title: '添加',
           shadeClose: false,
-          area: ['500px', '270px'],
+          area: ['40%', '60%'],
           btn: ['保存', '取消'],
           yes: function(index, dom){
               layui.onSubmitChild = function (data) {

+ 17 - 0
uis/views/account/department_edit.html

@@ -26,6 +26,17 @@
                           </div>
                       </div>
 
+                      <div class="layui-col-md12" id="div_range">
+                        <label class="layui-form-label">产品范围:</label>
+                        <div class="layui-input-block">
+                          <select name="product_range">
+                             <option value="1">原料</option>
+                              <option value="2">耗材</option>
+                              <option value="3">全部</option>
+                          </select>
+                        </div>
+                    </div>
+
                       <div class="layui-col-md12">
                           <label class="layui-form-label">备注:</label>
                           <div class="layui-input-block">
@@ -65,8 +76,14 @@
         var editdata = JSON.parse(JSON.stringify(parent.layui.table.editdata)); // 框架有Bug所以这么转换
         form.val("component-form-element", editdata);
         url = '/account/department/save/?id='+id;
+        if (!editdata.isCompany) {
+            $("#div_range").hide();
+        }
     }else{
       url = '/account/department/save/?parent_id='+ parent_id;
+      if (parent_id) {
+          $("#div_range").hide();
+      }
     }
 
     form.on('submit(component-form-element)', function(data){