- All 7 models: created_at/updated_at changed from datetime to timestamp type (DDL template auto-generates DEFAULT CURRENT_TIMESTAMP for timestamp type) - core.py: fix all sor.U() calls passing 3 args (id must be in data dict) - core.py: fix sor.I() misuse for INSERT (should be sor.C()) - API dspy updates: fix sor.U() 3-arg bug in category/product/type_config/resource/subscription/supplier - product_resource_supplier_update.dspy: add missing updated_at field
42 lines
1.6 KiB
Plaintext
42 lines
1.6 KiB
Plaintext
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
|
|
|
try:
|
|
user_id = await get_user()
|
|
org_id = (await get_userorgid()) or '0'
|
|
|
|
dbname = get_module_dbname('product_management')
|
|
data = dict(params_kw)
|
|
record_id = data.pop('id', None)
|
|
if not record_id:
|
|
raise ValueError('Missing id')
|
|
|
|
# Verify belongs to org + auto-fill product_type if category changed
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
check = await sor.sqlExe(
|
|
"SELECT id FROM product WHERE id = ${id}$ AND org_id = ${org_id}$",
|
|
{'id': record_id, 'org_id': org_id}
|
|
)
|
|
if not check:
|
|
raise ValueError('无权操作该记录')
|
|
|
|
if data.get('category_id') and not data.get('product_type'):
|
|
cat_check = await sor.sqlExe(
|
|
"SELECT product_type FROM product_category WHERE id = ${category_id}$ AND org_id = ${org_id}$",
|
|
{'category_id': data['category_id'], 'org_id': org_id}
|
|
)
|
|
if cat_check:
|
|
data['product_type'] = cat_check[0].get('product_type', '')
|
|
|
|
data['updated_at'] = timestampstr()
|
|
data['id'] = record_id
|
|
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
await sor.U('product', data)
|
|
|
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '产品更新成功', 'type': 'success'}}
|
|
|
|
except Exception as e:
|
|
result['options'] = {'title': 'Error', 'message': '更新失败: ' + str(e), 'type': 'error'}
|
|
|
|
return json.dumps(result, ensure_ascii=False)
|