1
0
forked from erp-dev/erp

fix: product sync error cause duplicate data

This commit is contained in:
2026-01-12 13:41:41 +08:00
parent bbe4039517
commit 7531b9fd5b
2 changed files with 17 additions and 4 deletions

View File

@@ -197,12 +197,19 @@ def _upsert_product(product_data, merchant, category):
if segment_decimal is not None:
defaults['segment_size'] = segment_decimal
product_obj, created = basic_models.Product.objects.get_or_create(
# 使用 filter().first() 替代 get_or_create,容忍重复数据
product_obj = basic_models.Product.objects.filter(
merchant=merchant,
human_id=product_data.uid,
defaults=defaults,
)
if created:
).first()
if product_obj is None:
# 不存在,创建新记录
product_obj = basic_models.Product.objects.create(
merchant=merchant,
human_id=product_data.uid,
**defaults,
)
return True
if not product_obj.from_mdy: