예제 #1
0
    def testStockReceipt(self):
        original_amounts = {"pp": 10, "pq": 20, "pr": 30}

        # First submit an soh so we can make sure receipts functions
        # differently than soh
        handle(
            self.users[0].get_verified_number(),
            "soh {loc} {report}".format(
                loc="loc1", report=" ".join("%s %s" % (k, v) for k, v in original_amounts.items())
            ),
        )

        received_amounts = {"pp": 1, "pq": 2, "pr": 3}

        handled = handle(
            self.users[0].get_verified_number(),
            "r {loc} {report}".format(
                loc="loc1", report=" ".join("%s %s" % (k, v) for k, v in received_amounts.items())
            ),
        )

        self.assertTrue(handled)

        self.check_form_type("receipts")

        for code in original_amounts.keys():
            expected_amount = original_amounts[code] + received_amounts[code]
            self.check_stock(code, expected_amount)
    def testStockConsumption(self):
        original_amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }

        # First submit an soh so we can make sure consumption functions properly
        handle(self.users[0].get_verified_number(), 'soh {loc} {report}'.format(
            loc='loc1',
            report=' '.join('%s %s' % (k, v) for k, v in original_amounts.items())
        ))

        lost_amounts = {
            'pp': 1,
            'pq': 2,
            'pr': 3,
        }

        handled = handle(self.users[0].get_verified_number(), 'c {loc} {report}'.format(
            loc='loc1',
            report=' '.join('%s %s' % (k, v) for k, v in lost_amounts.items())
        ))

        self.assertTrue(handled)

        # this is the only difference from losses..
        self.check_form_type('consumption')

        for code in original_amounts.keys():
            expected_amount = original_amounts[code] - lost_amounts[code]
            self.check_stock(code, expected_amount)
예제 #3
0
    def testStockLosses(self):
        original_amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }

        # First submit an soh so we can make sure losses functions properly
        handle(get_two_way_number_for_recipient(self.users[0]), 'soh {loc} {report}'.format(
            loc='loc1',
            report=' '.join('%s %s' % (k, v) for k, v in original_amounts.items())
        ), None)

        lost_amounts = {
            'pp': 1,
            'pq': 2,
            'pr': 3,
        }

        handled = handle(get_two_way_number_for_recipient(self.users[0]), 'l {loc} {report}'.format(
            loc='loc1',
            report=' '.join('%s %s' % (k, v) for k, v in lost_amounts.items())
        ), None)

        self.assertTrue(handled)

        self.check_form_type('consumption', 'loss')

        for code in original_amounts.keys():
            expected_amount = original_amounts[code] - lost_amounts[code]
            self.check_stock(code, expected_amount)
    def testStockReceipt(self):
        original_amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }

        # First submit an soh so we can make sure receipts functions
        # differently than soh
        handle(self.users[0].get_verified_number(), 'soh {loc} {report}'.format(
            loc='loc1',
            report=' '.join('%s %s' % (k, v) for k, v in original_amounts.items())
        ))

        received_amounts = {
            'pp': 1,
            'pq': 2,
            'pr': 3,
        }

        handled = handle(self.users[0].get_verified_number(), 'r {loc} {report}'.format(
            loc='loc1',
            report=' '.join('%s %s' % (k, v) for k, v in received_amounts.items())
        ))

        self.assertTrue(handled)

        self.check_form_type('receipts')

        for code in original_amounts.keys():
            expected_amount = original_amounts[code] + received_amounts[code]
            self.check_stock(code, expected_amount)
