fjykTec / ModernWMS

The open source simple and complete warehouse management system is derived from our many years of experience in implementing erp projects. We stripped the original commercial system wms function and opened it up for free, hoping to help the majority of small and medium-sized enterprises. At present, the system supports cross-platform。
https://modernwms.ikeyly.com/
Apache License 2.0
881 stars 273 forks source link

安全库存功能BUG #43

Open lifeifeijack opened 11 hours ago

lifeifeijack commented 11 hours ago

安全库存功能出现BUG,分析问题如下: ModernWMS/backend/ModernWMS.WMS/Services/Stock/StockService.cs 文件 SafetyStockPageAsync 函数

            var stock_group_datas = from stock in DbSet.AsNoTracking()
                                    join gl in location_DBSet.AsNoTracking() on stock.goods_location_id equals gl.id
                                    where stock.tenant_id == currentUser.tenant_id
                                    group new { stock, gl } by new { stock.sku_id, gl.warehouse_id } into sg
                                    select new
                                    {
                                        sku_id = sg.Key.sku_id,
                                        warehouse_id = sg.Key.warehouse_id,
                                        qty_frozen = sg.Where(t => t.stock.is_freeze == true).Sum(e => e.stock.qty),
                                        qty = sg.Sum(t => t.stock.qty)
                                    };

这个查询通过关联 goodslocation表拿到了warehouse_id。

            var query = from sg in stock_group_datas
                        join dp in dispatch_group_datas on new { sg.sku_id, sg.warehouse_id } equals new { dp.sku_id, dp.warehouse_id } into dp_left
                        from dp in dp_left.DefaultIfEmpty()
                        join pl in process_locked_group_datas on new { sg.sku_id, sg.warehouse_id } equals new { pl.sku_id, pl.warehouse_id } into pl_left
                        from pl in pl_left.DefaultIfEmpty()
                        join m in move_locked_group_datas on new { sg.sku_id, sg.warehouse_id } equals new { m.sku_id, m.warehouse_id } into m_left
                        from m in m_left.DefaultIfEmpty()
                        join sku in sku_DBSet on sg.sku_id equals sku.id
                        join spu in spu_DBSet on sku.spu_id equals spu.id
                        join gl in location_DBSet on sg.warehouse_id equals gl.id
                        join sss in sku_safety_DBSet on new { sg.sku_id, sg.warehouse_id } equals new { sss.sku_id, sss.warehouse_id } into sss_left
                        from sss in sss_left.DefaultIfEmpty()
                        select new SafetyStockManagementViewModel
                        {
                            sku_id = sg.sku_id,
                            spu_name = spu.spu_name,
                            spu_code = spu.spu_code,
                            sku_code = sku.sku_code,
                            sku_name = sku.sku_name,
                            qty_available = gl.warehouse_area_property == 5 ? 0 : (sg.qty - sg.qty_frozen - (dp.qty_locked == null ? 0 : dp.qty_locked) - (pl.qty_locked == null ? 0 : pl.qty_locked) - (m.qty_locked == null ? 0 : m.qty_locked)),
                            qty_frozen = sg.qty_frozen,
                            qty_locked = (dp.qty_locked == null ? 0 : dp.qty_locked) + (pl.qty_locked == null ? 0 : pl.qty_locked) + (m.qty_locked == null ? 0 : m.qty_locked),
                            qty = sg.qty,
                            warehouse_name = gl.warehouse_name,
                            safety_stock_qty = sss.safety_stock_qty == null ? 0 : sss.safety_stock_qty,
                        };

用这个数据集再去查询的时候 join gl in location_DBSet on sg.warehouse_id equals gl.id 如上,使用了warehouse_id 和 goodslocation.id 去关联,导致仓库显示错误。并且也可能会导致 qty_available = gl.warehouse_area_property == 5 ? 0 : (sg.qty - sg.qty_frozen - (dp.qty_locked == null ? 0 : dp.qty_locked) - (pl.qty_locked == null ? 0 : pl.qty_locked) - (m.qty_locked == null ? 0 : m.qty_locked)) 数据出错。

lifeifeijack commented 11 hours ago
            var stock_group_datas = from stock in DbSet.AsNoTracking()
                                    join gl in location_DBSet.AsNoTracking() on stock.goods_location_id equals gl.id
                                    where stock.tenant_id == currentUser.tenant_id
                                    group new { stock, gl } by new { stock.sku_id, gl.warehouse_id,gl.id } into sg
                                    select new
                                    {
                                        sku_id = sg.Key.sku_id,
                                        warehouse_id = sg.Key.warehouse_id,
                                        gl_id = sg.Key.id,
                                        qty_frozen = sg.Where(t => t.stock.is_freeze == true).Sum(e => e.stock.qty),
                                        qty = sg.Sum(t => t.stock.qty)
                                    };
            var query = from sg in stock_group_datas
                        join dp in dispatch_group_datas on new { sg.sku_id, sg.warehouse_id } equals new { dp.sku_id, dp.warehouse_id } into dp_left
                        from dp in dp_left.DefaultIfEmpty()
                        join pl in process_locked_group_datas on new { sg.sku_id, sg.warehouse_id } equals new { pl.sku_id, pl.warehouse_id } into pl_left
                        from pl in pl_left.DefaultIfEmpty()
                        join m in move_locked_group_datas on new { sg.sku_id, sg.warehouse_id } equals new { m.sku_id, m.warehouse_id } into m_left
                        from m in m_left.DefaultIfEmpty()
                        join sku in sku_DBSet on sg.sku_id equals sku.id
                        join spu in spu_DBSet on sku.spu_id equals spu.id
                        join gl in location_DBSet on sg.gl_id equals gl.id
                        join sss in sku_safety_DBSet on new { sg.sku_id, sg.warehouse_id } equals new { sss.sku_id, sss.warehouse_id } into sss_left
                        from sss in sss_left.DefaultIfEmpty()
                        select new SafetyStockManagementViewModel
                        {
                            sku_id = sg.sku_id,
                            spu_name = spu.spu_name,
                            spu_code = spu.spu_code,
                            sku_code = sku.sku_code,
                            sku_name = sku.sku_name,
                            qty_available = gl.warehouse_area_property == 5 ? 0 : (sg.qty - sg.qty_frozen - (dp.qty_locked == null ? 0 : dp.qty_locked) - (pl.qty_locked == null ? 0 : pl.qty_locked) - (m.qty_locked == null ? 0 : m.qty_locked)),
                            qty_frozen = sg.qty_frozen,
                            qty_locked = (dp.qty_locked == null ? 0 : dp.qty_locked) + (pl.qty_locked == null ? 0 : pl.qty_locked) + (m.qty_locked == null ? 0 : m.qty_locked),
                            qty = sg.qty,
                            warehouse_name = gl.warehouse_name,
                            safety_stock_qty = sss.safety_stock_qty == null ? 0 : sss.safety_stock_qty,
                        };