changeset e4a56983f233 in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset;node=e4a56983f233
description:
        Add test scenario for Product Quantities by Warehouse

        issue8355
        review261481002
diffstat:

 tests/scenario_stock_product_quantities_by_warehouse.rst |  82 ++++++++++++++++
 tests/test_stock.py                                      |   5 +
 2 files changed, 87 insertions(+), 0 deletions(-)

diffs (101 lines):

diff -r 6df434421641 -r e4a56983f233 
tests/scenario_stock_product_quantities_by_warehouse.rst
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/scenario_stock_product_quantities_by_warehouse.rst  Wed May 22 
18:32:01 2019 +0200
@@ -0,0 +1,82 @@
+=====================================
+Stock Product Quantities by Warehouse
+=====================================
+
+Imports::
+
+    >>> import datetime
+    >>> from dateutil.relativedelta import relativedelta
+    >>> from decimal import Decimal
+    >>> from proteus import Model, Wizard, Report
+    >>> from trytond.tests.tools import activate_modules
+    >>> from trytond.modules.company.tests.tools import create_company, \
+    ...     get_company
+    >>> today = datetime.date.today()
+    >>> yesterday = today - relativedelta(days=1)
+    >>> tomorrow = today + relativedelta(days=1)
+
+Install stock Module::
+
+    >>> config = activate_modules('stock')
+
+Create company::
+
+    >>> _ = create_company()
+    >>> company = get_company()
+
+Create product::
+
+    >>> ProductUom = Model.get('product.uom')
+    >>> ProductTemplate = Model.get('product.template')
+    >>> unit, = ProductUom.find([('name', '=', 'Unit')])
+    >>> template = ProductTemplate()
+    >>> template.name = 'Product'
+    >>> template.default_uom = unit
+    >>> template.type = 'goods'
+    >>> template.list_price = Decimal('20')
+    >>> template.save()
+    >>> product, = template.products
+
+Get stock locations::
+
+    >>> Location = Model.get('stock.location')
+    >>> warehouse_loc, = Location.find([('code', '=', 'WH')])
+    >>> supplier_loc, = Location.find([('code', '=', 'SUP')])
+    >>> customer_loc, = Location.find([('code', '=', 'CUS')])
+    >>> storage_loc, = Location.find([('code', '=', 'STO')])
+
+Fill warehouse::
+
+   >>> Move = Model.get('stock.move')
+   >>> move = Move()
+   >>> move.product = product
+   >>> move.from_location = supplier_loc
+   >>> move.to_location = storage_loc
+   >>> move.uom = unit
+   >>> move.quantity = 10
+   >>> move.effective_date = yesterday
+   >>> move.unit_price = Decimal('10')
+   >>> move.click('do')
+
+Empty warehouse::
+
+   >>> move = Move()
+   >>> move.product = product
+   >>> move.from_location = storage_loc
+   >>> move.to_location = customer_loc
+   >>> move.uom = unit
+   >>> move.quantity = 4
+   >>> move.planned_date = tomorrow
+   >>> move.unit_price = Decimal('20')
+   >>> move.save()
+
+Check Product Quantities by Warehouse::
+
+   >>> ProductQuantitiesByWarehouse = 
Model.get('stock.product_quantities_warehouse')
+   >>> with config.set_context(
+   ...      product_template=template.id, warehouse=warehouse_loc.id):
+   ...   records = ProductQuantitiesByWarehouse.find([])
+   >>> len(records)
+   2
+   >>> [(r.date, r.quantity) for r in records] == [(yesterday, 10), (tomorrow, 
6)]
+   True
diff -r 6df434421641 -r e4a56983f233 tests/test_stock.py
--- a/tests/test_stock.py       Wed May 22 18:31:21 2019 +0200
+++ b/tests/test_stock.py       Wed May 22 18:32:01 2019 +0200
@@ -1403,6 +1403,11 @@
 def suite():
     suite = trytond.tests.test_tryton.suite()
     suite.addTests(unittest.TestLoader().loadTestsFromTestCase(StockTestCase))
+    suite.addTests(doctest.DocFileSuite(
+            'scenario_stock_product_quantities_by_warehouse.rst',
+            tearDown=doctest_teardown, encoding='utf-8',
+            checker=doctest_checker,
+            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
     suite.addTests(doctest.DocFileSuite('scenario_stock_shipment_out.rst',
             tearDown=doctest_teardown, encoding='utf-8',
             checker=doctest_checker,

Reply via email to