当前位置: 首页>>代码示例>>Python>>正文


Python LedgerAccessorSQL.save_ledger_values方法代码示例

本文整理汇总了Python中corehq.form_processor.backends.sql.dbaccessors.LedgerAccessorSQL.save_ledger_values方法的典型用法代码示例。如果您正苦于以下问题:Python LedgerAccessorSQL.save_ledger_values方法的具体用法?Python LedgerAccessorSQL.save_ledger_values怎么用?Python LedgerAccessorSQL.save_ledger_values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在corehq.form_processor.backends.sql.dbaccessors.LedgerAccessorSQL的用法示例。


在下文中一共展示了LedgerAccessorSQL.save_ledger_values方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_models_for_stock_report_helper

# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import LedgerAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.LedgerAccessorSQL import save_ledger_values [as 别名]
 def _create_models_for_stock_report_helper(self, form, stock_report_helper):
     processing_result = StockProcessingResult(form, stock_report_helpers=[stock_report_helper])
     processing_result.populate_models()
     if should_use_sql_backend(self.domain_name):
         from corehq.form_processor.backends.sql.dbaccessors import LedgerAccessorSQL
         LedgerAccessorSQL.save_ledger_values(processing_result.models_to_save)
     else:
         processing_result.commit()
开发者ID:dimagi,项目名称:commcare-hq,代码行数:10,代码来源:test_indicators.py

示例2: hard_rebuild_ledgers

# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import LedgerAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.LedgerAccessorSQL import save_ledger_values [as 别名]
 def hard_rebuild_ledgers(case_id, section_id=None, entry_id=None):
     transactions = LedgerAccessorSQL.get_ledger_transactions_for_case(case_id, section_id, entry_id)
     if not transactions:
         LedgerAccessorSQL.delete_ledger_values(case_id, section_id, entry_id)
         return
     ledger_value = LedgerAccessorSQL.get_ledger_value(case_id, section_id, entry_id)
     ledger_value = LedgerProcessorSQL._rebuild_ledger_value_from_transactions(ledger_value, transactions)
     LedgerAccessorSQL.save_ledger_values([ledger_value])
     publish_ledger_v2_saved(ledger_value)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:11,代码来源:ledger.py

示例3: process_form_unarchived

# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import LedgerAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.LedgerAccessorSQL import save_ledger_values [as 别名]
    def process_form_unarchived(self, form):
        from corehq.apps.commtrack.processing import process_stock

        result = process_stock([form])
        result.populate_models()
        LedgerAccessorSQL.save_ledger_values(result.models_to_save)
        for ledger_value in result.models_to_save:
            publish_ledger_v2_saved(ledger_value)

        refs_to_rebuild = {ledger_value.ledger_reference for ledger_value in result.models_to_save}
        for ref in refs_to_rebuild:
            self.rebuild_ledger_state(**ref._asdict())

        result.finalize()
开发者ID:dimagi,项目名称:commcare-hq,代码行数:16,代码来源:ledger.py

示例4: _get_daily_consumption_for_ledger

# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import LedgerAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.LedgerAccessorSQL import save_ledger_values [as 别名]
def _get_daily_consumption_for_ledger(ledger):
    from corehq.apps.commtrack.consumption import get_consumption_for_ledger_json
    daily_consumption = get_consumption_for_ledger_json(ledger)
    if should_use_sql_backend(ledger['domain']):
        from corehq.form_processor.backends.sql.dbaccessors import LedgerAccessorSQL
        ledger_value = LedgerAccessorSQL.get_ledger_value(
            ledger['case_id'], ledger['section_id'], ledger['entry_id']
        )
        ledger_value.daily_consumption = daily_consumption
        LedgerAccessorSQL.save_ledger_values([ledger_value])
    else:
        from corehq.apps.commtrack.models import StockState
        StockState.objects.filter(pk=ledger['_id']).update(daily_consumption=daily_consumption)

    return daily_consumption
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:17,代码来源:ledger.py

示例5: save_processed_models

# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import LedgerAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.LedgerAccessorSQL import save_ledger_values [as 别名]
    def save_processed_models(cls, processed_forms, cases=None, stock_result=None):
        with transaction.atomic():
            logging.debug('Beginning atomic commit\n')
            # Save deprecated form first to avoid ID conflicts
            if processed_forms.deprecated:
                FormAccessorSQL.save_deprecated_form(processed_forms.deprecated)

            FormAccessorSQL.save_new_form(processed_forms.submitted)
            if cases:
                for case in cases:
                    CaseAccessorSQL.save_case(case)

            if stock_result:
                ledgers_to_save = stock_result.models_to_save
                LedgerAccessorSQL.save_ledger_values(ledgers_to_save, processed_forms.deprecated)

        cls._publish_changes(processed_forms, cases, stock_result)
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:19,代码来源:processor.py

示例6: save_processed_models

# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import LedgerAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.LedgerAccessorSQL import save_ledger_values [as 别名]
    def save_processed_models(cls, processed_forms, cases=None, stock_result=None, publish_to_kafka=True):
        db_names = {processed_forms.submitted.db}
        if processed_forms.deprecated:
            db_names |= {processed_forms.deprecated.db}

        if cases:
            db_names |= {case.db for case in cases}

        if stock_result:
            db_names |= {
                ledger_value.db for ledger_value in stock_result.models_to_save
            }

        with ExitStack() as stack:
            for db_name in db_names:
                stack.enter_context(transaction.atomic(db_name))

            # Save deprecated form first to avoid ID conflicts
            if processed_forms.deprecated:
                FormAccessorSQL.update_form(processed_forms.deprecated, publish_changes=False)

            FormAccessorSQL.save_new_form(processed_forms.submitted)
            if cases:
                for case in cases:
                    CaseAccessorSQL.save_case(case)

            if stock_result:
                ledgers_to_save = stock_result.models_to_save
                LedgerAccessorSQL.save_ledger_values(ledgers_to_save, stock_result)

        if cases:
            sort_submissions = toggles.SORT_OUT_OF_ORDER_FORM_SUBMISSIONS_SQL.enabled(
                processed_forms.submitted.domain, toggles.NAMESPACE_DOMAIN)
            if sort_submissions:
                for case in cases:
                    if SqlCaseUpdateStrategy(case).reconcile_transactions_if_necessary():
                        CaseAccessorSQL.save_case(case)

        if publish_to_kafka:
            try:
                cls.publish_changes_to_kafka(processed_forms, cases, stock_result)
            except Exception as e:
                raise KafkaPublishingError(e)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:45,代码来源:processor.py

示例7: reprocess_form

# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import LedgerAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.LedgerAccessorSQL import save_ledger_values [as 别名]
def reprocess_form(form, save=True, lock_form=True):
    if lock_form:
        # track load if locking; otherise it will be tracked elsewhere
        form_load_counter("reprocess_form", form.domain)()
    interface = FormProcessorInterface(form.domain)
    lock = interface.acquire_lock_for_xform(form.form_id) if lock_form else None
    with LockManager(form, lock):
        logger.info('Reprocessing form: %s (%s)', form.form_id, form.domain)
        # reset form state prior to processing
        if should_use_sql_backend(form.domain):
            form.state = XFormInstanceSQL.NORMAL
        else:
            form.doc_type = 'XFormInstance'

        cache = interface.casedb_cache(
            domain=form.domain, lock=True, deleted_ok=True, xforms=[form],
            load_src="reprocess_form",
        )
        with cache as casedb:
            try:
                case_stock_result = SubmissionPost.process_xforms_for_cases([form], casedb)
            except (IllegalCaseId, UsesReferrals, MissingProductId,
                    PhoneDateValueError, InvalidCaseIndex, CaseValueError) as e:
                error_message = '{}: {}'.format(type(e).__name__, six.text_type(e))
                form = interface.xformerror_from_xform_instance(form, error_message)
                return ReprocessingResult(form, [], [], error_message)

            form.initial_processing_complete = True
            form.problem = None

            stock_result = case_stock_result.stock_result
            assert stock_result.populated

            cases = case_stock_result.case_models
            _log_changes(cases, stock_result.models_to_save, stock_result.models_to_delete)

            ledgers = []
            if should_use_sql_backend(form.domain):
                cases_needing_rebuild = _get_case_ids_needing_rebuild(form, cases)

                ledgers = stock_result.models_to_save
                ledgers_updated = {ledger.ledger_reference for ledger in ledgers if ledger.is_saved()}

                if save:
                    for case in cases:
                        CaseAccessorSQL.save_case(case)
                    LedgerAccessorSQL.save_ledger_values(ledgers)
                    FormAccessorSQL.update_form_problem_and_state(form)
                    FormProcessorSQL.publish_changes_to_kafka(ProcessedForms(form, None), cases, stock_result)

                # rebuild cases and ledgers that were affected
                for case in cases:
                    if case.case_id in cases_needing_rebuild:
                        logger.info('Rebuilding case: %s', case.case_id)
                        if save:
                            # only rebuild cases that were updated
                            detail = FormReprocessRebuild(form_id=form.form_id)
                            interface.hard_rebuild_case(case.case_id, detail, lock=False)

                for ledger in ledgers:
                    if ledger.ledger_reference in ledgers_updated:
                        logger.info('Rebuilding ledger: %s', ledger.ledger_reference)
                        if save:
                            # only rebuild updated ledgers
                            interface.ledger_processor.rebuild_ledger_state(**ledger.ledger_reference._asdict())

            else:
                if save:
                    interface.processor.save_processed_models([form], cases, stock_result)
                    from casexml.apps.stock.models import StockTransaction
                    ledgers = [
                        model
                        for model in stock_result.models_to_save
                        if isinstance(model, StockTransaction)
                    ]
                    for ledger in ledgers:
                        interface.ledger_processor.rebuild_ledger_state(**ledger.ledger_reference._asdict())

            save and SubmissionPost.do_post_save_actions(casedb, [form], case_stock_result)

        return ReprocessingResult(form, cases, ledgers, None)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:83,代码来源:reprocess.py


注:本文中的corehq.form_processor.backends.sql.dbaccessors.LedgerAccessorSQL.save_ledger_values方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。