예제 #5
0
    def testStockConsumption(self):
        original_amounts = {"pp": 10, "pq": 20, "pr": 30}

        # First submit an soh so we can make sure consumption functions properly
        handle(
            self.users[0].get_verified_number(),
            "soh {loc} {report}".format(
                loc="loc1", report=" ".join("%s %s" % (k, v) for k, v in original_amounts.items())
            ),
        )

        lost_amounts = {"pp": 1, "pq": 2, "pr": 3}

        handled = handle(
            self.users[0].get_verified_number(),
            "c {loc} {report}".format(loc="loc1", report=" ".join("%s %s" % (k, v) for k, v in lost_amounts.items())),
        )

        self.assertTrue(handled)

        # this is the only difference from losses..
        self.check_form_type("consumption")

        for code in original_amounts.keys():
            expected_amount = original_amounts[code] - lost_amounts[code]
            self.check_stock(code, expected_amount)
예제 #6
0
    def testStockLosses(self):
        original_amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }

        # First submit an soh so we can make sure losses functions properly
        handle(
            get_two_way_number_for_recipient(self.users[0]),
            'soh {loc} {report}'.format(
                loc='loc1',
                report=' '.join('%s %s' % (k, v)
                                for k, v in original_amounts.items())), None)

        lost_amounts = {
            'pp': 1,
            'pq': 2,
            'pr': 3,
        }

        handled = handle(
            get_two_way_number_for_recipient(self.users[0]),
            'l {loc} {report}'.format(
                loc='loc1',
                report=' '.join('%s %s' % (k, v)
                                for k, v in lost_amounts.items())), None)

        self.assertTrue(handled)

        self.check_form_type('consumption', 'loss')

        for code in original_amounts.keys():
            expected_amount = original_amounts[code] - lost_amounts[code]
            self.check_stock(code, expected_amount)
예제 #7
0
    def testStockConsumption(self):
        original_amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }

        # First submit an soh so we can make sure consumption functions properly
        handle(
            self.users[0].get_verified_number(), 'soh {loc} {report}'.format(
                loc='loc1',
                report=' '.join('%s %s' % (k, v)
                                for k, v in original_amounts.items())))

        lost_amounts = {
            'pp': 1,
            'pq': 2,
            'pr': 3,
        }

        handled = handle(
            self.users[0].get_verified_number(), 'c {loc} {report}'.format(
                loc='loc1',
                report=' '.join('%s %s' % (k, v)
                                for k, v in lost_amounts.items())))

        self.assertTrue(handled)

        # this is the only difference from losses..
        self.check_form_type('consumption')

        for code in original_amounts.keys():
            expected_amount = original_amounts[code] - lost_amounts[code]
            self.check_stock(code, expected_amount)
    def testStockReceipt(self):
        original_amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }

        # First submit an soh so we can make sure receipts functions
        # differently than soh
        handle(get_two_way_number_for_recipient(self.users[0]), 'soh {loc} {report}'.format(
            loc='loc1',
            report=' '.join('%s %s' % (k, v) for k, v in original_amounts.items())
        ), None)

        received_amounts = {
            'pp': 1,
            'pq': 2,
            'pr': 3,
        }

        handled = handle(get_two_way_number_for_recipient(self.users[0]), 'r {loc} {report}'.format(
            loc='loc1',
            report=' '.join('%s %s' % (k, v) for k, v in received_amounts.items())
        ), None)

        self.assertTrue(handled)

        self.check_form_type('receipts')

        for code in original_amounts.keys():
            expected_amount = original_amounts[code] + received_amounts[code]
            self.check_stock(code, expected_amount)
예제 #9
0
    def testApprovalBadLocations(self):
        self.testRequisition()

        try:
            handle(self.verified_number, 'approve')
            self.fail("empty locations should fail")
        except SMSError, e:
            self.assertEqual('must specify a location code', str(e))
예제 #10
0
    def inactive_testApprovalBadLocations(self):
        self.testRequisition()

        try:
            handle(self.user.get_verified_number(), 'approve')
            self.fail("empty locations should fail")
        except SMSError, e:
            self.assertEqual('must specify a location code', str(e))
