| | |
| | | import ( |
| | | "context" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | "time" |
| | | "wms/constvar" |
| | |
| | | detail.Amount = decimal.NewFromInt(product.Amount) |
| | | details = append(details, &detail) |
| | | } |
| | | err = models.NewOperationSearch().Create(&operation) |
| | | return new(PurchaseToWmsResponse), err |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | err := models.NewOperationSearch().SetOrm(db).Create(&operation) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | for _, detail := range details { |
| | | detail.OperationID = operation.Id |
| | | } |
| | | err = models.NewOperationDetailsSearch().SetOrm(db).CreateBatch(details) |
| | | return err |
| | | }) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | resp := new(PurchaseToWmsResponse) |
| | | resp.Warehouse = warehouse.Name |
| | | return resp, nil |
| | | } |