From 7d4ad4c22a254fcc3a99c543533f0dddbadaeb7e Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 26 六月 2024 19:47:59 +0800
Subject: [PATCH] 多单位保存时,不保存值或单位为0的
---
models/material.go | 9 ++++++++-
service/more_units.go | 3 +++
2 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/models/material.go b/models/material.go
index 20896fc..e410f35 100644
--- a/models/material.go
+++ b/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
}
diff --git a/service/more_units.go b/service/more_units.go
index 729ce4a..5abdb09 100644
--- a/service/more_units.go
+++ b/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,
--
Gitblit v1.8.0