本文整理汇总了Python中corehq.apps.commtrack.models.RequisitionCase.open_for_location方法的典型用法代码示例。如果您正苦于以下问题:Python RequisitionCase.open_for_location方法的具体用法?Python RequisitionCase.open_for_location怎么用?Python RequisitionCase.open_for_location使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.commtrack.models.RequisitionCase
的用法示例。
在下文中一共展示了RequisitionCase.open_for_location方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRequisition
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import open_for_location [as 别名]
def testRequisition(self):
# confirm we have a clean start
self.assertEqual(0, len(RequisitionCase.open_for_location(self.domain.name, self.loc._id)))
self.assertEqual(0, len(self.get_commtrack_forms(self.domain.name)))
amounts = {
'pp': 10,
'pq': 20,
'pr': 30,
}
# req loc1 pp 10 pq 20...
handled = handle(self.users[0].get_verified_number(), 'req {loc} {report}'.format(
loc='loc1',
report=' '.join('%s %s' % (k, v) for k, v in amounts.items())
))
self.assertTrue(handled)
# make sure we got the updated requisitions
reqs = RequisitionCase.open_for_location(self.domain.name, self.loc._id)
self.assertEqual(1, len(reqs))
req = RequisitionCase.get(reqs[0])
[index] = req.indices
self.assertEqual(req.requisition_status, 'requested')
self.assertEqual(const.SUPPLY_POINT_CASE_TYPE, index.referenced_type)
self.assertEqual(self.sp._id, index.referenced_id)
self.assertEqual('parent_id', index.identifier)
# check updated status
for code, amt in amounts.items():
self.check_stock(code, amt, req._id, 'ct-requested')
self.check_stock(code, 0, req._id, 'stock')
示例2: testRequisition
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import open_for_location [as 别名]
def testRequisition(self):
self.assertEqual(0, len(RequisitionCase.open_for_location(self.domain.name, self.loc._id)))
self.assertEqual(0, len(self.get_commtrack_forms()))
amounts = {
'pp': 10,
'pq': 20,
'pr': 30,
}
# req loc1 pp 10 pq 20...
handled = handle(self.user.get_verified_number(), 'req {loc} {report}'.format(
loc='loc1',
report=' '.join('%s %s' % (k, v) for k, v in amounts.items())
))
self.assertTrue(handled)
# make sure we got the updated requisitions
reqs = RequisitionCase.open_for_location(self.domain.name, self.loc._id)
self.assertEqual(3, len(reqs))
forms = list(self.get_commtrack_forms())
self.assertEqual(1, len(forms))
self.assertEqual(self.sp.location_, forms[0].location_)
# check updated status
for code, amt in amounts.items():
spp = CommCareCase.get(self.spps[code]._id)
# make sure the index was created
[req_ref] = spp.reverse_indices
req_case = RequisitionCase.get(req_ref.referenced_id)
self.assertEqual(str(amt), req_case.amount_requested)
self.assertEqual(self.user._id, req_case.requested_by)
self.assertEqual(req_case.location_, self.sp.location_)
self.assertTrue(req_case._id in reqs)
self.assertEqual(spp._id, req_case.get_product_case()._id)
示例3: testReceipts
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import open_for_location [as 别名]
def testReceipts(self):
# this tests the requisition specific receipt keyword. not to be confused
# with the standard stock receipt keyword
self.testRequisition()
reqs = RequisitionCase.open_for_location(self.domain.name, self.loc._id)
self.assertEqual(3, len(reqs))
req_ids_by_product_code = dict(((RequisitionCase.get(id).get_product().code, id) for id in reqs))
rec_amounts = {
'pp': 30,
'pq': 20,
'pr': 10,
}
# rec loc1 pp 10 pq 20...
handled = handle(self.user.get_verified_number(), 'rec {loc} {report}'.format(
loc='loc1',
report=' '.join('%s %s' % (k, v) for k, v in rec_amounts.items())
))
self.assertTrue(handled)
# we should have closed the requisitions
self.assertEqual(0, len(RequisitionCase.open_for_location(self.domain.name, self.loc._id)))
forms = list(self.get_commtrack_forms())
self.assertEqual(2, len(forms))
self.assertEqual(self.sp.location_, forms[1].location_)
# check updated status
for code, amt in rec_amounts.items():
req_case = RequisitionCase.get(req_ids_by_product_code[code])
self.assertTrue(req_case.closed)
self.assertEqual(str(amt), req_case.amount_received)
self.assertEqual(self.user._id, req_case.received_by)
self.assertTrue(req_case._id in reqs, 'requisition %s should be in %s' % (req_case._id, reqs))
示例4: testReceipt
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import open_for_location [as 别名]
def testReceipt(self):
amounts = {
'pp': 10,
'pq': 20,
'pr': 30,
}
# start with an open request
handle(
self.users[0].get_verified_number(),
'req {loc} {report}'.format(
loc='loc1',
report=' '.join('%s %s' % (k, v) for k, v in amounts.items())
)
)
# fulfill it
handle(
self.users[0].get_verified_number(),
'fulfill {loc} {report}'.format(
loc='loc1',
report=' '.join('%s %s' % (k, v) for k, v in amounts.items())
)
)
# grab this first because we are about to close it
req_id = RequisitionCase.open_for_location(self.domain.name, self.loc._id)[0]
# mark it received
handle(
self.users[0].get_verified_number(),
'rec {loc} {report}'.format(
loc='loc1',
report=' '.join('%s %s' % (k, v) for k, v in amounts.items())
)
)
reqs = RequisitionCase.open_for_location(self.domain.name, self.loc._id)
# receiving by sms closes the req
self.assertEqual(0, len(reqs))
req = RequisitionCase.get(req_id)
[index] = req.indices
self.assertEqual(req.requisition_status, 'received')
# check updated status
for code, amt in amounts.items():
self.check_stock(code, 0, req._id, 'stock')
self.check_stock(code, amt, self.sp._id, 'stock')
示例5: get_case_ids
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import open_for_location [as 别名]
def get_case_ids(self):
# todo: too many couch requests
for c in filter(
create_unique_filter(lambda id: RequisitionCase.get(id).get_product_case_id()),
RequisitionCase.open_for_location(self.domain, self.location_id),
):
yield c
示例6: get_req_id
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import open_for_location [as 别名]
def get_req_id(self):
reqs = RequisitionCase.open_for_location(self.location["location"].domain, self.location["location"]._id)
if reqs:
# only support one open requisition per location
assert len(reqs) == 1
return reqs[0]
else:
return uuid.uuid4().hex
示例7: testReceiptsWithNoOpenRequisition
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import open_for_location [as 别名]
def testReceiptsWithNoOpenRequisition(self):
# make sure we don't have any open requisitions
self.assertEqual(0, len(RequisitionCase.open_for_location(self.domain.name, self.loc._id)))
rec_amounts = {
'pp': 30,
'pq': 20,
'pr': 10,
}
# rec loc1 pp 10 pq 20...
handled = handle(self.user.get_verified_number(), 'rec {loc} {report}'.format(
loc='loc1',
report=' '.join('%s %s' % (k, v) for k, v in rec_amounts.items())
))
self.assertTrue(handled)
# should still be no open requisitions
self.assertEqual(0, len(RequisitionCase.open_for_location(self.domain.name, self.loc._id)))
示例8: inactive_testSimpleApproval
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import open_for_location [as 别名]
def inactive_testSimpleApproval(self):
self.testRequisition()
# approve loc1
handled = handle(self.user.get_verified_number(), 'approve {loc}'.format(
loc='loc1',
))
self.assertTrue(handled)
reqs = RequisitionCase.open_for_location(self.domain.name, self.loc._id)
self.assertEqual(3, len(reqs))
for req_id in reqs:
req_case = RequisitionCase.get(req_id)
self.assertEqual(RequisitionStatus.APPROVED, req_case.requisition_status)
self.assertEqual(req_case.amount_requested, req_case.amount_approved)
self.assertEqual(self.user._id, req_case.approved_by)
self.assertIsNotNone(req_case.approved_on)
self.assertTrue(isinstance(req_case.approved_on, datetime))
示例9: testSimplePack
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import open_for_location [as 别名]
def testSimplePack(self):
self.testRequisition()
# pack loc1
handled = handle(self.user.get_verified_number(), 'pack {loc}'.format(
loc='loc1',
))
self.assertTrue(handled)
reqs = RequisitionCase.open_for_location(self.domain.name, self.loc._id)
self.assertEqual(3, len(reqs))
for req_id in reqs:
req_case = RequisitionCase.get(req_id)
self.assertEqual(RequisitionStatus.PACKED, req_case.requisition_status)
self.assertEqual(req_case.amount_requested, req_case.amount_packed)
self.assertEqual(self.user._id, req_case.packed_by)
self.assertIsNotNone(req_case.packed_on)
self.assertTrue(isinstance(req_case.packed_on, datetime))
self.assertEqual(req_case.product_id, req_case.get_product_case().product)
示例10: testSimpleFulfill
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import open_for_location [as 别名]
def testSimpleFulfill(self):
amounts = {
'pp': 10,
'pq': 20,
'pr': 30,
}
# start with an open request
handle(
self.users[0].get_verified_number(),
'req {loc} {report}'.format(
loc='loc1',
report=' '.join('%s %s' % (k, v) for k, v in amounts.items())
)
)
# fulfill loc1
handled = handle(
self.users[0].get_verified_number(),
'fulfill {loc} {report}'.format(
loc='loc1',
report=' '.join('%s %s' % (k, v) for k, v in amounts.items())
)
)
self.assertTrue(handled)
reqs = RequisitionCase.open_for_location(self.domain.name, self.loc._id)
# should not have created a new req
self.assertEqual(1, len(reqs))
req = RequisitionCase.get(reqs[0])
[index] = req.indices
self.assertEqual(req.requisition_status, 'fulfilled')
for code, amt in amounts.items():
self.check_stock(code, amt, req._id, 'stock')
self.check_stock(code, amt, req._id, 'ct-fulfilled')
示例11: test_create_fulfill_and_receive_requisition
# 需要导入模块: from corehq.apps.commtrack.models import RequisitionCase [as 别名]
# 或者: from corehq.apps.commtrack.models.RequisitionCase import open_for_location [as 别名]
def test_create_fulfill_and_receive_requisition(self):
amounts = [(p._id, 50.0 + float(i*10)) for i, p in enumerate(self.products)]
# ----------------
# Create a request
# ----------------
self.submit_xml_form(create_requisition_xml(amounts))
req_cases = list(get_cases_in_domain(self.domain.name, type=const.REQUISITION_CASE_TYPE))
self.assertEqual(1, len(req_cases))
req = RequisitionCase.get(req_cases[0]._id)
[index] = req.indices
self.assertEqual(req.requisition_status, 'requested')
self.assertEqual(const.SUPPLY_POINT_CASE_TYPE, index.referenced_type)
self.assertEqual(self.sp._id, index.referenced_id)
self.assertEqual('parent_id', index.identifier)
# TODO: these types of tests probably belong elsewhere
self.assertEqual(req.get_next_action().keyword, 'fulfill')
self.assertEqual(req.get_location()._id, self.sp.location._id)
self.assertEqual(len(RequisitionCase.open_for_location(
self.domain.name,
self.sp.location._id
)), 1)
self.assertEqual(
get_notification_message(
req.get_next_action(),
[req]
),
self.expected_notification_message(req, amounts)
)
for product, amt in amounts:
self.check_stock_models(req, product, amt, 0, 'ct-requested')
# ----------------
# Mark it fulfilled
# -----------------
self.submit_xml_form(create_fulfillment_xml(req, amounts))
req = RequisitionCase.get(req._id)
self.assertEqual(req.requisition_status, 'fulfilled')
self.assertEqual(req.get_next_action().keyword, 'rec')
self.assertEqual(
get_notification_message(
req.get_next_action(),
[req]
),
self.expected_notification_message(req, amounts)
)
for product, amt in amounts:
# we are expecting two separate blocks to have come with the same
# values
self.check_stock_models(req, product, amt, amt, 'stock')
self.check_stock_models(req, product, amt, 0, 'ct-fulfilled')
# ----------------
# Mark it received
# ----------------
self.submit_xml_form(create_received_xml(req, amounts))
req = RequisitionCase.get(req._id)
self.assertEqual(req.requisition_status, 'received')
self.assertIsNone(req.get_next_action())
self.assertEqual(len(RequisitionCase.open_for_location(
self.domain.name,
self.sp.location._id
)), 0)
for product, amt in amounts:
self.check_stock_models(req, product, 0, -amt, 'stock')
self.check_stock_models(self.sp, product, amt, amt, 'stock')