zhangqian
2024-06-26 7d4ad4c22a254fcc3a99c543533f0dddbadaeb7e
多单位保存时,不保存值或单位为0的
2个文件已修改
12 ■■■■■ 已修改文件
models/material.go 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/more_units.go 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/material.go
@@ -164,7 +164,14 @@
        }
    }
    if len(slf.MoreUnitList) != 0 {
        str, err := json.Marshal(slf.MoreUnitList)
        items := make([]UnitItems, 0)
        for k, item := range slf.MoreUnitList {
            if item.Unit != "" && !item.Amount.IsZero() {
                items = append(items, slf.MoreUnitList[k])
            }
        }
        str, err := json.Marshal(items)
        if err != nil {
            return err
        }
service/more_units.go
@@ -11,6 +11,9 @@
func CreateMoreUnit(amount decimal.Decimal, units []models.UnitItems) []models.UnitItems {
    moreValueArr := make([]models.UnitItems, 0, len(units))
    for _, unitItem := range units {
        if unitItem.Amount.IsZero() {
            continue
        }
        moreValueArr = append(moreValueArr, models.UnitItems{
            Amount:   amount.Div(unitItem.Amount),
            Unit:     unitItem.Unit,