Skip to content

Commit

Permalink
[TEST] Using a warehouse context in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Sausin committed Oct 30, 2015
1 parent 2c72fb1 commit f39f26c
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions stock_available_sale/tests/test_quoted_qty.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def setUp(self):
super(TestQuotedQty, self).setUp()

self.product = self.browse_ref('product.product_product_10')
self.wh_main = self.browse_ref('stock.warehouse0')
self.wh_ch = self.browse_ref('stock.stock_warehouse_shop0')

#  Create a UoM in the category of PCE
self.thousand = self.env['product.uom'].create({
Expand All @@ -46,15 +48,16 @@ def test_quoted_qty(self):
orders.action_cancel()

# The quoted quantity should be 0
self.assertEqual(self.product.quoted_qty, 0.0, "Check quoted_qty")
self.assertEqual(
self.product.quoted_qty, 0.0, "Check initial quoted quantity")

# Enter a Quotation
order1 = self.env['sale.order'].create({
'partner_id': self.ref('base.res_partner_2'),
'partner_invoice_id': self.ref('base.res_partner_address_8'),
'partner_shipping_id': self.ref('base.res_partner_address_8'),
'pricelist_id': self.ref('product.list0')
})
'pricelist_id': self.ref('product.list0'),
'warehouse_id': self.wh_main.id})
self.env['sale.order.line'].create({
'order_id': order1.id,
'name': 'Quotation 1',
Expand All @@ -63,15 +66,24 @@ def test_quoted_qty(self):
'state': 'draft',
'product_id': self.product.id})
# The quoted qty should match the single quotation
self.assertEqual(self.product.quoted_qty, 107.0, "Check quoted_qty")
self.assertEqual(
self.product.quoted_qty, 107.0, "Check total quoted quantity")
self.assertEqual(
self.product.with_context(warehouse=self.wh_main.id).quoted_qty,
107.0,
"Check quoted quantity in main WH")
self.assertEqual(
self.product.with_context(warehouse=self.wh_ch.id).quoted_qty,
0.0,
"Check quoted quantity in Chicago WH")

# Enter another Quotation
order2 = self.env['sale.order'].create({
'partner_id': self.ref('base.res_partner_2'),
'partner_invoice_id': self.ref('base.res_partner_address_9'),
'partner_shipping_id': self.ref('base.res_partner_address_9'),
'pricelist_id': self.ref('product.list0')
})
'pricelist_id': self.ref('product.list0'),
'warehouse_id': self.wh_ch.id})
self.env['sale.order.line'].create({
'order_id': order2.id,
'name': 'Quotation 2',
Expand All @@ -80,11 +92,27 @@ def test_quoted_qty(self):
'state': 'draft',
'product_id': self.product.id})
# The quoted qty should match the total of the quotations
self.assertEqual(self.product.quoted_qty, 720.0,
"Check Check quoted quantity")
self.assertEqual(
self.product.quoted_qty, 720.0, "Check total quoted quantity")
self.assertEqual(
self.product.with_context(warehouse=self.wh_main.id).quoted_qty,
107.0,
"Check quoted quantity in main WH")
self.assertEqual(
self.product.with_context(warehouse=self.wh_ch.id).quoted_qty,
613.0,
"Check quoted quantity in Chicago WH")

# Confirm one of the Quotations
order1.signal_workflow('order_confirm')
# The quoted qty should match the remaining quotation
self.assertEqual(self.product.quoted_qty, 613.0,
"Check Check quoted quantity")
self.assertEqual(
self.product.quoted_qty, 613.0, "Check Check quoted quantity")
self.assertEqual(
self.product.with_context(warehouse=self.wh_main.id).quoted_qty,
0.0,
"Check quoted quantity in main WH")
self.assertEqual(
self.product.with_context(warehouse=self.wh_ch.id).quoted_qty,
613.0,
"Check quoted quantity in Chicago WH")

0 comments on commit f39f26c

Please sign in to comment.