本文整理匯總了Python中stoqlib.domain.product.ProductHistory.add_produced_item方法的典型用法代碼示例。如果您正苦於以下問題:Python ProductHistory.add_produced_item方法的具體用法?Python ProductHistory.add_produced_item怎麽用?Python ProductHistory.add_produced_item使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類stoqlib.domain.product.ProductHistory
的用法示例。
在下文中一共展示了ProductHistory.add_produced_item方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: produce
# 需要導入模塊: from stoqlib.domain.product import ProductHistory [as 別名]
# 或者: from stoqlib.domain.product.ProductHistory import add_produced_item [as 別名]
def produce(self, quantity, produced_by=None, serials=None):
"""Sets a certain quantity as produced. The quantity will be marked as
produced only if there are enough materials allocated, otherwise a
ValueError exception will be raised.
:param quantity: the quantity that will be produced.
"""
assert self.can_produce(quantity)
# check if its ok to produce before consuming material
if self.product.has_quality_tests():
# We have some quality tests to assure. Register it for later
assert produced_by
assert len(serials) == quantity
# We only support yield quantity > 1 when there are no tests
assert self.product.yield_quantity == 1
self.store.savepoint(u'before_produce')
for component in self.get_components():
material = self._get_material_from_component(component)
needed_material = quantity * component.quantity
try:
material.consume(needed_material)
except ValueError:
self.store.rollback_to_savepoint(u'before_produce')
raise
if self.product.has_quality_tests():
for serial in serials:
ProductionProducedItem(store=self.store,
order=self.order,
product=self.product,
produced_by=produced_by,
produced_date=localnow(),
serial_number=serial,
entered_stock=False)
else:
# There are no quality tests for this product. Increase stock
# right now.
storable = self.product.storable
# A production process may yield more than one unit of this product
yield_quantity = quantity * self.product.yield_quantity
storable.increase_stock(yield_quantity, self.order.branch,
StockTransactionHistory.TYPE_PRODUCTION_PRODUCED,
self.id)
self.produced += quantity
self.order.try_finalize_production()
ProductHistory.add_produced_item(self.store, self.order.branch, self)