Selaa lähdekoodia

原料耗材区分

lyh 1 vuosi sitten
vanhempi
sitoutus
7b1e9fd6de

+ 11 - 0
apps/account/models.py

@@ -163,9 +163,20 @@ class SubEmployee(models.Model):
         )
         )
 
 
 class Department(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"名称")
     name = models.CharField(max_length=100, verbose_name=u"名称")
     notes = models.CharField(max_length=500, verbose_name=u"备注",blank=True,null=True)
     notes = models.CharField(max_length=500, verbose_name=u"备注",blank=True,null=True)
     parent_id = models.IntegerField(verbose_name=u"父部门",null=True,blank=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"左值")
     lft = models.IntegerField(verbose_name=u"左值")
     rgt = 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 = []
     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:

+ 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.exceptions import CustomError, ExportChange
 from apps.account.decorators import token_required, permission_required, valid_permission, isHasPermissions
 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.foundation.models import BizLog, Option
 from apps.product.models import ProductBase
 from apps.product.models import ProductBase
 from apps.warehouse.models import WarehouseRecord, Warehouse, WarehouseStockRecord, WarehouseRecordDetail
 from apps.warehouse.models import WarehouseRecord, Warehouse, WarehouseStockRecord, WarehouseRecordDetail
@@ -1583,6 +1583,14 @@ def search_product(request):
     warehouse_id = request.GET.get('warehouse')
     warehouse_id = request.GET.get('warehouse')
     rows = ProductBase.objects.filter(enabled=True, type__lt=ProductBase.GOODS)
     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:
     if type:
         rows = rows.filter(type=int(type))
         rows = rows.filter(type=int(type))
 
 

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

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

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

@@ -26,6 +26,17 @@
                           </div>
                           </div>
                       </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">
                       <div class="layui-col-md12">
                           <label class="layui-form-label">备注:</label>
                           <label class="layui-form-label">备注:</label>
                           <div class="layui-input-block">
                           <div class="layui-input-block">
@@ -65,8 +76,14 @@
         var editdata = JSON.parse(JSON.stringify(parent.layui.table.editdata)); // 框架有Bug所以这么转换
         var editdata = JSON.parse(JSON.stringify(parent.layui.table.editdata)); // 框架有Bug所以这么转换
         form.val("component-form-element", editdata);
         form.val("component-form-element", editdata);
         url = '/account/department/save/?id='+id;
         url = '/account/department/save/?id='+id;
+        if (!editdata.isCompany) {
+            $("#div_range").hide();
+        }
     }else{
     }else{
       url = '/account/department/save/?parent_id='+ parent_id;
       url = '/account/department/save/?parent_id='+ parent_id;
+      if (parent_id) {
+          $("#div_range").hide();
+      }
     }
     }
 
 
     form.on('submit(component-form-element)', function(data){
     form.on('submit(component-form-element)', function(data){