本文整理汇总了Python中casexml.apps.stock.models.StockTransaction.get_ordered_transactions_for_stock方法的典型用法代码示例。如果您正苦于以下问题:Python StockTransaction.get_ordered_transactions_for_stock方法的具体用法?Python StockTransaction.get_ordered_transactions_for_stock怎么用?Python StockTransaction.get_ordered_transactions_for_stock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类casexml.apps.stock.models.StockTransaction
的用法示例。
在下文中一共展示了StockTransaction.get_ordered_transactions_for_stock方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recalculate_domain_consumption
# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import get_ordered_transactions_for_stock [as 别名]
def recalculate_domain_consumption(domain):
"""
Given a domain, recalculate all saved consumption settings in that domain.
"""
# note: might get slow as this gets huge
found_doc_ids = DocDomainMapping.objects.filter(
domain_name=domain,
doc_type='CommCareCase',
).values_list('doc_id', flat=True)
products = Product.by_domain(domain)
for supply_point_id in found_doc_ids:
for product in products:
filtered_transactions = StockTransaction.get_ordered_transactions_for_stock(
supply_point_id, const.SECTION_TYPE_STOCK, product._id
)
if filtered_transactions:
update_stock_state_for_transaction(filtered_transactions[0])
示例2: recalculate_domain_consumption
# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import get_ordered_transactions_for_stock [as 别名]
def recalculate_domain_consumption(domain):
"""
Given a domain, recalculate all saved consumption settings in that domain.
"""
# note: might get slow as this gets huge
found_doc_ids = DocDomainMapping.objects.filter(
domain_name=domain,
doc_type='CommCareCase',
).values_list('doc_id', flat=True)
products = Product.by_domain(domain)
for supply_point_id in found_doc_ids:
for product in products:
try:
latest_transaction = StockTransaction.get_ordered_transactions_for_stock(
supply_point_id, const.SECTION_TYPE_STOCK, product._id
)[0]
except IndexError:
pass
else:
state = get_stock_state_for_transaction(latest_transaction)
daily_consumption = get_consumption_for_ledger(state)
state.daily_consumption = daily_consumption
with drop_connected_signals(post_save):
state.save()
示例3: _get_stats
# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import get_ordered_transactions_for_stock [as 别名]
def _get_stats(self):
stock_state = StockState.objects.get(**self._stock_state_key)
latest_txn = StockTransaction.latest(**self._stock_state_key)
all_txns = StockTransaction.get_ordered_transactions_for_stock(
**self._stock_state_key)
return stock_state, latest_txn, all_txns