예제 #11
0
    def testStockReportRoaming(self):
        self.assertEqual([], list(iter_commtrack_forms(self.domain.name)))
        amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }
        # soh loc1 pp 10 pq 20...
        handled = handle(
            get_two_way_number_for_recipient(self.users[0]),
            'soh {loc} {report}'.format(
                loc='loc1',
                report=' '.join('%s %s' % (k, v) for k, v in amounts.items())),
            None)
        self.assertTrue(handled)
        forms = list(iter_commtrack_forms(self.domain.name))
        self.assertEqual(1, len(forms))
        self.assertEqual(_get_location_from_sp(self.sp),
                         _get_location_from_form(forms[0]))

        ledger_transactions = LedgerAccessorSQL.get_ledger_transactions_for_case(
            self.sp.case_id)
        self.assertEqual({forms[0].form_id},
                         set(t.form_id for t in ledger_transactions))
        self.assertEqual({'balance'},
                         set(t.readable_type for t in ledger_transactions))
        self.assertEqual(3, len(ledger_transactions))

        self.check_transaction_amounts(ledger_transactions, amounts)
예제 #12
0
    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')
    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))
예제 #14
0
    def testStockReportRoaming(self):
        self.assertEqual(0, len(self.get_commtrack_forms(self.domain.name)))
        amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }
        # soh loc1 pp 10 pq 20...
        handled = handle(self.users[0].get_verified_number(), 'soh {loc} {report}'.format(
            loc='loc1',
            report=' '.join('%s %s' % (k, v) for k, v in amounts.items())
        ))
        self.assertTrue(handled)
        forms = list(self.get_commtrack_forms(self.domain.name))
        self.assertEqual(1, len(forms))
        self.assertEqual(_get_location_from_sp(self.sp), _get_location_from_form(forms[0]))

        self.assertEqual(1, StockReport.objects.count())
        report = StockReport.objects.all()[0]
        self.assertEqual(forms[0]._id, report.form_id)
        self.assertEqual('balance', report.type)
        self.assertEqual(3, report.stocktransaction_set.count())

        for code, amt in amounts.items():
            [product] = filter(lambda p: p.code_ == code, self.products)
            trans = StockTransaction.objects.get(product_id=product._id)
            self.assertEqual(self.sp._id, trans.case_id)
            self.assertEqual(0, trans.quantity)
            self.assertEqual(amt, trans.stock_on_hand)
예제 #15
0
    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.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)))
    def testStockReportFixed(self):
        self.assertEqual(0, len(get_commtrack_forms(self.domain.name)))

        amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }
        # soh loc1 pp 10 pq 20...
        handled = handle(
            get_two_way_number_for_recipient(self.users[1]),
            'soh {report}'.format(report=' '.join(
                '%s %s' % (k, v) for k, v in amounts.items())), None)
        self.assertTrue(handled)
        forms = list(get_commtrack_forms(self.domain.name))
        self.assertEqual(1, len(forms))
        self.assertEqual(_get_location_from_sp(self.sp),
                         _get_location_from_form(forms[0]))

        for code, amt in amounts.items():
            [product] = filter(lambda p: p.code_ == code, self.products)
            trans = StockTransaction.objects.get(product_id=product._id)
            self.assertEqual(self.sp.case_id, trans.case_id)
            self.assertEqual(0, trans.quantity)
            self.assertEqual(amt, trans.stock_on_hand)
    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)
예제 #18
0
    def testStockReportRoaming(self):
        self.assertEqual(0, len(get_commtrack_forms(self.domain.name)))
        amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }
        # soh loc1 pp 10 pq 20...
        handled = handle(
            get_two_way_number_for_recipient(self.users[0]),
            'soh {loc} {report}'.format(
                loc='loc1',
                report=' '.join('%s %s' % (k, v) for k, v in amounts.items())),
            None)
        self.assertTrue(handled)
        forms = list(get_commtrack_forms(self.domain.name))
        self.assertEqual(1, len(forms))
        self.assertEqual(_get_location_from_sp(self.sp),
                         _get_location_from_form(forms[0]))

        self.assertEqual(1, StockReport.objects.count())
        report = StockReport.objects.all()[0]
        self.assertEqual(forms[0]._id, report.form_id)
        self.assertEqual('balance', report.type)
        self.assertEqual(3, report.stocktransaction_set.count())

        for code, amt in amounts.items():
            [product] = [p for p in self.products if p.code_ == code]
            trans = StockTransaction.objects.get(product_id=product._id)
            self.assertEqual(self.sp.case_id, trans.case_id)
            self.assertEqual(0, trans.quantity)
            self.assertEqual(amt, trans.stock_on_hand)
