diff options
| author | William Henrotin <whe@odoo.com> | 2019-08-08 09:19:28 +0000 |
|---|---|---|
| committer | William Henrotin <whe@odoo.com> | 2019-08-13 07:54:38 +0000 |
| commit | fff2a30afba8b8f13ca03b1719f4e3c93174d1ae (patch) | |
| tree | a18fd91d7390688898570d79ddb66d99472d644a /addons/sale_stock/tests | |
| parent | c2c9d6d143af7f00bb07e391fe494c2496cdad88 (diff) | |
[IMP] sale_stock,sale_mrp: available quantities on sales order
Selling a product you don't have in stock anymore triggers a message
without pertinent information about available quantity.
This commit adds a little widget on sale order line to inform the salesman
there are not enough quantity available. Clicking on it will reveal:
* The estimated delivery date
* The actual quantity on hand
* The quantity forcasted at the estimated delivery date
For kit product, the quantities are the maximum occurence of kit available
regarding components quantities.
Task 2003485
closes odoo/odoo#34336
Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
Diffstat (limited to 'addons/sale_stock/tests')
| -rw-r--r-- | addons/sale_stock/tests/test_sale_stock.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/addons/sale_stock/tests/test_sale_stock.py b/addons/sale_stock/tests/test_sale_stock.py index 66b61fe8c97..9fd480aa392 100644 --- a/addons/sale_stock/tests/test_sale_stock.py +++ b/addons/sale_stock/tests/test_sale_stock.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from datetime import datetime, timedelta from odoo.addons.sale.tests.test_sale_common import TestSale from odoo.exceptions import UserError @@ -559,3 +560,49 @@ class TestSaleStock(TestSale): self.assertEqual(so1.order_line.qty_delivered, 5) self.assertEqual(so1.picking_ids[-1].move_lines.product_qty, 10) + def test_09_qty_available(self): + """ create a sale order in warehouse1, change to warehouse2 and check the + available quantities on sale order lines are well updated """ + # sell two products + item1 = self.products['prod_order'] + item1.type = 'product' + warehouse1 = self.env.ref('stock.warehouse0') + self.env['stock.quant']._update_available_quantity(item1, warehouse1.lot_stock_id, 10) + self.env['stock.quant']._update_reserved_quantity(item1, warehouse1.lot_stock_id, 3) + warehouse2 = self.env['stock.warehouse'].search([('id', '!=', warehouse1.id)], limit=1) + self.env['stock.quant']._update_available_quantity(item1, warehouse2.lot_stock_id, 5) + so = self.env['sale.order'].create({ + 'partner_id': self.partner.id, + 'order_line': [ + (0, 0, {'name': item1.name, 'product_id': item1.id, 'product_uom_qty': 1, 'product_uom': item1.uom_id.id, 'price_unit': item1.list_price}), + ], + }) + line = so.order_line[0] + self.assertAlmostEqual(line.scheduled_date, datetime.now(), delta=timedelta(seconds=10)) + self.assertEqual(line.virtual_available_at_date, 10) + self.assertEqual(line.free_qty_today, 7) + self.assertEqual(line.qty_available_today, 10) + self.assertEqual(line.warehouse_id, warehouse1) + self.assertEqual(line.qty_to_deliver, 1) + so.warehouse_id = warehouse2 + self.assertEqual(line.virtual_available_at_date, 5) + self.assertEqual(line.free_qty_today, 5) + self.assertEqual(line.qty_available_today, 5) + self.assertEqual(line.warehouse_id, warehouse2) + self.assertEqual(line.qty_to_deliver, 1) + + def test_10_qty_available(self): + """create a sale order containing three times the same product. The + quantity available should be different for the 3 lines""" + item1 = self.products['prod_order'] + item1.type = 'product' + self.env['stock.quant']._update_available_quantity(item1, self.env.ref('stock.stock_location_stock'), 10) + so = self.env['sale.order'].create({ + 'partner_id': self.partner.id, + 'order_line': [ + (0, 0, {'name': item1.name, 'product_id': item1.id, 'product_uom_qty': 5, 'product_uom': item1.uom_id.id, 'price_unit': item1.list_price}), + (0, 0, {'name': item1.name, 'product_id': item1.id, 'product_uom_qty': 5, 'product_uom': item1.uom_id.id, 'price_unit': item1.list_price}), + (0, 0, {'name': item1.name, 'product_id': item1.id, 'product_uom_qty': 5, 'product_uom': item1.uom_id.id, 'price_unit': item1.list_price}), + ], + }) + self.assertEqual(so.order_line.mapped('free_qty_today'), [10, 5, 0]) |
