提交 f27bf620 authored 作者: 李思鑫's avatar 李思鑫

mes views sync

上级 0433212c
......@@ -27,6 +27,9 @@ sK = 'fgfdvgu$#&3t@j'
# 2023-07-24
from inventory.views import decrypt_11,decrypt_11h,LabelQuery
# 2024-10-11
from utils.security_os import decryptQueryString
#2020-10-27 11位解密
#def decrypt_11(code):
......@@ -98,6 +101,7 @@ def edit_Storehouse(request,id=None):
is_saved = True
return render(request,'mes/edit_storehouse.html',{'form':form,'is_saved':is_saved})
#lisin 2024-08-24 包材管理相关
#包材名称模糊搜索
@login_required
......@@ -158,6 +162,7 @@ def packaging_purchase_query(request):
return JsonResponse(data)
except PackagingInstore.DoesNotExist:
return JsonResponse({'error': 'id not found'}, status=404)
# 包材采购记录list
@login_required
def packaging_purchase_list(request):
......@@ -177,30 +182,22 @@ def packaging_purchase_list(request):
for r in cur.fetchall():
code_link = f"<a href='/mes/packaging/purchase/edit/{r[0]}'>{r[1]}<a/>"
data['data'].append([ code_link,r[2],r[3],r[4],r[5],r[6],r[7],float(r[8]),int(r[9]),float(r[10]) ])
return render(request,'obj/list_obj.html',data)
#包材采购记录添加/编辑
@login_required
def packaging_purchase_edit(request,id=None):
packaging = {
'id': '' ,
'name':''
}
if id is not None:
obj = PackagingPurchasRecord.objects.get(id=int(id))
packagingData = Packaging.objects.get(id=obj.packaging.id)
packaging = {
'id':packagingData.id,
'name':packagingData.name
}
else:
obj = PackagingPurchasRecord()
is_saved=False
company_id=request.user.company.id
obj.company = request.user.company
obj.company_id = company_id
# md_packaging = Packaging.objects.filter(company=request.user.company).all()
# md_vendor = Vendor.objects.filter(company=request.user.company).all()
md_packaging = Packaging.objects.filter(company=request.user.company).all()
md_vendor = Vendor.objects.filter(company=request.user.company).all()
if request.method == 'GET':
if id is None: #新增 创建编码
obj.code = create_code('CG')
......@@ -211,8 +208,8 @@ def packaging_purchase_edit(request,id=None):
if form.is_valid():
form.save()
is_saved = True
return render(request,'mes/packaging_purchase_edit.html',{'form':form,'is_saved':is_saved, 'packaging':packaging})
return render(request,'mes/packaging_purchase_edit.html',{'form':form,'is_saved':is_saved,
'md_packaging':md_packaging, 'md_vendor':md_vendor})
#包材入库记录list
@login_required
......@@ -513,7 +510,7 @@ def edit_batch(request,vtype_id,id=None):
if id:
obj=Batch.objects.get(id=int(id))
else:
obj=Batch(company_id=c.id,user_id=u.id)
obj=Batch(company_id=c.id,user_id=u.id,dt_voucher=datetime.datetime.now())
obj.vtype_id=int(vtype_id)
unit_ids=[]
units=[]
......@@ -576,9 +573,9 @@ def list_obj(request,what):
return render(request,'mes/list_order.html',data)
elif what=='vendor':
data['subtt']=[_('供应商与客户'),_('供应商')]
data['clmns']=[_('供应商名称'),_('供应商外部编码'),_('详细地址'),_('联系人'),_('联系电话'),_('备注说明'),_('操作')]
data['clmns']=[_('供应商名称'),_('详细地址'),_('联系电话'),_('备注说明'),_('操作')]
d=[]
s="SELECT id,name,coalesce(external_code,'/'),coalesce(address,''),coalesce(contents,'/'),coalesce(cellphone,''),coalesce(remark,'') "+\
s="SELECT id,name,coalesce(address,''),coalesce(cellphone,''),coalesce(remark,'') "+\
"FROM mes_vendor where company_id="+str(c.id)+" and is_delete is false"
cur.execute(s)
for r in cur.fetchall():
......@@ -586,7 +583,7 @@ def list_obj(request,what):
if data['show_add']:
a='<a class="edt" href="/mes/edit/vendor/'+str(r[0])+'/">'+r[1]+'</a>'
btn = '<a class="btn btn-sm btn-default" href="/mes/edit/vendorPhotos/'+str(r[0])+'">资质图片管理</a>'
d.append([ a,r[2],r[3],r[4],r[5],r[6],btn ])
d.append([ a,r[2],r[3],r[4],btn ])
data['data']=d
elif what=='customer':
data['subtt']=[_('供应商与客户'),_('代工客户')]
......@@ -1120,6 +1117,9 @@ def label_tb_check(tb):
"""
检查号段表是否存在,不存在就创建
"""
# 2024-07-29
tb=tb.lower()
s="select count(*) from information_schema.tables where table_schema='label' "+\
"and table_type='BASE TABLE' and table_name='"+tb+"'"
cur=connection.cursor()
......@@ -1129,7 +1129,7 @@ def label_tb_check(tb):
s="CREATE TABLE label."+tb+"("+\
"CONSTRAINT "+tb+"_id_pk PRIMARY KEY(id),"+\
"CONSTRAINT "+tb+"_code_unique UNIQUE(code),"\
"CONSTRAINT "+tb+"_code_check CHECK(\"left\"(code::text,4)='"+tb[-4:]+"'::text)"+\
"CONSTRAINT "+tb+"_code_check CHECK(\"left\"(code::text,4)='"+tb[-4:].upper()+"'::text)"+\
") INHERITS (label.labelinfo);"+\
"ALTER TABLE label."+tb+" OWNER TO acc;"+\
"CREATE INDEX "+tb+"_category_idx ON label."+tb+" USING btree(category_id);"+\
......@@ -1144,7 +1144,10 @@ def label_tb_check(tb):
def carton_tb_check(tb):
"""
检查号段表是否存在,不存在就创建
"""
"""
# 2024-07-29
tb=tb.lower()
s="select count(*) from information_schema.tables where table_schema='carton' "+\
"and table_type='BASE TABLE' and table_name='"+tb+"'"
cur=connection.cursor()
......@@ -1154,9 +1157,9 @@ def carton_tb_check(tb):
s="CREATE TABLE carton."+tb+"("+\
"CONSTRAINT "+tb+"_id_pk PRIMARY KEY(id),"+\
"CONSTRAINT "+tb+"_code_unique UNIQUE(code),"\
"CONSTRAINT "+tb+"_code_check CHECK(\"left\"(code::text,4)='"+tb[-4:]+"'::text)"+\
"CONSTRAINT "+tb+"_code_check CHECK(\"left\"(lower(code)::text,4)='"+tb[-4:]+"'::text)"+\
") INHERITS (carton.cartoninfo);"+\
"ALTER TABLE carton."+tb+" OWNER TO acc;"+\
"ALTER TABLE carton."+tb+" OWNER TO tjfw;"+\
"CREATE INDEX "+tb+"_code_idx ON carton."+tb+" USING btree(code COLLATE pg_catalog.\"default\");"+\
"CREATE INDEX "+tb+"_company_idx ON carton."+tb+" USING btree(company_id);"+\
"CREATE INDEX "+tb+"_dt_idx ON carton."+tb+" USING btree(dt);"+\
......@@ -1224,8 +1227,11 @@ def label_bind(request,company_id,action,what,thirdparty=None):
cur.execute("select id,name from inventory_storehouse where company_id="+company_id)
for r in cur.fetchall() :
data['stores'].append({'id':r[0],'name':r[1]})
if company_id in ['180087',]:
# 吉林康庄大道农业发展有限公司
# 2024-10-08
#if company_id in ['180087',]:
#if company_id in ['180087','243885',]:
if True:
# 吉林康庄大道农业发展有限公司 辽宁铁研种业科技有限公司
# 种子来源地 追加返回一级行政区划
adms=[]
# 不包含港澳台
......@@ -1436,7 +1442,9 @@ def label_bind(request,company_id,action,what,thirdparty=None):
if store:
store_id=str(store[0])
product_id=str(r['product_id'])
batch_no="'"+r['batch_no']+"'"
batch_no='null'
if 'batch_no' in r:
batch_no="'"+r['batch_no']+"'"
#if 'remark' in r:
# remark="'"+r['remark']+"'"
......@@ -1899,8 +1907,8 @@ def label_bind(request,company_id,action,what,thirdparty=None):
else:
d_tbs[tb]=["("+company_id+","+type_id+","+cat_id+","+p_tb+","+\
"'"+bcd+"',1,"+x_id+",false,false,true,"+remark+")"]
# 盒标号段数组
bottle_tb.append(bcd[:4])
# 瓶标号段数组 2024-07-25
bottle_tb.append(bcd[:4].lower())
for t in d_tbs:
s="insert into label.t"+t+"("+flds_lbl+") values"+",".join(d_tbs[t])+\
......@@ -1944,6 +1952,227 @@ def label_bind(request,company_id,action,what,thirdparty=None):
")"
cur.execute(s)
data['cnt']=1
# 2024-09-11
elif what=='STACK':
# 垛标绑箱标
stack=None
cartons=[]
if 'stack' in r:
stack=r['stack']
if 'cartons' in r:
cartons=r['cartons']
if stack and cartons:
a=[]
# 2024-10-12 辽宁铁研,设备没有按常规上传,每一大袋都传一次垛码
b_exists=False
if company_id in ['243885']:
s="select id from inventory_stack where code='"+stack+"' and company_id="+company_id
cur.execute(s)
rr=cur.fetchone()
if rr:
id=str(rr[0])
b_exists=True
if not b_exists:
s="INSERT INTO inventory_stack(code,qty_lmt,company_id,store_id,product_id,user_id,remark) "+\
" values ('"+stack+"',"+str(len(cartons))+","+company_id+","+store_id+","+product_id+","+user_id+","+remark+") "+\
"returning id"
cur.execute(s)
rr=cur.fetchone()
id=str(rr[0])
# 2024-09-25 跟第三方确认,数据上传要先传箱瓶绑定,再传垛标绑定,即要确保箱标在标签表内存在
for c in cartons:
a.append("("+product_id+",3,'"+c+"',"+id+","+company_id+","+\
"(select id from label.t"+c[:4].lower()+" where code='"+c+"'),"+\
"(select coalesce(parent_id,id) from label.t"+c[:4].lower()+" where code='"+c+"')"+\
")")
# 2024-09-25
s="INSERT INTO inventory_stackdetails(product_id,label_pkg,label_code,stack_id,company_id,label_id,label_pk_id) "+\
" VALUES "+",".join(a)+" on conflict do nothing"
cur.execute(s)
data['cnt']=cur.rowcount
else:
data['e']='cartons and stack required'
# 2024-10-10 怀庄大坛酒不贴二/三维码标签,箱子、盒子、坛子各一枚NFC标签,扫码枪成套上传
elif what=='NFC':
# 安全起见,把nfc数据写入标签nfc表
nfcs=[]
# 厂家可能会指定生产日期
tm='now()'
dt='now()'
if 'dt_product' in r:
dt="'"+r['dt_product']+"'"
tm="'"+r['dt_product']+" "+datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')[-8:]+"'"
cnt=0
d=r['data']
# 收藏码 treasure_code
treasure_code='null'
if 'treasure_code' in d:
if d['treasure_code']:
treasure_code="'"+str(d['treasure_code'])+"'"
# 套标关系
cs=d['codes']
#{'cartons':[{'code':'A64A6CF85BA83245F7384A5C840A513C'}],'boxes':[{'code':'A64A6CF85BA83245906873155F7E6011','bottles':[{'code':'A64A6CF85BA832453828DF051EC0001D'}]}],'bottles':[]}
# 箱盒瓶标
xs=cs['cartons']
hs=cs['boxes']
ps=cs['bottles']
if (hs and ps) or ( not hs and not ps):
data['e']='数据格式错误,boxes和bottles不能同时有值或同时为空'
return JsonResponse(data)
remark="'NFC as Label'"
x=xs[0]
# 主箱标
n=xs[0]['code']
l=decryptQueryString(n)
# 目前,绑定的NFC(前4位)都在同一个号段 号段表是否存在,不存在自动创建
label_tb_check("t"+l[:4])
#flds_lbl="company_id,type_id,category_id,parent_tb,code,package_id,parent_id,is_pk,is_related,is_active,remark"
# INSERT INTO label.lbl_nfc(company_id,label_code,nfc,label_pk_id,label_id,label_pkg,treasure_code)
s="insert into label.t"+l[:4]+"("+flds_lbl+") values ("+\
company_id+","+type_id+","+cat_id+",null,'"+l+"',3,null,true,false,true,"+remark+") "+\
"on conflict(code) do update set parent_id=excluded.parent_id,tm=now(),remark=excluded.remark "+\
"returning id"
cur.execute(s)
rr=cur.fetchone()
# 主箱标id
x_id=str(rr[0])
# 主箱标号码
x_code=l
# 盒箱绑定数组
hxs=[]
# 瓶盒绑定数组
phs=[]
# 瓶箱绑定数组
pxs=[]
# 删除标记 盒
del_h=[]
nfcs.append("("+company_id+",'"+l+"','"+n+"',"+x_id+","+x_id+",3,"+treasure_code+","+dt+","+product_id+")")
cnt=cnt+1
# 箱上是否有多个nfc
i=1
while i<len(xs):
x=xs[i]
n=x['code']
l=decryptQueryString(n)
s="insert into label.t"+l[:4]+"("+flds_lbl+") values ("+\
company_id+","+type_id+","+cat_id+",null,'"+l+"',3,"+xid+",false,true,true,"+remark+") "+\
"on conflict(code) do update set parent_id=excluded.parent_id,tm=now(),remark=excluded.remark "+\
"returning id"
cur.execute(s)
rr=cur.fetchone()
id=str(rr[0])
nfcs.append("("+company_id+",'"+l+"','"+n+"',"+x_id+","+id+",3,"+treasure_code+","+dt+","+product_id+")")
i=i+1
cnt=cnt+1
#del_x.append("'"+l+"'")
if hs:
# 箱盒瓶三绑定
# 盒标
sIns="INSERT INTO mes_labelbindph(company_id,product_id,store_id,user_id,batch_no,"+\
"prd_shop,prd_line,prd_team,qc,remark,box_code,bottle_code)"
for h in hs:
n=h['code']
l=decryptQueryString(n)
hxs.append("("+company_id+","+product_id+","+store_id+","+user_id+","+batch_no+","+\
prd_shop+","+prd_line+","+prd_team+","+qc+","+remark+",'"+x_code+"','"+l+"',"+dt+","+tm+\
")"
)
del_h.append("'"+l+"'")
s="insert into label.t"+l[:4]+"("+flds_lbl+") values ("+\
company_id+","+type_id+","+cat_id+",null,'"+l+"',2,"+x_id+",false,false,true,"+remark+") "+\
"on conflict(code) do update set parent_id=excluded.parent_id,tm=now(),remark=excluded.remark "+\
"returning id"
cur.execute(s)
rr=cur.fetchone()
h_id=str(rr[0])
h_code=l
nfcs.append("("+company_id+",'"+l+"','"+n+"',"+x_id+","+h_id+",2,"+treasure_code+","+dt+","+product_id+")")
cnt=cnt+1
for b in h['bottles']:
# 瓶标
n=b['code']
l=decryptQueryString(n)
phs.append("("+company_id+","+product_id+","+store_id+","+user_id+","+batch_no+","+\
prd_shop+","+prd_line+","+prd_team+","+qc+","+remark+",'"+h_code+"','"+l+"',"+dt+","+tm+")"
)
s="insert into label.t"+l[:4]+"("+flds_lbl+") values ("+\
company_id+","+type_id+","+cat_id+",null,'"+l+"',1,"+h_id+",false,false,true,"+remark+") "+\
"on conflict(code) do update set parent_id=excluded.parent_id,tm=now(),remark=excluded.remark "+\
"returning id"
cur.execute(s)
rr=cur.fetchone()
id=str(rr[0])
nfcs.append("("+company_id+",'"+l+"','"+n+"',"+x_id+","+id+",1,"+treasure_code+","+dt+","+product_id+")")
cnt=cnt+1
elif ps:
# 箱瓶二级绑定
for p in ps:
# 瓶标
n=p['code']
l=decryptQueryString(n)
pxs.append("("+company_id+","+product_id+","+store_id+","+user_id+","+batch_no+","+\
prd_shop+","+prd_line+","+prd_team+","+qc+","+remark+",'"+x_code+"','"+l+"'"+dt+","+tm+")"
)
s="insert into label.t"+l[:4]+"("+flds_lbl+") values ("+\
company_id+","+type_id+","+cat_id+",null,'"+l+"',1,"+x_id+",false,false,true,"+remark+") "+\
"on conflict(code) do update set parent_id=excluded.parent_id,tm=now(),remark=excluded.remark "+\
"returning id"
cur.execute(s)
rr=cur.fetchone()
id=str(rr[0])
nfcs.append("("+company_id+",'"+l+"','"+n+"',"+x_id+","+id+",1,"+treasure_code+","+dt+","+product_id+")")
cnt=cnt+1
# 写入label.lbl_nfc绑定
s="INSERT INTO label.lbl_nfc(company_id,label_code,nfc,label_pk_id,label_id,label_pkg,treasure_code,dt_product,product_id) "+\
"values " + ",".join(nfcs)+" on conflict do nothing"
cur.execute(s)
# MES 需打删除标记的记录
if del_h:
# 箱盒瓶三绑定
cur.execute("update mes_labelbindhx set is_delete=true where carton_code='"+x_code+"'")
cur.execute("update mes_labelbindph set is_delete=true where box_code in ("+",".join(del_h)+")")
else:
# 箱瓶二级绑定
cur.execute("update mes_labelbindpx set is_delete=true where carton_code='"+x_code+"'")
# 写入MES在线绑定表
if pxs:
s="INSERT INTO mes_labelbindpx(company_id,product_id,store_id,user_id,batch_no,"+\
"prd_shop,prd_line,prd_team,qc,remark,carton_code,bottle_code,dt,tm)"+\
" values "+",".join(pxs)
cur.execute(s)
if phs:
s="INSERT INTO mes_labelbindph(company_id,product_id,store_id,user_id,batch_no,"+\
"prd_shop,prd_line,prd_team,qc,remark,box_code,bottle_code,dt,tm)"+\
" values "+",".join(phs)
cur.execute(s)
if hxs:
s="INSERT INTO mes_labelbindhx(company_id,product_id,store_id,user_id,batch_no,"+\
"prd_shop,prd_line,prd_team,qc,remark,carton_code,box_code,dt,tm)"+\
" values "+",".join(hxs)
cur.execute(s)
data['cnt']=cnt
# 2022-12-12 组合包装产品
elif action=='component':
......@@ -2061,11 +2290,21 @@ def label_bind(request,company_id,action,what,thirdparty=None):
else:
remark="null"
# 2024-09-10
qc_no='null'
section='null'
if 'qc_no' in r:
if r['qc_no']:
qc_no="'"+r['qc_no']+"'"
if 'section' in r:
if r['section']:
section="'"+r['section']+"'"
# 2023-10-26 西凤老绿瓶模式瓶盖绑定数据
# 现只考虑上传西凤模式盖码数据,即内(加密码)外码(10位16进制)由瓶盖厂绑定;酒厂扫盖外码与瓶(盒)标绑定
if what.upper()=='CAP':
lmt=10 # 数组长度达到此长度,写入一次临时表
lmt=1000 # 数组长度达到此长度,写入一次临时表
tb='mes_bottlcap'
tmp="codes"
s="create temp table "+tmp+"("+\
......@@ -2080,19 +2319,34 @@ def label_bind(request,company_id,action,what,thirdparty=None):
n=0
tt=0
ok=0
sIns="INSERT INTO "+tmp+"(label_code,cap,outter,label_pkg,duplications)"
#sIns="INSERT INTO "+tmp+"(label_code,cap,outter,label_pkg,duplications)"
# 2024-07-19 大批量导入,不再检查重复数据
sIns="INSERT INTO "+tmp+"(label_code,cap,outter,label_pkg)"
for d in r['details']:
b=d['label_code'] # 瓶标
g=d['cap'] # 盖内码
o=d['outer'] # 盖外码
if len(o)==10 and len(b)==12 and b.isdigit():
g = "(select cap from bottlecap.fcty_binding_details where outter='" + o.upper() + "' ORDER BY tm LIMIT 1)"
#if len(o)==10 and len(b)==12 and b.isdigit():
# 2024-07-25 蒙古王 激光码 以字母JD(酒店)或LT(流通)开头跟13个数字
if len(o)==10 :
g = "(select cap from bottlecap.fcty_binding_details where outter='" + o.upper() + "' ORDER BY tm LIMIT 1)"
# 2024-07-18 盖外码已分表
g= "(select cap from bottlecap.fo"+str(int(o,16))[:4]+" where outter='"+ o.upper()+"')"
o="'"+o+"'"
a.append("('"+b+"',"+g+","+o+","+str(d['label_pkg'])+","+\
"(select jsonb_agg(jsonb_build_object("+\
"'id',id, 'label_code',label_code, 'label_pkg',label_pkg, 'cap',cap, 'outter',outter"+\
")) from "+tb+" where (label_code='"+b+"' or outter='"+d['outer']+"') and is_delete=false"+\
"))")
#a.append("('"+b+"',"+g+","+o+","+str(d['label_pkg'])+","+\
# "(select jsonb_agg(jsonb_build_object("+\
# "'id',id, 'label_code',label_code, 'label_pkg',label_pkg, 'cap',cap, 'outter',outter"+\
# ")) from "+tb+" where (label_code='"+b+"' or outter='"+d['outer']+"') and is_delete=false"+\
# "))")
# 2024-07-19 大批量导入,不再检查重复数据
a.append("('"+b+"',"+g+","+o+","+str(d['label_pkg'])+")")
n=n+1
if n==lmt:
cur.execute(sIns+" values "+",".join(a))
......@@ -2104,26 +2358,38 @@ def label_bind(request,company_id,action,what,thirdparty=None):
tt=tt+cur.rowcount
if tt:
# 先写入瓶盖绑定明细
#s="INSERT INTO "+tb+"(company_id,product_id,store_id,user_id,batch_no,"+\
# "prd_shop,prd_line,prd_team,qc,remark,"+\
# "label_code,cap,outter,label_pkg) select "+\
# company_id+","+product_id+","+store_id+","+user_id+","+batch_no+","+\
# prd_shop+","+prd_line+","+prd_team+","+qc+","+remark+","+\
# "label_code,cap,outter,label_pkg from "+\
# "(select label_code,cap,outter,label_pkg from "+tmp+" group by label_code,cap,outter,label_pkg) g"
# 2024-09-10
s="INSERT INTO "+tb+"(company_id,product_id,store_id,user_id,batch_no,"+\
"prd_shop,prd_line,prd_team,qc,remark,"+\
"label_code,cap,outter,label_pkg) select "+\
"label_code,cap,outter,label_pkg,qc_no,section) select "+\
company_id+","+product_id+","+store_id+","+user_id+","+batch_no+","+\
prd_shop+","+prd_line+","+prd_team+","+qc+","+remark+","+\
"label_code,cap,outter,label_pkg from "+\
"label_code,cap,outter,label_pkg,"+qc_no+","+section+" from "+\
"(select label_code,cap,outter,label_pkg from "+tmp+" group by label_code,cap,outter,label_pkg) g"
cur.execute(s)
ok=ok+cur.rowcount
# 写入重复绑定表 如果有
s="INSERT INTO mes_labelbindduplicate(company_id,user_id,portal,label_parent,label_child,duplications) select "+\
company_id+","+user_id+",'CAP',label_code,outter,duplications from "+tmp+" where jsonb_array_length(duplications)>0"
cur.execute(s)
# 2024-07-19 大批量导入,不再检查重复数据
#s="INSERT INTO mes_labelbindduplicate(company_id,user_id,portal,label_parent,label_child,duplications) select "+\
# company_id+","+user_id+",'CAP',label_code,outter,duplications from "+tmp+" where jsonb_array_length(duplications)>0"
#cur.execute(s)
# 重复数据打删除标记 如果有
s="update "+tb+" set is_delete=true where id in ("+\
"select id from (SELECT (jsonb_array_elements(duplications)->>'id')::int id FROM "+tmp+" "+\
"where jsonb_array_length(duplications)>0) t "+\
"group by t.id "+\
")"
cur.execute(s)
# 2024-07-19 大批量导入,不再检查重复数据
#s="update "+tb+" set is_delete=true where id in ("+\
# "select id from (SELECT (jsonb_array_elements(duplications)->>'id')::int id FROM "+tmp+" "+\
# "where jsonb_array_length(duplications)>0) t "+\
# "group by t.id "+\
# ")"
#cur.execute(s)
data={'e':'','cnt':tt,'cnt_ok':ok}
return JsonResponse(data)
......@@ -2136,16 +2402,30 @@ def label_bind(request,company_id,action,what,thirdparty=None):
remark="'离线,套标关系未写入'"
for d in r['details']:
#a.append("("+company_id+","+product_id+","+store_id+","+user_id+","+batch_no+","+\
# prd_shop+","+prd_line+","+prd_team+","+qc+","+remark+","+\
# "'"+d['box']+"','"+d['bottle']+"'"+\
#")")
# 2024-09-10
a.append("("+company_id+","+product_id+","+store_id+","+user_id+","+batch_no+","+\
prd_shop+","+prd_line+","+prd_team+","+qc+","+remark+","+\
"'"+d['box']+"','"+d['bottle']+"'"+\
")")
"'"+d['box']+"','"+d['bottle']+"',"+qc_no+","+section+\
")")
# 插入mes绑定明细
#cur.execute("INSERT INTO "+tb+"("+\
# "company_id,product_id,store_id,user_id,batch_no,"+\
# "prd_shop,prd_line,prd_team,qc,remark,"+\
# "box_code,bottle_code) values "+",".join(a)
#)
# 2024-09-10
cur.execute("INSERT INTO "+tb+"("+\
"company_id,product_id,store_id,user_id,batch_no,"+\
"prd_shop,prd_line,prd_team,qc,remark,"+\
"box_code,bottle_code) values "+",".join(a)
"box_code,bottle_code,qc_no,section) values "+",".join(a)
)
data['cnt']=cur.rowcount
cur.close()
return JsonResponse(data)
......@@ -2168,7 +2448,7 @@ def label_bind(request,company_id,action,what,thirdparty=None):
m=d['main_code'][0]
else:
m=d['main_code']
mt="'"+m[:4]+"'"
mt="'"+m[:4].lower()+"'"
mc="'"+m+"'"
rc='null'
rt='null'
......@@ -2201,14 +2481,24 @@ def label_bind(request,company_id,action,what,thirdparty=None):
cur.execute(s)
# 插入mes绑定明细
#cur.execute("INSERT INTO "+tb_mes+"("+\
# "company_id,product_id,store_id,user_id,batch_no,"+\
# "prd_shop,prd_line,prd_team,qc,remark,"+\
# "carton_code,carton_related,"+fld_c+\
# ") select "+\
# company_id+","+product_id+","+store_id+","+user_id+","+batch_no+","+\
# prd_shop+","+prd_line+","+prd_team+","+qc+","+remark+","+\
# "main_code,related_code,child_code from codes"
#)
# 2024-09-10
cur.execute("INSERT INTO "+tb_mes+"("+\
"company_id,product_id,store_id,user_id,batch_no,"+\
"prd_shop,prd_line,prd_team,qc,remark,"+\
"carton_code,carton_related,"+fld_c+\
"carton_code,carton_related,"+fld_c+",qc_no,section"+\
") select "+\
company_id+","+product_id+","+store_id+","+user_id+","+batch_no+","+\
prd_shop+","+prd_line+","+prd_team+","+qc+","+remark+","+\
"main_code,related_code,child_code from codes"
"main_code,related_code,child_code,"+qc_no+","+section+" from codes"
)
flds_lbl="company_id,type_id,category_id,parent_tb,code,package_id,parent_id,is_pk,is_related,is_active,remark"
......@@ -2216,6 +2506,9 @@ def label_bind(request,company_id,action,what,thirdparty=None):
cur.execute("select main_tb from codes group by main_tb")
rs=cur.fetchall()
for rr in rs:
# 2024-07-25 表若不存在,创建
label_tb_check('t'+rr[0])
cur.execute("insert into label.t"+rr[0]+"("+flds_lbl+") select "+\
company_id+","+type_id+","+cat_id+",null,main_code,3,null,true,false,true,"+remark+" "+\
"from (select main_code from codes where main_tb='"+rr[0]+"' group by main_code) a "+\
......@@ -2233,7 +2526,8 @@ def label_bind(request,company_id,action,what,thirdparty=None):
for r0 in rs0:
p_tb='null'
if rr[0]!=r0[0]:
p_tb="'"+rr[0]+"'"
p_tb="'"+rr[0]+"'"
cur.execute("insert into label.t"+rr[0]+"("+flds_lbl+") select "+\
company_id+","+type_id+","+cat_id+","+p_tb+",related_code,3,"+\
"label_pk_id,false,true,true,"+remark+" "+\
......@@ -2250,8 +2544,14 @@ def label_bind(request,company_id,action,what,thirdparty=None):
for r0 in rs0:
p_tb='null'
if rr[0]!=r0[0]:
p_tb="'"+rr[0]+"'"
cur.execute("insert into label.t"+rr[0]+"("+flds_lbl+") select "+\
p_tb="'"+r0[0]+"'"
# 2024-07-25 跨段,检查carton表是否存在
if what[-1]=='X': # PX HX 绑定
carton_tb_check('t'+r0[0])
# 2024-07-25 标签表若不存在,创建
label_tb_check('t'+rr[0])
cur.execute("insert into label.t"+rr[0].lower()+"("+flds_lbl+") select "+\
company_id+","+type_id+","+cat_id+","+p_tb+",child_code,"+c_pkg+","+\
"label_pk_id,false,false,true,"+remark+" "+\
"from (select label_pk_id,child_code from codes where child_tb='"+rr[0]+"' "+\
......@@ -2268,22 +2568,31 @@ def label_bind(request,company_id,action,what,thirdparty=None):
s="INSERT INTO carton.t"+rr[0]+"(code,level,"+c_tb+",company_id,tm,dt,remark) select "+\
"main_code,"+lv+",tbs,"+\
company_id+",now(),now(),"+remark+" from "+\
"(select main_code,array_to_string(array"+\
"(select child_tb from codes where main_code=g.main_code group by child_tb),',') tbs "+\
"(select main_code,lower(array_to_string(array"+\
"(select child_tb from codes where main_code=g.main_code group by child_tb),',')) tbs "+\
"from "+\
"(select main_code from codes where main_tb='"+rr[0]+"' group by main_code) g "+\
") a "+\
"on conflict(code) do update set level=excluded.level,box_tb=excluded.box_tb,bottle_tb=excluded.bottle_tb,"+\
"company_id=excluded.company_id,remark=excluded.remark,dt=now(),tm=now()"
"company_id=excluded.company_id,remark=excluded.remark,dt=now(),tm=now()"
cur.execute(s)
tb_stk="stkdetails.c"+company_id
tb_stk="stkdetails.c"+company_id
# 自动入库
uid=14499 # 以system身份做入库
cid=int(company_id)
b=Batch(code=batch_no.replace("'",''), level_id=1, vtype_id=1, company_id=cid, hierarchy_id=cid, ancestor_id=cid, product_id=product_id,
company_fr_id=cid, user_id=uid, voucher_id=1, version=0,store_fr_id=int(store_id), remark=remark
)
# 2024-09-10
if qc_no!='null':
b.qc_no=qc_no
if section!='null':
b.section=section
b.save()
# 写入batch_details
s="insert into inventory_batchdetails(batch_id,label_code,label_id,label_pkg,tm,label_pk_id,company_id,ancestor_id,product_id,label_code0) select " +\
......@@ -2367,7 +2676,7 @@ def product_bind(request,action,what=None):
if cid.__eq__(19267):
data = {'data': [],
'clmns': ['日期', '生产时间', '产品', '包装规格', '生产批次号', '仓库', '产量', '待入库', '备注', '单行入库'],
'dt_fr': dt_fr, 'dt_to': dt_to, 'qty_uninbound': 0}
'dt_fr': dt_fr, 'dt_to': dt_to, 'qty_uninbound': 0, 'cid': cid}
s = "select to_char(g.dt,'yyyy-mm-dd'),to_char(tm1,'HH24:MI:SS')||'--'||to_char(tm2,'HH24:MI:ss')," + \
"coalesce(prd_line,''),coalesce((select name from product_product where id=product_id),'')," + \
"coalesce(batch_no,''),coalesce((select name from inventory_storehouse where id=store_id),''),qty,lv," + \
......@@ -2392,39 +2701,67 @@ def product_bind(request,action,what=None):
") h " + \
"group by prd_line,batch_no,store_id,product_id,dt" + \
") g"
# 2024-09-04
s = "select to_char(g.dt,'yyyy-mm-dd'),to_char(tm1,'HH24:MI:SS')||'--'||to_char(tm2,'HH24:MI:ss')," + \
"coalesce(prd_line,''),coalesce((select name from product_product where id=product_id),'')," + \
"coalesce(batch_no,''),coalesce((select name from inventory_storehouse where id=store_id),''),qty,lv," + \
"(select count(*) from mes_labelbindhx" + sWhere + " and inbound=false " + \
"and product_id=g.product_id and batch_no=g.batch_no and store_id=g.store_id and dt=g.dt)+" + \
"(select count(*) from mes_labelbindpx" + sWhere + " and inbound=false " + \
"and product_id=g.product_id and batch_no=g.batch_no and store_id=g.store_id and dt=g.dt) qty_inbound, " + \
"q0,coalesce((SELECT value FROM product_productprop where company_id=" + cid + " and categoryprop_id=" + \
"(SELECT id FROM company_categoryprop where name=case when category_id=7 then 'specification' else 'package' end " + \
"and category_id=(select category_id from company_company where id=" + cid + ")) " + \
"and id in (select prd_property_id from product_prdprops where product_id=g.product_id) limit 1),''),g.dt,product_id,coalesce(store_id,0) " + \
"from " + \
"(select min(tm1) tm1,max(tm2) tm2,prd_line,batch_no,store_id,product_id,count(*) qty,'三级绑定' lv,sum(q0) q0,dt from " + \
"(select min(tm) tm1,max(tm) tm2,prd_line,batch_no,store_id,product_id,carton_code,count(*) q0,dt FROM mes_labelbindhx" + sWhere + \
"group by prd_line,batch_no,store_id,product_id,carton_code,dt" + \
") h " + \
"group by prd_line,batch_no,store_id,product_id,dt " + \
"union all " + \
"select min(tm1) tm1,max(tm2) tm2,prd_line,batch_no,store_id,product_id,count(*) qty,'二级绑定' lv,sum(q0),dt from " + \
"(select min(tm) tm1,max(tm) tm2,prd_line,batch_no,store_id,product_id,carton_code,count(*) q0,dt FROM mes_labelbindpx" + sWhere + \
"group by prd_line,batch_no,store_id,product_id,carton_code,dt" + \
") h " + \
"group by prd_line,batch_no,store_id,product_id,dt" + \
") g"
# 2023-10-18
if cid in ['180087',]:
data['clmns']=['日期','生产时间','产品','包装规格','生产批次号','制种产地','仓库','产量','待入库','备注']
# 2024-10-16
if cid in ['180087','243885']:
#data['clmns']=['日期','生产时间','产品','包装规格','生产批次号','制种产地','仓库','产量','待入库','备注']
data['clmns']=['日期','车间','产线','生产时间','产品','包装规格','生产批次号','制种产地','仓库','产量','待入库','备注']
s="select to_char(g.dt,'yyyy-mm-dd'),to_char(tm1,'HH24:MI:SS')||'--'||to_char(tm2,'HH24:MI:ss'),"+\
"coalesce(prd_line,''),coalesce((select name from product_product where id=product_id),''),"+\
"coalesce(batch_no,''),coalesce((select name from inventory_storehouse where id=store_id),''),qty,lv,"+\
"(select count(*) from mes_labelbindhx"+sWhere+" and inbound=false "+\
"and product_id=g.product_id and batch_no=g.batch_no and store_id=g.store_id and dt=g.dt)+"+\
"and prd_line=g.prd_line and prd_shop=g.prd_shop and product_id=g.product_id and batch_no=g.batch_no and store_id=g.store_id and dt=g.dt)+"+\
"(select count(*) from mes_labelbindpx"+sWhere+" and inbound=false "+\
"and product_id=g.product_id and batch_no=g.batch_no and store_id=g.store_id and dt=g.dt) qty_inbound, "+\
"and coalesce(prd_line,'')=g.prd_line and coalesce(prd_shop,'')=g.prd_shop and product_id=g.product_id and batch_no=g.batch_no and store_id=g.store_id and dt=g.dt) qty_inbound, "+\
"q0,coalesce((SELECT value FROM product_productprop where company_id="+cid+" and categoryprop_id="+\
"(SELECT id FROM company_categoryprop where name='package' "+\
"and category_id=(select category_id from company_company where id="+cid+")) "+\
"and id in (select prd_property_id from product_prdprops where product_id=g.product_id) limit 1),''),g.dt,"+\
"(select name from gis.adm_map_cn where id=origin_adm_id) "+\
"(select name from gis.adm_map_cn where id=origin_adm_id),"+\
"coalesce(prd_shop,''),coalesce(qc,'') "+\
"from "+\
"(select min(tm1) tm1,max(tm2) tm2,prd_line,batch_no,store_id,product_id,count(*) qty,'三级绑定' lv,sum(q0) q0,dt,null origin_adm_id from "+\
"(select min(tm) tm1,max(tm) tm2,prd_line,batch_no,store_id,product_id,carton_code,count(*) q0,dt FROM mes_labelbindhx"+sWhere+\
"group by prd_line,batch_no,store_id,product_id,carton_code,dt"+\
"(select min(tm1) tm1,max(tm2) tm2,prd_line,batch_no,store_id,product_id,count(*) qty,'三级绑定' lv,sum(q0) q0,dt,null origin_adm_id,prd_shop,qc from "+\
"(select min(tm) tm1,max(tm) tm2,coalesce(prd_line,'') prd_line,coalesce(prd_shop,'') prd_shop,coalesce(qc,'') qc,"+\
"batch_no,store_id,product_id,carton_code,count(*) q0,dt FROM mes_labelbindhx"+sWhere+\
"group by prd_line,prd_shop,qc,batch_no,store_id,product_id,carton_code,dt"+\
") h "+\
"group by prd_line,batch_no,store_id,product_id,dt "+\
"group by prd_line,prd_shop,qc,batch_no,store_id,product_id,dt "+\
"union all "+\
"select min(tm1) tm1,max(tm2) tm2,prd_line,batch_no,store_id,product_id,count(*) qty,'二级绑定' lv,sum(q0),dt,origin_adm_id from "+\
"(select min(tm) tm1,max(tm) tm2,prd_line,batch_no,store_id,product_id,carton_code,count(*) q0,dt,origin_adm_id FROM mes_labelbindpx"+sWhere+\
"group by prd_line,batch_no,store_id,product_id,carton_code,dt,origin_adm_id"+\
"select min(tm1) tm1,max(tm2) tm2,prd_line,batch_no,store_id,product_id,count(*) qty,'二级绑定' lv,sum(q0),dt,origin_adm_id,prd_shop,qc from "+\
"(select min(tm) tm1,max(tm) tm2,coalesce(prd_line,'') prd_line,coalesce(prd_shop,'') prd_shop,coalesce(qc,'') qc,"+\
"batch_no,store_id,product_id,carton_code,count(*) q0,dt,origin_adm_id FROM mes_labelbindpx"+sWhere+\
"group by prd_line,prd_shop,qc,batch_no,store_id,product_id,carton_code,dt,origin_adm_id"+\
") h "+\
"group by prd_line,batch_no,store_id,product_id,dt,origin_adm_id"+\
"group by prd_line,prd_shop,qc,batch_no,store_id,product_id,dt,origin_adm_id"+\
") g"
cur.execute(s)
cnt=0
for r in cur.fetchall():
#print(r)
for r in cur.fetchall():
#print(r[8],r[9],r[10])
if r[10]:
......@@ -2454,14 +2791,33 @@ def product_bind(request,action,what=None):
q2=str(qty_in % int(a[1]))+"盒"
# 2023-10-18
if cid=='180087':
# if cid=='180087':
# 2024-10-12
if cid in ['180087','243885']:
q1=q1.replace('箱','大袋').replace('盒','小袋')
q2=q2.replace('箱','大袋').replace('盒','小袋')
data['data'].append([ r[0],r[1],r[3],r[10],r[4],r[12],r[5],q1,q2,r[7] ])
q2=q2.replace('箱','大袋').replace('盒','小袋')
# 2024-10-16
#data['data'].append([ r[0],r[1],r[3],r[10],r[4],r[12],r[5],q1,q2,r[7] ])
data['data'].append([ r[0], r[13],r[2] ,r[1],r[3],r[10],r[4],r[12],r[5],q1,q2,r[7] ])
elif cid.__eq__(19267):
btn_html = "<a type=\"button\" id='btn-single-inbound' class='btn btn-primary'>入库本行</a>" \
if int(qty_in/int(a[1])) else "已入库"
data['data'].append([r[0], r[1], r[3], r[10], r[4], r[5], q1, q2, r[7], btn_html, r[-2], r[-1]])
# 2024-09-03 海邦电子要显示明细
if cid=='212916':
data['clmns'] = ['日期', '生产时间', '产品', '包装规格', '生产批次号', '仓库', '产量', '待入库', '备注'
# , '单行入库'
]
data['data'].append([r[0], r[1], r[3], r[10], r[4], r[5],
"<button class='btn btn-xs btn-primary btn-details' href='/mes/product/bind/details/?"+
"batch_no="+r[4]+"&dt="+r[0]+"&store_id="+str(r[-1])+"&product_id="+str(r[-2])+"'>"+
str(q1)+"</button>", q2, r[7],
# btn_html, r[-2]
])
else:
data['data'].append([r[0], r[1], r[3], r[10], r[4], r[5], q1, q2, r[7], btn_html, r[-2], r[-1]])
else:
data['data'].append([ r[0],r[1],r[3],r[10],r[4],r[5],q1,q2,r[7] ])
......@@ -2472,9 +2828,35 @@ def product_bind(request,action,what=None):
cnt=cnt+qty_in
data['qty_uninbound']=cnt
# 2024-10-12
if cid in ('180087','243885'):
u='小袋'
else:
u='盒'
data['unit']=u
#print(data)
return render(request,'mes/product_bind.html',data)
# 2024-09-03
elif action=='details':
a=[]
dt=request.GET.get('dt','')
no=request.GET.get('batch_no','')
pid=request.GET.get('product_id','')
sid=request.GET.get('store_id','')
carton_code = 'carton_code'
if cid == "212916":
carton_code = "(select code_b from label.lbl_abcode where code_a = carton_code )"
s="SELECT "+carton_code+",box_code,coalesce((select nfc from label.lbl_nfc where label_code=box_code limit 1),'') "+\
"FROM mes_labelbindhx where company_id="+cid+" and dt='"+dt+"' and batch_no='"+no+"' and product_id="+pid+" and store_id="+sid
cur.execute(s)
for r in cur.fetchall():
a.append([r[0],r[1],r[2]])
cur.close()
return JsonResponse(a,safe=False)
elif action=='bottlcap_output':
data={'data':[],'clmns':['日期','生产时间','产品','生产批次号','数量','备注'],'dt_fr':dt_fr,'dt_to':dt_to,'qty_uninbound':0}
s=f"""
......@@ -3054,6 +3436,9 @@ def label_rework(request,company_id,action,what=None):
cur=connection.cursor()
if what=='old':
# 2024-07-27
data['product']={}
# 旧标签检查
# 用标签号码在redis做键值
tmp='rework_'+company_id+'_'+what+'_'+c
......@@ -3073,7 +3458,13 @@ def label_rework(request,company_id,action,what=None):
data['e']='旧标签 %s %s 已做返工,新号码 %s' % (c,r[2],r[1])
else:
# 传过来的标签(将被替换的标签)如果已出库,必须先做销售退库后才可以返工
q=LabelQuery(company_id,c)
q=LabelQuery(company_id,c)
# 2024-07-27
prd=q.get_product()
data['product']['id']=prd['id']
data['product']['name']=prd['name']
pk_id=q.infor['label_pk_id']
pk_code=q.infor['label_pk_code']
if not pk_id:
......@@ -3235,3 +3626,84 @@ SELECT bottle, label encode, code decode FROM label.bottlecap WHERE bottle IN %s
}
})
return JsonResponse(res)
def list_caps_by_label_code(request):
"""
根据盒码查盖子码(玖藏)
"""
res = {}
codes = request.GET.get("codes", None)
if not codes:
res["e"] = "Missing parameter codes"
return JsonResponse(res)
codes = ','.join("'{0}'".format(i) for i in codes.replace(' ', '').split(','))
s = f"""SELECT label_code, count(0) FROM mes_bottlcap WHERE label_code IN ({codes}) group by label_code"""
cur = connection.cursor()
cur.execute(s)
data = cur.fetchall()
if not data or len(data) == 0:
return JsonResponse({"data": []})
else:
res["data"] = []
for row in data:
res["data"].append({
"label_code": row[0],
"count": row[1]
})
return JsonResponse(res)
# 2024-10-11
def nfc_to_label(request):
data={'e':'','label':''}
e = time_key_check(request, sK)
if e:
data['e'] = e
return JsonResponse(data)
nfc=request.GET.get('nfc','')
if nfc:
try:
l=decryptQueryString(nfc)
data['label']=l
except Exception:
data['e']=_('nfc数据错误')
else:
data['e']='nfc code missing'
# 2024-10-15
initial=request.GET.get('initial','')
if initial=='1' and data['label']:
cur=connection.cursor()
c=data['label']
s="select package_id,tm from ("+\
"select 3 package_id,tm from mes_labelbindhx where carton_code='"+c+"'"+\
" union all "+\
"select 2 package_id,tm from mes_labelbindhx where box_code='"+c+"'"+\
" union all "+\
"select 1 package_id,tm from mes_labelbindph where bottle_code='"+c+"'"+\
" union all "+\
"select 2 package_id,tm from mes_labelbindph where box_code='"+c+"'"+\
" union all "+\
"select 1 package_id,tm from mes_labelbindpx where bottle_code='"+c+"'"+\
" union all "+\
"select 3 package_id,tm from mes_labelbindpx where carton_code='"+c+"'"+\
") u"
# 2024-10-18
s="select label_pkg,tm,product_id from label.lbl_nfc where nfc='"+nfc+"'"
cur.execute(s)
r=cur.fetchone()
if r:
t=r[1].strftime('%Y-%m-%d %H:%M:%S')
if r[0]==1:
p='瓶'
elif r[0]==2:
p='盒'
elif r[0]==3:
p='箱'
data['e']=p+"标NFC("+c+") "+t+" 已绑定"
cur.close()
return JsonResponse(data)
......@@ -3,6 +3,11 @@
<script type="text/javascript">
$(document).ready(function(){
var qty_uninbound={{qty_uninbound}};
var cid={{cid|default:0}};
if(cid==212916){//南京海邦 隐藏入库按钮
$(".btn-inbound").hide();
}
if(qty_uninbound>0){
$('#qty_uninbound').text(qty_uninbound+" 盒待入库");
}else{
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论