fix: 兼容相同顺运宝明细逐件回写 (#289)
This commit is contained in:
@@ -124,6 +124,58 @@ func TestApplyClaimedInnerCode_两个单件码写入两个明细(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyClaimedInnerCode_两个单件码写入两条现成相同明细(t *testing.T) {
|
||||
record := innerCodeApplyTestRecord("")
|
||||
record.InnerCode = "DK-001,DK-002"
|
||||
record.SourceDuplicateCount = 2
|
||||
record.SybSKU = "A档#1-黑色-M"
|
||||
record.SybVariationSKU = "A档#1"
|
||||
record.RemoteItemsJSON = `[{"code":"DK-001","detail_id":20,"source":"existing_matched","status":"planned"},{"code":"DK-002","detail_id":21,"source":"existing_matched","status":"planned"}]`
|
||||
writer := innerCodeApplyTestWriter(record, "")
|
||||
writer.stock.Details[0].ProductQty = 1
|
||||
writer.stock.Details[0].Raw["sku"] = record.SybSKU
|
||||
writer.stock.Details[0].Raw["variationSku"] = record.SybVariationSKU
|
||||
writer.stock.Details = append(writer.stock.Details, syb.DetailItem{
|
||||
ID: 21, ProductSpec: record.SybSpec, ProductQty: 1,
|
||||
Raw: map[string]any{"sku": record.SybSKU, "variationSku": record.SybVariationSKU,
|
||||
"innerExpCode": "", "purchasePlatform": "", "purchaseCode": ""},
|
||||
})
|
||||
|
||||
outcome := applyClaimedInnerCode(context.Background(), writer, record, nil)
|
||||
if outcome.Status != model.InnerCodeUpdated || writer.updateCount != 2 || writer.createCount != 0 ||
|
||||
writer.deleteCount != 0 || writer.readCount != 3 {
|
||||
t.Fatalf("outcome=%+v update=%d create=%d delete=%d read=%d",
|
||||
outcome, writer.updateCount, writer.createCount, writer.deleteCount, writer.readCount)
|
||||
}
|
||||
if got := innerCodeDetailCode(writer.stock, 20); got != "DK-001" {
|
||||
t.Fatalf("第一条现成明细写码错误: %q", got)
|
||||
}
|
||||
if got := innerCodeDetailCode(writer.stock, 21); got != "DK-002" {
|
||||
t.Fatalf("第二条现成明细写码错误: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyClaimedInnerCode_现成多明细身份变化时零写入(t *testing.T) {
|
||||
record := innerCodeApplyTestRecord("")
|
||||
record.InnerCode = "DK-001,DK-002"
|
||||
record.SourceDuplicateCount = 2
|
||||
record.SybSKU = "A档#1-黑色-M"
|
||||
record.RemoteItemsJSON = `[{"code":"DK-001","detail_id":20,"source":"existing_matched","status":"planned"},{"code":"DK-002","detail_id":21,"source":"existing_matched","status":"planned"}]`
|
||||
writer := innerCodeApplyTestWriter(record, "")
|
||||
writer.stock.Details[0].ProductQty = 1
|
||||
writer.stock.Details[0].Raw["sku"] = record.SybSKU
|
||||
writer.stock.Details = append(writer.stock.Details, syb.DetailItem{
|
||||
ID: 21, ProductSpec: record.SybSpec, ProductQty: 1,
|
||||
Raw: map[string]any{"sku": "B档#2", "innerExpCode": "", "purchasePlatform": "", "purchaseCode": ""},
|
||||
})
|
||||
|
||||
outcome := applyClaimedInnerCode(context.Background(), writer, record, nil)
|
||||
if outcome.Status != model.InnerCodeSkipped || writer.updateCount != 0 || writer.createCount != 0 || writer.deleteCount != 0 {
|
||||
t.Fatalf("身份变化必须零写入: outcome=%+v update=%d create=%d delete=%d",
|
||||
outcome, writer.updateCount, writer.createCount, writer.deleteCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyClaimedInnerCode_三个单件码创建两条零价明细(t *testing.T) {
|
||||
record := innerCodeApplyTestRecord("")
|
||||
record.InnerCode = "DK-001,DK-002,DK-003"
|
||||
|
||||
Reference in New Issue
Block a user