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


Python StockTransaction.save方法代码示例

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


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

示例1: create_models

# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import save [as 别名]
 def create_models(self, domain=None):
     # todo: this function should probably move to somewhere in casexml.apps.stock
     if self.tag not in stockconst.VALID_REPORT_TYPES:
         return
     report = DbStockReport.objects.create(
         form_id=self.form_id,
         date=self.timestamp,
         type=self.tag,
         domain=self._form.domain,
     )
     for txn in self.transactions:
         db_txn = DbStockTransaction(
             report=report,
             case_id=txn.case_id,
             section_id=txn.section_id,
             product_id=txn.product_id,
         )
         if domain:
             # set this as a shortcut for post save signal receivers
             db_txn.domain = domain
         db_txn.type = txn.action
         db_txn.subtype = txn.subaction
         if self.tag == stockconst.REPORT_TYPE_BALANCE:
             db_txn.stock_on_hand = txn.quantity
             db_txn.quantity = 0
         else:
             assert self.tag == stockconst.REPORT_TYPE_TRANSFER
             previous_transaction = db_txn.get_previous_transaction()
             db_txn.quantity = txn.relative_quantity
             db_txn.stock_on_hand = (previous_transaction.stock_on_hand if previous_transaction else 0) + db_txn.quantity
         db_txn.save()
开发者ID:elbowink,项目名称:commcare-hq,代码行数:33,代码来源:models.py

示例2: _test_subtype

# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import save [as 别名]
    def _test_subtype(self, initial, final):
        case_id = uuid.uuid4().hex
        CommCareCase(
            _id=case_id,
            domain='fakedomain',
        ).save()

        product_id = uuid.uuid4().hex
        SQLProduct(product_id=product_id, domain='fakedomain').save()
        report = StockReport.objects.create(
            form_id=uuid.uuid4().hex,
            date=ago(1),
            server_date=datetime.utcnow(),
            type=const.REPORT_TYPE_BALANCE
        )

        txn = StockTransaction(
            report=report,
            section_id=const.SECTION_TYPE_STOCK,
            type=const.TRANSACTION_TYPE_STOCKONHAND,
            subtype=initial,
            case_id=case_id,
            product_id=product_id,
            stock_on_hand=Decimal(10),
        )
        txn.save()

        saved = StockTransaction.objects.get(id=txn.id)
        self.assertEqual(final, saved.subtype)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:31,代码来源:test_stock_transaction.py

示例3: create_transactions

# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import save [as 别名]
    def create_transactions(self, domain=None):
        report = StockReport.objects.create(
            form_id=uuid.uuid4().hex,
            date=ago(2),
            type=const.REPORT_TYPE_BALANCE,
            domain=domain
        )

        txn = StockTransaction(
            report=report,
            section_id=const.SECTION_TYPE_STOCK,
            type=const.TRANSACTION_TYPE_STOCKONHAND,
            case_id=self.case_id,
            product_id=self.product_id,
            stock_on_hand=Decimal(10),
        )
        txn.save()

        report2 = StockReport.objects.create(
            form_id=uuid.uuid4().hex,
            date=ago(1),
            type=const.REPORT_TYPE_BALANCE,
            domain=domain
        )

        txn2 = StockTransaction(
            report=report2,
            section_id=const.SECTION_TYPE_STOCK,
            type=const.TRANSACTION_TYPE_STOCKONHAND,
            case_id=self.case_id,
            product_id=self.product_id,
            stock_on_hand=Decimal(30),
        )
        txn2.save()
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:36,代码来源:test_logistics_consumption.py

示例4: _create_model_for_stock_transaction

# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import save [as 别名]
def _create_model_for_stock_transaction(report, transaction_helper):
    assert report.type in stockconst.VALID_REPORT_TYPES
    txn = StockTransaction(
        report=report,
        case_id=transaction_helper.case_id,
        section_id=transaction_helper.section_id,
        product_id=transaction_helper.product_id,
        type=transaction_helper.action,
        subtype=transaction_helper.subaction,
    )

    def lazy_original_balance():
        previous_transaction = txn.get_previous_transaction()
        if previous_transaction:
            return previous_transaction.stock_on_hand
        else:
            return None

    new_ledger_values = compute_ledger_values(
        lazy_original_balance, report.type,
        transaction_helper.relative_quantity)

    txn.stock_on_hand = new_ledger_values.balance
    txn.quantity = new_ledger_values.delta

    if report.domain:
        # set this as a shortcut for post save signal receivers
        txn.domain = report.domain
    txn.save()
    return txn
