script actiontype forbidden in bricks; use Message widget instead. Status column reflects saved state on page load/reload.
35 lines
1.4 KiB
Plaintext
35 lines
1.4 KiB
Plaintext
"""Save or update a supply contract product discount."""
|
|
contract_id = params_kw.get('contract_id')
|
|
productid = params_kw.get('productid')
|
|
prodtypeid = params_kw.get('prodtypeid') or ''
|
|
new_discount = params_kw.get('discount') or '1.0'
|
|
old_discount = params_kw.get('old_discount') or '1.0'
|
|
item_id = params_kw.get('item_id')
|
|
|
|
userorgid = (await get_userorgid()) or '0'
|
|
dbname = get_module_dbname('supplychain')
|
|
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
if item_id:
|
|
if new_discount == old_discount:
|
|
pass
|
|
elif float(new_discount) <= 0:
|
|
await sor.D('supply_contract_items', {'id': item_id})
|
|
else:
|
|
await sor.U('supply_contract_items', {
|
|
'id': item_id, 'discount': new_discount, 'updated_at': timestampstr()
|
|
})
|
|
elif float(new_discount) > 0 and new_discount != old_discount:
|
|
now = timestampstr()
|
|
await sor.C('supply_contract_items', {
|
|
'id': getID(), 'contract_id': contract_id, 'resellerid': userorgid,
|
|
'productid': productid, 'prodtypeid': prodtypeid,
|
|
'discount': new_discount, 'created_at': now,
|
|
})
|
|
|
|
status_text = '已设置' if float(new_discount) > 0 else '已删除'
|
|
return {
|
|
'widgettype': 'Message',
|
|
'options': {'title': '保存成功', 'message': f'折扣 {status_text}: {new_discount}', 'type': 'success', 'timeout': 2}
|
|
}
|