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

新增 康庄大道进销存退报表 产品维度

上级 fdc98e21
......@@ -209,6 +209,8 @@ urlpatterns = [
url(r'^inventory/batch/(?P<obj>\w+)/$',inventory_views.batch_list),
url(r'^inventory/batch/(?P<obj>\w+)/(?P<company_id>\d+)/$',inventory_views.batch_list),
# 产品维度进销存报表
url(r'^inventory/batch/product/(?P<obj>\w+)/$',inventory_views.batch_product_list),
url(r'^inventory/edit/batch/(?P<id>\d+)/$',inventory_views.batch_edit),
......
......@@ -3712,6 +3712,7 @@ def batch_list(request,obj,company_id=None):
dt = datetime.datetime.now().strftime('%Y-%m-%d')
dt_fr = request.GET.get('date_fr', dt)
dt_to = request.GET.get('date_to', dt)
print('dt_fr',dt_fr)
if request.user.company.id == 19257:
dt_fr = request.GET.get(
'date_fr', (datetime.datetime.now() + datetime.timedelta(days=-7)).strftime('%Y-%m-%d'))
......@@ -4315,6 +4316,100 @@ def batch_list(request,obj,company_id=None):
'params': params
})
@login_required
def batch_product_list(request, obj):
company_id=str(request.user.company.id)
ancestor_id = request.user.ancestor_id
product_id = request.GET.get("product_id","")
dt = datetime.datetime.now().strftime('%Y-%m-%d')
dt_fr = request.GET.get('date_fr', dt)
dt_to = request.GET.get('date_to', dt)
# dt_fr = '2023-12-30'
# dt_to = '2024-01-09'
dt_max = max(dt_fr, dt_to)
dt_min = min(dt_fr, dt_to)
dt_fr = dt_min
dt_to = dt_max
params = {
'dt_fr': dt_fr,
'dt_to': dt_to,
# 'product_id': product_id
}
v=None
e=""
sProduct=""
sAgent=""
sCode=""
if product_id:
sProduct=" and product_id="+product_id
# 2022-10-29 stkdetails分表
tb_stk="stkdetails.c"+str(ancestor_id)
vs=Voucher.objects.filter(code=obj.upper())
data=[]
"""
单据类别:voucher id
1;"成品入库单";"GRN";1
2;"销售出库单";"GDN";-1
3;"成品转库单";"GTN";0
4;"销售退库单";"GWN";1
5;"入库单退库";"GCN";-1
"""
if not vs:
e=_('单据类别错误')
else:
v=vs[0]
vid=str(v.id)
sWhere=" where company_id="+company_id+" and vtype_id="+vid+\
" and (dt between '"+dt_fr+"' and '"+dt_to+"')"
package_units = get_package_name(ancestor_id,'数')
clmns=[]
if vid in ['1','2','4']: #成品入库\出库\退库
clmns=['产品名称','生产批次','仓库名称','操作人',package_units[2],package_units[1],package_units[0]]
else:
e=_('暂未开放该类型统计')
s = f"""
select
coalesce((select name from product_product where id=b.product_id),''),
STRING_AGG(DISTINCT b.code,'、') as batch_codes,
STRING_AGG(DISTINCT coalesce((select name from inventory_storehouse where id=b.store_fr_id),''),'、'),
STRING_AGG(DISTINCT coalesce((select coalesce(last_name,username) from company_user where id=b.user_id),''),'、'),
(select json_build_object('x', sum(x), 'h', sum(h), 'p', sum(p))
from
(select
case when label_pkg in (3,4) then 1 else 0 end as x,
case when label_pkg=2 then 1 else 0 end as h,
case when label_pkg=1 then 1 else 0 end as p
from {tb_stk}
WHERE batch_id IN (SELECT UNNEST(array_agg(DISTINCT b.id))) -- 聚合 b.id 成数组
) g
) jdata
from inventory_batch b {sWhere} {sProduct}
group by b.product_id
"""
cur = connection.cursor()
cur.execute(s)
for r in cur.fetchall():
jdata=r[4]
data.append([r[0],r[1],r[2],r[3],
jdata['x'] if jdata['x'] else '0',
jdata['h'] if jdata['h'] else '0',
jdata['p'] if jdata['p'] else '0'
])
return render(request, 'inventory/stock/batch_product_list.html', {
'data':SafeString(data),
'clmns':clmns,
'e': e,
'voucher':v,
'params': params
})
@tj_login_required
def delete_obj(request,obj_name='',id='0'):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论