def _create_ledgers(self):
        case_type = 'case'

        case1 = CaseStructure(
            case_id='case1',
            attrs={
                'create': True,
                'case_type': case_type
            },
        )
        case2 = CaseStructure(
            case_id='case2',
            attrs={
                'create': True,
                'case_type': case_type
            },
        )  # case2 will have no ledgers
        self.ledgers = {
            'icecream':
            Balance(
                entity_id=case1.case_id,
                date=datetime(2017, 11, 21, 0, 0, 0, 0),
                section_id='test',
                entry=Entry(id='icecream', quantity=4),
            ),
            'blondie':
            Balance(
                entity_id=case1.case_id,
                date=datetime(2017, 11, 21, 0, 0, 0, 0),
                section_id='test',
                entry=Entry(id='blondie', quantity=5),
            )
        }
        self.device.post_changes([case1, case2])
        self.device.post_changes(list(self.ledgers.values()))
예제 #2
0
    def _create_ledgers(self):
        case_type = 'case'

        case1 = CaseStructure(
            case_id='case1',
            attrs={'create': True, 'case_type': case_type},
        )
        case2 = CaseStructure(
            case_id='case2',
            attrs={'create': True, 'case_type': case_type},
        )
        entry = Entry(id='icecream', quantity=4)
        self.balance = Balance(
            entity_id=case1.case_id,
            date=datetime(2017, 11, 21, 0, 0, 0, 0),
            section_id='test',
            entry=entry,
        )  # start case1 off with 4 items
        self.transfer = Transfer(
            src=case1.case_id,
            dest=case2.case_id,
            date=datetime(2017, 11, 21, 0, 0, 0, 0),
            type='stuff',
            section_id='test',
            entry=entry,
        )  # transfer all 4 items to case 2
        self.device.post_changes([case1, case2])
        transfer_form = self.device.post_changes([self.balance, self.transfer])
        self.transaction_date = transfer_form.received_on
예제 #3
0
def ledger_data():
    from casexml.apps.stock.mock import Balance
    from casexml.apps.case.mock import CaseFactory
    from casexml.apps.stock.mock import Entry

    factory = CaseFactory('domain')
    with case_data() as case_ids:
        balance_blocks = [
            Balance(
                entity_id=case_id,
                date=datetime.utcnow(),
                section_id='test',
                entry=Entry(id='chocolate', quantity=4),
            ).as_xml()
            for case_id in case_ids
        ]
        form, _ = factory.post_case_blocks(balance_blocks)

        ledgers = LedgerAccessorSQL.get_ledger_values_for_cases(case_ids)

        try:
            yield [ledger.ledger_id for ledger in ledgers]
        finally:
            form.delete()
            for ledger in ledgers:
                ledger.delete()
예제 #4
0
 def ledgers(self):
     """Dict of ledgers, keyed by entity ID, from the sync body"""
     ledgers = defaultdict(list)
     balance_nodes = self.xml.findall("{%s}balance" % COMMTRACK_REPORT_XMLNS)
     for balance_node in balance_nodes:
         balance_obj = Balance.from_xml(balance_node)
         ledgers[balance_obj.entity_id].append(balance_obj)
     return dict(ledgers)
예제 #5
0
파일: utils.py 프로젝트: dimagi/commcare-hq
 def ledgers(self):
     """Dict of ledgers, keyed by entity ID, from the sync body"""
     ledgers = defaultdict(list)
     balance_nodes = self.xml.findall("{%s}balance" % COMMTRACK_REPORT_XMLNS)
     for balance_node in balance_nodes:
         balance_obj = Balance.from_xml(balance_node)
         ledgers[balance_obj.entity_id].append(balance_obj)
     return dict(ledgers)
예제 #6
0
def missing_ledger_patch(diff):
    ref = diff.ref
    data = diff.old_value["ledger"]
    return Balance(
        entity_id=ref.case_id,
        date=iso_string_to_datetime(data["last_modified"]).date(),
        section_id=ref.section_id,
        entry=Entry(id=ref.entry_id, quantity=data["balance"]),
    )
예제 #7
0
def _ledger_update_xml(episode_case_id, entry_id, ledger_value):
    balance = Balance()
    balance.entity_id = episode_case_id
    balance.date = datetime.utcnow()
    balance.section_id = EPISODE_LEDGER_SECTION_ID
    balance.entry = Entry(id=entry_id, quantity=ledger_value)
    return balance
예제 #8
0
def ledger_balance_patch(diff):
    assert isinstance(diff.old_value, (Decimal, int, float)), diff
    ref = diff.ref
    stock = StockState.objects.get(
        case_id=ref.case_id,
        section_id=ref.section_id,
        product_id=ref.entry_id,
    )
    return Balance(
        entity_id=ref.case_id,
        date=stock.last_modified_date.date(),
        section_id=ref.section_id,
        entry=Entry(id=ref.entry_id, quantity=diff.old_value),
    )