1
0
forked from erp-dev/erp

fix: query param of api_man

This commit is contained in:
2025-12-09 16:34:46 +08:00
parent d61a644d92
commit 4188bae0fc
12 changed files with 181 additions and 5 deletions

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2.8 on 2025-12-09 06:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('basic_info', '0019_customer_mdy_fields'),
]
operations = [
migrations.AddField(
model_name='product',
name='mdy_image_url',
field=models.URLField(blank=True, help_text='来自明道云的图片链接', max_length=500, null=True, verbose_name='明道云图片URL'),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2.8 on 2025-12-09 07:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('basic_info', '0020_product_mdy_image_url'),
]
operations = [
migrations.AlterField(
model_name='product',
name='unit',
field=models.IntegerField(choices=[(1, ''), (2, ''), (3, '公斤'), (4, '')], default=1, verbose_name='单位'),
),
]

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.2.8 on 2025-12-09 07:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('basic_info', '0021_alter_product_unit'),
]
operations = [
migrations.AddField(
model_name='product',
name='pieces',
field=models.IntegerField(blank=True, null=True, verbose_name='件数'),
),
migrations.AddField(
model_name='product',
name='segment_size',
field=models.IntegerField(blank=True, null=True, verbose_name='一段尺寸'),
),
]

View File

@@ -1,4 +1,5 @@
from decimal import Decimal
import json
from django.db import models
from flower.common import ModelBase
@@ -36,6 +37,7 @@ class ProductUnitEnum(models.IntegerChoices):
METER = 1, ''
YARD = 2, ''
KG = 3, '公斤'
SEGMENT = 4, ''
class EmployeeTypeEnum(models.TextChoices):
@@ -226,6 +228,8 @@ class Product(ModelBase):
human_id = models.CharField(max_length=100, verbose_name='产品编号', blank=True)
color = models.CharField(max_length=50, blank=True, null=True, verbose_name='颜色')
width_size = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True, verbose_name='宽幅')
pieces = models.IntegerField(blank=True, null=True, verbose_name='件数')
segment_size = models.IntegerField(blank=True, null=True, verbose_name='一段尺寸')
single_price_in = models.DecimalField(
max_digits=10,
decimal_places=2,
@@ -253,6 +257,13 @@ class Product(ModelBase):
null=True,
verbose_name='产品图片',
)
mdy_image_url = models.URLField(
max_length=500,
blank=True,
null=True,
verbose_name='明道云图片URL',
help_text='来自明道云的图片链接',
)
minimum_quantity = models.IntegerField(null=True, blank=True, verbose_name='最低库存量')
transform_rate = models.DecimalField(
max_digits=10,
@@ -267,6 +278,36 @@ class Product(ModelBase):
help_text='标记该产品是否通过明道云接口同步',
)
def get_primary_image_url(self):
"""
优先返回 mdy_image_url若为空则尝试从 description JSON 中提取 original_file_full_path。
"""
if self.mdy_image_url:
return self.mdy_image_url
if not self.description:
return None
try:
payload = json.loads(self.description) if isinstance(self.description, str) else self.description
except (TypeError, ValueError, json.JSONDecodeError):
return None
if isinstance(payload, dict):
items = [payload]
elif isinstance(payload, list):
items = payload
else:
return None
for item in items:
if not isinstance(item, dict):
continue
url = item.get('original_file_full_path') or item.get('DownloadUrl')
if url:
return url
return None
def __str__(self):
return self.name