feat: sync product_org_auth on supply_contract_items create/delete
This commit is contained in:
parent
49d59c3ed0
commit
3c98e8a991
@ -300,9 +300,16 @@ async def update_supply_contract_item(request, params_kw):
|
|||||||
async def delete_supply_contract_item(request, params_kw):
|
async def delete_supply_contract_item(request, params_kw):
|
||||||
"""Delete a supply contract item."""
|
"""Delete a supply contract item."""
|
||||||
data = params_kw
|
data = params_kw
|
||||||
|
item_id = data["id"]
|
||||||
db, dbname = _get_sor()
|
db, dbname = _get_sor()
|
||||||
async with db.sqlorContext(dbname) as sor:
|
async with db.sqlorContext(dbname) as sor:
|
||||||
await sor.D("supply_contract_items", {"id": data["id"]})
|
await sor.D("supply_contract_items", {"id": item_id})
|
||||||
|
# Also remove product_org_auth
|
||||||
|
async with DBPools().sqlorContext("sage") as sor_sage:
|
||||||
|
await sor_sage.sqlExe(
|
||||||
|
"DELETE FROM product_org_auth WHERE auth_source_id = ${sid}$",
|
||||||
|
{"sid": item_id}
|
||||||
|
)
|
||||||
return json.dumps({"status": "ok", "message": "删除成功"})
|
return json.dumps({"status": "ok", "message": "删除成功"})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,15 +6,29 @@ try:
|
|||||||
dbname = get_module_dbname('supplychain')
|
dbname = get_module_dbname('supplychain')
|
||||||
|
|
||||||
data = dict(params_kw)
|
data = dict(params_kw)
|
||||||
data['id'] = getID()
|
item_id = getID()
|
||||||
|
data['id'] = item_id
|
||||||
data['resellerid'] = user_orgid
|
data['resellerid'] = user_orgid
|
||||||
data['created_by'] = user_id
|
|
||||||
data['created_at'] = timestampstr()
|
data['created_at'] = timestampstr()
|
||||||
data['updated_at'] = timestampstr()
|
data['updated_at'] = timestampstr()
|
||||||
|
|
||||||
|
product_id = data.get('productid')
|
||||||
|
contract_id = data.get('contract_id')
|
||||||
|
|
||||||
async with DBPools().sqlorContext(dbname) as sor:
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
await sor.C('supply_contract_items', data)
|
await sor.C('supply_contract_items', data)
|
||||||
|
|
||||||
|
# Sync product_org_auth
|
||||||
|
if product_id:
|
||||||
|
async with DBPools().sqlorContext('sage') as sor_sage:
|
||||||
|
await sor_sage.C('product_org_auth', {
|
||||||
|
'id': getID(),
|
||||||
|
'product_id': product_id,
|
||||||
|
'org_id': user_orgid,
|
||||||
|
'auth_source': 'supply_contract',
|
||||||
|
'auth_source_id': item_id,
|
||||||
|
})
|
||||||
|
|
||||||
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '供应合同项目创建成功', 'type': 'success'}}
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '供应合同项目创建成功', 'type': 'success'}}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user