Пример #1
0
def _tx_new(type_, delta, updated_balance, age):
    return LedgerTransaction(
        type=type_,
        delta=delta,
        updated_balance=updated_balance,
        report_date=ago(age)
    )
Пример #2
0
def _get_ledger_transaction(lazy_original_balance, stock_report_helper,
                            stock_trans, new_balance):
    return LedgerTransaction(form_id=stock_report_helper.form_id,
                             server_date=stock_report_helper.server_date,
                             report_date=stock_report_helper.timestamp,
                             type=_report_type_to_ledger_type(
                                 stock_report_helper.report_type),
                             case_id=stock_trans.case_id,
                             section_id=stock_trans.section_id,
                             entry_id=stock_trans.product_id,
                             user_defined_type=stock_trans.subaction,
                             delta=new_balance - lazy_original_balance(),
                             updated_balance=new_balance)
Пример #3
0
 def delete_ledger_transactions_for_form(case_ids, form_id):
     """
     Delete LedgerTransactions for form.
     :param case_ids: list of case IDs which ledger transactions belong to (required for correct sharding)
     :param form_id:  ID of the form
     :return: number of transactions deleted
     """
     assert isinstance(case_ids, list)
     with LedgerTransaction.get_plproxy_cursor() as cursor:
         cursor.execute(
             "SELECT delete_ledger_transactions_for_form(%s, %s) as deleted_count",
             [case_ids, form_id])
         results = fetchall_as_namedtuple(cursor)
         return sum([result.deleted_count for result in results])