- agreement_discount_setting.ui: product list with UiFloat discount inputs - contract_discount_setting.ui: same for supply contracts - get_agreement_discount_items.dspy + Python function - get_contract_discount_items.dspy + Python function - save_agreement_discount.dspy: create/update/delete items on discount change - save_contract_discount.dspy: same for supply contracts - Updated distribution_agreements_list and supply_contracts_list subtables
31 lines
1.2 KiB
Plaintext
31 lines
1.2 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,
|
|
})
|
|
|
|
return {'status': 'ok'}
|