From 389dffb0b6218f05277b8755bb82b61b6a316528 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 14 三月 2024 20:06:13 +0800 Subject: [PATCH] 按仓库返回销售明细单对应产品完成入库且可用数量 --- proto/product_inventory/server.go | 35 ++++++++++++++++++++++++----------- 1 files changed, 24 insertions(+), 11 deletions(-) diff --git a/proto/product_inventory/server.go b/proto/product_inventory/server.go index 6fb93ca..14fa029 100644 --- a/proto/product_inventory/server.go +++ b/proto/product_inventory/server.go @@ -17,12 +17,14 @@ } type ProductAndLocationInfo struct { - ProductId string `json:"productId"` - Amount decimal.Decimal `json:"amount"` - LocationId int `json:"locationId"` - Number string `json:"number"` - WaybillNumber string `json:"waybillNumber"` - Name string `json:"name"` + ProductId string `json:"productId"` + Amount decimal.Decimal `json:"amount"` + LocationId int `json:"locationId"` + FromLocationId int `json:"fromLocationId"` + ToLocationId int `json:"toLocationId"` + Number string `json:"number"` + WaybillNumber string `json:"waybillNumber"` + Name string `json:"name"` } func (s *Server) GetInventoryProductInfo(ctx context.Context, req *GetInventoryProductInfoRequest) (*GetInventoryProductInfoResponse, error) { @@ -33,12 +35,19 @@ var details []ProductAndLocationInfo var productIds []string resp := new(GetInventoryProductInfoResponse) - err := models.NewOperationDetailsSearch().Orm.Model(&models.OperationDetails{}). - Select("wms_operation_details.product_id,wms_operation_details.amount,wms_operation_details.from_location_id as location_id,"+ + search := models.NewOperationDetailsSearch().Orm.Model(&models.OperationDetails{}). + Select("wms_operation_details.product_id,wms_operation_details.amount,wms_operation_details.from_location_id,wms_operation_details.to_location_id"+ "wms_operation.number,wms_operation.waybill_number, logistic_company.name"). Joins("left join wms_operation on wms_operation.id = wms_operation_details.operation_id"). Joins("left join logistic_company on logistic_company.id = wms_operation.logistic_company_id"). - Where("wms_operation.source_number = ?", req.Number).Find(&details).Error + Where("wms_operation.source_number = ?", req.Number) + if req.IsInput { + search.Where("wms_operation.base_operation_type = ?", constvar.BaseOperationTypeIncoming) + } + if req.IsOutput { + search.Where("wms_operation.base_operation_type = ?", constvar.BaseOperationTypeOutgoing) + } + err := search.Find(&details).Error if err != nil { return nil, err } @@ -49,8 +58,12 @@ var locationId int for _, detail := range details { productIds = append(productIds, detail.ProductId) - locationIds = append(locationIds, detail.LocationId) - locationId = detail.LocationId + if req.IsInput { //鍙煡鍏ュ簱 + locationIds = append(locationIds, detail.ToLocationId) + } else if req.IsOutput { //鍙煡鍑哄簱 + locationIds = append(locationIds, detail.FromLocationId) + } + locationId = detail.FromLocationId } //鏌ヨ浜у搧淇℃伅 materials, err := models.NewMaterialSearch().SetIDs(productIds).FindNotTotal() -- Gitblit v1.8.0