Beispiel #1
0
def process_stock(xform, case_db=None):
    """
    process the commtrack xml constructs in an incoming submission
    """
    case_db = case_db or CaseDbCache()
    assert isinstance(case_db, CaseDbCache)

    stock_report_helpers, case_actions = get_stock_actions(xform)
    # omitted: normalize_transactions (used for bulk requisitions?)

    # validate product ids
    if any(transaction_helper.product_id in ('', None)
            for stock_report_helper in stock_report_helpers
            for transaction_helper in stock_report_helper.transactions):
        raise MissingProductId(
            _('Product IDs must be set for all ledger updates!'))

    relevant_cases = []
    # touch every case for proper ota restore logic syncing to be preserved
    for case_id, case_action in case_actions:
        case = case_db.get(case_id)
        relevant_cases.append(case)
        if case is None:
            raise IllegalCaseId(
                _('Ledger transaction references invalid Case ID "{}"')
                .format(case_id))

        # hack: clear the sync log id so this modification always counts
        # since consumption data could change server-side
        case_action.sync_log_id = ''
        case.actions.append(case_action)
        case_db.mark_changed(case)
Beispiel #2
0
 def validate(self):
     """
     Validates this object as best we can and raises Exceptions if we find anything invalid .
     """
     if any(transaction_helper.product_id in ('', None)
            for transaction_helper in self.transactions):
         raise MissingProductId(
             _('Product IDs must be set for all ledger updates!'))