fix(pl): keep multi-brand site feedback when plan product row is stale

Persist submitted brand qtys even if plan brand_mode lookup fails; resolve soft-deleted plan products for brand metadata instead of substituting another product; stop seeding all actual qty onto the first brand option.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-07-31 07:06:41 +08:00
1 parent d1daedc17d
commit 5a9abfdd5d
6 files changed
+220 -54

No files matched your search

@@ -73,3 +73,56 @@ def test_require_calls_validate_when_positive_rows(monkeypatch):
assert called["brand_mode"] == "any"
assert called["actual_qty"] == Decimal("10")
assert called["rows"] == rows
def test_persist_io_item_brand_qtys_writes_when_brand_mode_missing():
"""计划行 brand_mode 丢失时,客户端提交的多品牌明细仍应落库(不能只软删不写)。"""
from app.services.pl_feedback_brand_qty import persist_io_item_brand_qtys
class _Row:
def __init__(self):
self.del_flag = 0
self.update_by = None
existing = [_Row()]
added = []
class _Query:
def filter(self, *args, **kwargs):
return self
def all(self):
return existing
class _Db:
def query(self, model):
return _Query()
def add(self, obj):
added.append(obj)
class _Model:
order_item_id = object()
tenant_no = object()
del_flag = object()
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
persist_io_item_brand_qtys(
_Db(),
model=_Model,
tenant_no="t1",
order_id="o1",
order_item_id="i1",
plan_product_id="p1",
brand_mode=None,
rows=[
{"brandId": "b1", "brandName": "君正", "qty": Decimal("20")},
{"brandId": "b2", "brandName": "红四方", "qty": Decimal("30")},
],
user_id="u1",
)
assert existing[0].del_flag == 1
assert len(added) == 2
assert {a.brand_id for a in added} == {"b1", "b2"}