本文整理汇总了Python中casexml.apps.stock.models.StockTransaction.subtype方法的典型用法代码示例。如果您正苦于以下问题:Python StockTransaction.subtype方法的具体用法?Python StockTransaction.subtype怎么用?Python StockTransaction.subtype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类casexml.apps.stock.models.StockTransaction
的用法示例。
在下文中一共展示了StockTransaction.subtype方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_models
# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import subtype [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()
示例2: create_models_for_stock_report
# 需要导入模块: from casexml.apps.stock.models import StockTransaction [as 别名]
# 或者: from casexml.apps.stock.models.StockTransaction import subtype [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()