开发者ID:ekush,项目名称:commcare-hq,代码行数:32,代码来源:processing.py

示例5: _receipt_report

# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import save [as 别名]
def _receipt_report(case_id, product_id, amount, days_ago):
    report = StockReport.objects.create(form_id=uuid.uuid4().hex, date=ago(days_ago), type=const.REPORT_TYPE_TRANSFER)
    txn = StockTransaction(
        report=report,
        section_id=const.SECTION_TYPE_STOCK,
        type=const.TRANSACTION_TYPE_RECEIPTS,
        case_id=case_id,
        product_id=product_id,
        quantity=amount,
    )
    previous_transaction = txn.get_previous_transaction()
    txn.stock_on_hand = (previous_transaction.stock_on_hand if previous_transaction else 0) + txn.quantity
    txn.save()
开发者ID:dimagi,项目名称:casexml,代码行数:15,代码来源:base.py

示例6: _stock_report

# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import save [as 别名]
def _stock_report(case_id, product_id, amount, days_ago):
    report = StockReport.objects.create(form_id=uuid.uuid4().hex, date=ago(days_ago), type=const.REPORT_TYPE_BALANCE)
    txn = StockTransaction(
        report=report,
        section_id=const.SECTION_TYPE_STOCK,
        type=const.TRANSACTION_TYPE_STOCKONHAND,
        case_id=case_id,
        product_id=product_id,
        stock_on_hand=Decimal(amount),
    )
    txn._test_config = ConsumptionConfiguration.test_config()
    txn.quantity = 0
    txn.save()
开发者ID:dimagi,项目名称:casexml,代码行数:15,代码来源:base.py

示例7: _create_stock_state

# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import save [as 别名]
 def _create_stock_state(self, product, consumption):
     xform = XFormInstance.get('test-xform')
     loc = Location.by_site_code(TEST_DOMAIN, 'garms')
     now = datetime.datetime.utcnow()
     report = StockReport(
         form_id=xform._id,
         date=(now - datetime.timedelta(days=10)).replace(second=0, microsecond=0),
         type='balance',
         domain=TEST_DOMAIN
     )
     report.save()
     stock_transaction = StockTransaction(
         case_id=loc.linked_supply_point().get_id,
         product_id=product.get_id,
         sql_product=SQLProduct.objects.get(product_id=product.get_id),
         section_id='stock',
         type='stockonhand',
         stock_on_hand=2 * consumption,
         report=report
     )
     stock_transaction.save()
开发者ID:nnestle,项目名称:commcare-hq,代码行数:23,代码来源:utils.py

示例8: create_models_for_stock_report

# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import save [as 别名]
def create_models_for_stock_report(domain, stock_report_helper):
    """
    Save stock report and stock transaction models to the database.
    """
    assert stock_report_helper._form.domain == domain
    domain = domain
    if stock_report_helper.tag not in stockconst.VALID_REPORT_TYPES:
        return
    report = StockReport.objects.create(
        form_id=stock_report_helper.form_id,
        date=stock_report_helper.timestamp,
        type=stock_report_helper.tag,
        domain=domain,
    )
    for txn in stock_report_helper.transactions:
        db_txn = StockTransaction(
            report=report,
            case_id=txn.case_id,
            section_id=txn.section_id,
            product_id=txn.product_id,
        )
        if domain:
            # set this as a shortcut for post save signal receivers
            db_txn.domain = domain
        db_txn.type = txn.action
        db_txn.subtype = txn.subaction
        if stock_report_helper.tag == stockconst.REPORT_TYPE_BALANCE:
            db_txn.stock_on_hand = txn.quantity
            db_txn.quantity = 0
        else:
            assert stock_report_helper.tag == stockconst.REPORT_TYPE_TRANSFER
            previous_transaction = db_txn.get_previous_transaction()
            db_txn.quantity = txn.relative_quantity
            db_txn.stock_on_hand = db_txn.quantity + (
                previous_transaction.stock_on_hand
                if previous_transaction else 0
            )
        db_txn.save()
开发者ID:idiene,项目名称:commcare-hq,代码行数:40,代码来源:processing.py


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