本文整理汇总了Python中corehq.apps.commtrack.models.RequisitionCase类的典型用法代码示例。如果您正苦于以下问题:Python RequisitionCase类的具体用法?Python RequisitionCase怎么用?Python RequisitionCase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequisitionCase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testReceipts
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))
示例2: get_case_ids
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
示例3: testRequisition
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')
示例4: testRequisition
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)
示例5: testReceipt
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')
示例6: raise_events
def raise_events(xform, cases):
supply_points = [SupplyPointCase.wrap(c._doc) for c in cases if c.type == const.SUPPLY_POINT_CASE_TYPE]
case_updates = get_case_updates(xform)
for sp in supply_points:
created = any(filter(lambda update: update.id == sp._id and update.creates_case(), case_updates))
supply_point_modified.send(sender=None, supply_point=sp, created=created)
requisition_cases = [RequisitionCase.wrap(c._doc) for c in cases if c.type == const.REQUISITION_CASE_TYPE]
if requisition_cases and requisition_cases[0].requisition_status is RequisitionStatus.APPROVED:
requisition_approved.send(sender=None, requisitions=requisition_cases)
if requisition_cases and requisition_cases[0].requisition_status is RequisitionStatus.RECEIVED:
requisition_receipt.send(sender=None, requisitions=requisition_cases)
requisition_cases = [RequisitionCase.wrap(c._doc) for c in cases if c.type == const.REQUISITION_CASE_TYPE]
if requisition_cases:
requisition_modified.send(sender=None, cases=requisition_cases)
示例7: sync_requisition_from_openlmis
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
示例8: create_requisition
def create_requisition(user_id, product_stock_case, transaction):
req = RequisitionState.from_transactions(user_id, product_stock_case, [transaction])
submit_case_blocks(req.to_xml(), req.domain, req.username,
req.user_id)
case = RequisitionCase.get(req.id)
case.location_ = product_stock_case.location_
return case
示例9: get_req_id
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
示例10: inactive_testSimpleApproval
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))
示例11: raise_events
def raise_events(xform, cases):
requisition_cases = [RequisitionCase.wrap(c._doc) for c in cases if c.type == const.REQUISITION_CASE_TYPE]
if requisition_cases and requisition_cases[0].requisition_status == RequisitionStatus.APPROVED:
requisition_approved.send(sender=None, requisitions=requisition_cases)
if requisition_cases and requisition_cases[0].requisition_status == RequisitionStatus.RECEIVED:
requisition_receipt.send(sender=None, requisitions=requisition_cases)
if requisition_cases and requisition_cases[0].requisition_status == RequisitionStatus.REQUESTED:
requisition_modified.send(sender=None, cases=requisition_cases)
示例12: testReceiptsWithNoOpenRequisition
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)))
示例13: testSimplePack
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)
示例14: get_transactions
def get_transactions(self):
for case_id in self.get_case_ids():
# this is going to hit the db a lot
c = RequisitionCase.get(case_id)
yield(RequisitionResponse(
product_id = c.product_id,
case_id=c._id,
action_name=self.action_name,
value=c.get_default_value(),
inferred=True,
config=self.config,
))
示例15: testSimpleFulfill
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')