예제 #19
0
class StockRequisitionTest(CommTrackTest):
    requisitions_enabled = True

    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.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)

    def testApprovalBadLocations(self):
        self.testRequisition()

        try:
            handle(self.verified_number, 'approve')
            self.fail("empty locations should fail")
        except SMSError, e:
            self.assertEqual('must specify a location code', str(e))

        try:
            handle(self.verified_number, 'approve notareallocation')
            self.fail("unknown locations should fail")
        except SMSError, e:
            self.assertTrue('invalid location code' in str(e))
예제 #20
0
    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')
예제 #21
0
 def testStockReport(self):
     amounts = {
         'pp': 10,
         'pq': 20,
         'pr': 30,
     }
     # soh loc1 pp 10 pq 20...
     handled = handle(self.verified_number, 'soh {loc} {report}'.format(
         loc='loc1',
         report=' '.join('%s %s' % (k, v) for k, v in amounts.items())
     ))
     self.assertTrue(handled)
     for code, amt in amounts.items():
         spp = CommCareCase.get(self.spps[code]._id)
         self.assertEqual(str(amt), spp.current_stock)
    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)))
예제 #23
0
 def testRequisition(self):
     amounts = {
         'pp': 10,
         'pq': 20,
         'pr': 30,
     }
     # soh loc1 pp 10 pq 20...
     handled = handle(self.verified_number, 'req {loc} {report}'.format(
         loc='loc1',
         report=' '.join('%s %s' % (k, v) for k, v in amounts.items())
     ))
     self.assertTrue(handled)
     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 = CommCareCase.get(req_ref.referenced_id)
         self.assertEqual(str(amt), req_case.amount_requested)
예제 #24
0
    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))
예제 #25
0
    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.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))
예제 #26
0
    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')
    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)
예제 #28
0
    def testStockReportFixed(self):
        self.assertEqual(0, len(self.get_commtrack_forms(self.domain.name)))

        amounts = {"pp": 10, "pq": 20, "pr": 30}
        # soh loc1 pp 10 pq 20...
        handled = handle(
            self.users[1].get_verified_number(),
            "soh {report}".format(report=" ".join("%s %s" % (k, v) for k, v in amounts.items())),
        )
        self.assertTrue(handled)
        forms = list(self.get_commtrack_forms(self.domain.name))
        self.assertEqual(1, len(forms))
        self.assertEqual(_get_location_from_sp(self.sp), _get_location_from_form(forms[0]))

        for code, amt in amounts.items():
            [product] = filter(lambda p: p.code_ == code, self.products)
            trans = StockTransaction.objects.get(product_id=product._id)
            self.assertEqual(self.sp._id, trans.case_id)
            self.assertEqual(0, trans.quantity)
            self.assertEqual(amt, trans.stock_on_hand)
예제 #29
0
    def testSimplePack(self):
        self.testRequisition()

        # pack loc1
        handled = handle(self.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)
