本文整理汇总了Python中corehq.apps.commtrack.models.RequisitionCase.get_by_external_id方法的典型用法代码示例。如果您正苦于以下问题:Python RequisitionCase.get_by_external_id方法的具体用法?Python RequisitionCase.get_by_external_id怎么用?Python RequisitionCase.get_by_external_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.commtrack.models.RequisitionCase
的用法示例。
在下文中一共展示了RequisitionCase.get_by_external_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sync_requisition_from_openlmis
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import get_by_external_id [as 别名]
def sync_requisition_from_openlmis(domain, requisition_id, openlmis_endpoint):
cases = []
send_notification = False
lmis_requisition_details = openlmis_endpoint.get_requisition_details(requisition_id)
if lmis_requisition_details:
rec_cases = [c for c in RequisitionCase.get_by_external_id(domain, str(lmis_requisition_details.id)) if c.type == const.REQUISITION_CASE_TYPE]
if len(rec_cases) == 0:
products = [product for product in lmis_requisition_details.products if product.skipped == False]
for product in products:
pdt = Product.get_by_code(domain, product.code.lower())
if pdt:
case = lmis_requisition_details.to_requisition_case(pdt._id)
case.save()
if case.requisition_status == 'AUTHORIZED':
send_notification = True
cases.append(case)
else:
for case in rec_cases:
before_status = case.requisition_status
if apply_updates(case, lmis_requisition_details.to_dict(case.product_id)):
after_status = case.requisition_status
case.save()
if before_status in ['INITIATED', 'SUBMITTED'] and after_status == 'AUTHORIZED':
send_notification = True
cases.append(case)
return cases, send_notification
else:
return None, False
示例2: sync_requisition_from_openlmis
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import get_by_external_id [as 别名]
def sync_requisition_from_openlmis(domain, requisition_id, openlmis_endpoint):
cases = []
send_notification = False
lmis_requisition_details = openlmis_endpoint.get_requisition_details(requisition_id)
rec_cases = [RequisitionCase.wrap(c._doc) for c in RequisitionCase.get_by_external_id(domain, lmis_requisition_details.id) if c.type == const.REQUISITION_CASE_TYPE]
if rec_cases is None:
for product in lmis_requisition_details.products:
pdt = Product.get_by_code(domain, product.code)
case = lmis_requisition_details.to_requisition_case(pdt._id)
case.save()
if case.requisition_status is 'AUTHORIZED':
send_notification = True
cases.append(case)
else:
for case in rec_cases:
before_status = case.requisition_status
if _apply_updates(case, lmis_requisition_details.to_requisition_case(case.product_id)):
after_status = case.requisition_status
case.save()
if before_status in ['INITIATED', 'SUBMITTED'] and after_status is 'AUTHORIZED':
send_notification = True
cases.append(case)
return cases, send_notification