예제 #30
0
    def testStockReportFixed(self):
        self.assertEqual([], list(iter_commtrack_forms(self.domain.name)))
        amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }
        # soh loc1 pp 10 pq 20...
        handled = handle(
            get_two_way_number_for_recipient(self.users[1]),
            'soh {report}'.format(report=' '.join(
                '%s %s' % (k, v) for k, v in amounts.items())), None)
        self.assertTrue(handled)
        forms = list(iter_commtrack_forms(self.domain.name))
        self.assertEqual(1, len(forms))
        self.assertEqual(_get_location_from_sp(self.sp),
                         _get_location_from_form(forms[0]))

        ledger_transactions = LedgerAccessorSQL.get_ledger_transactions_for_case(
            self.sp.case_id)
        self.check_transaction_amounts(ledger_transactions, amounts)
    def testStockReportFixed(self):
        self.assertEqual(0, len(self.get_commtrack_forms()))

        amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }
        # soh loc1 pp 10 pq 20...
        handled = handle(self.reporters['fixed'].get_verified_number(), 'soh {report}'.format(
            report=' '.join('%s %s' % (k, v) for k, v in amounts.items())
        ))
        self.assertTrue(handled)
        forms = list(self.get_commtrack_forms())
        self.assertEqual(1, len(forms))
        self.assertEqual(self.sp.location_, forms[0].location_)

        for code, amt in amounts.items():
            spp = CommCareCase.get(self.spps[code]._id)
            self.assertEqual(self.sp.location_, spp.location_)
            self.assertEqual(str(amt), spp.current_stock)
예제 #32
0
    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.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)
예제 #33
0
    def testStockReport(self):
        self.assertEqual(0, len(self.get_commtrack_forms()))

        amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }
        # soh loc1 pp 10 pq 20...
        handled = handle(
            self.verified_number, 'soh {loc} {report}'.format(
                loc='loc1',
                report=' '.join('%s %s' % (k, v) for k, v in amounts.items())))
        self.assertTrue(handled)
        forms = list(self.get_commtrack_forms())
        self.assertEqual(1, len(forms))
        self.assertEqual(self.sp.location_, forms[0].location_)

        for code, amt in amounts.items():
            spp = CommCareCase.get(self.spps[code]._id)
            self.assertEqual(self.sp.location_, spp.location_)
            self.assertEqual(str(amt), spp.current_stock)
예제 #34
0
    def testStockReportFixed(self):
        self.assertEqual(0, len(get_commtrack_forms(self.domain.name)))

        amounts = {
            'pp': 10,
            'pq': 20,
            'pr': 30,
        }
        # soh loc1 pp 10 pq 20...
        handled = handle(get_two_way_number_for_recipient(self.users[1]), 'soh {report}'.format(
            report=' '.join('%s %s' % (k, v) for k, v in amounts.items())
        ), None)
        self.assertTrue(handled)
        forms = list(get_commtrack_forms(self.domain.name))
        self.assertEqual(1, len(forms))
        self.assertEqual(_get_location_from_sp(self.sp), _get_location_from_form(forms[0]))

        for code, amt in amounts.items():
            [product] = [p for p in self.products if p.code_ == code]
            trans = StockTransaction.objects.get(product_id=product._id)
            self.assertEqual(self.sp.case_id, trans.case_id)
            self.assertEqual(0, trans.quantity)
            self.assertEqual(amt, trans.stock_on_hand)
예제 #35
0
    def test_soh_and_receipt(self):
        handled = handle(self.users[0].get_verified_number(), 'pp 20.30')
        self.assertTrue(handled)

        self.check_stock('pp', Decimal(20))
예제 #36
0
    def test_soh_and_receipt(self):
        handled = handle(get_two_way_number_for_recipient(self.users[0]),
                         'pp 20.30', None)
        self.assertTrue(handled)

        self.check_stock('pp', Decimal(20))
예제 #37
0
    def test_soh_and_receipt(self):
        handled = handle(self.users[0].get_verified_number(), 'pp 20.30')
        self.assertTrue(handled)

        self.check_stock('pp', Decimal(20))
예제 #38
0
    def test_soh_and_receipt(self):
        handled = handle(get_two_way_number_for_recipient(self.users[0]), 'pp 20.30', None)
        self.assertTrue(handled)

        self.check_stock('pp', Decimal(20))