summaryrefslogtreecommitdiff
path: root/addons/sale_stock/tests
diff options
context:
space:
mode:
authorSimon Lejeune <sle@openerp.com>2019-07-29 11:43:30 +0000
committerSimon Lejeune <sle@openerp.com>2019-07-29 14:49:12 +0000
commit8a3284685856b6980e3b620abdbbb3e2c79f57c4 (patch)
treed68ba11f927022cd1b83a8c81c23dad322c498e5 /addons/sale_stock/tests
parenta894bb590849a29cae01b81fd1b10b468b2ae751 (diff)
[REF] sale_stock: delivered and procurement quantity
Share the logic for delivered and procurement quantities computation. In some edge cases, the differences between them triggered an unexpected behaviour such as showcased in the added tests. closes odoo/odoo#35257 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com> Co-authored-by: Arnold Moyaux <arm@odoo.com>
Diffstat (limited to 'addons/sale_stock/tests')
-rw-r--r--addons/sale_stock/tests/test_sale_stock.py66
1 files changed, 65 insertions, 1 deletions
diff --git a/addons/sale_stock/tests/test_sale_stock.py b/addons/sale_stock/tests/test_sale_stock.py
index 47fd2408bd3..a6b6c26940d 100644
--- a/addons/sale_stock/tests/test_sale_stock.py
+++ b/addons/sale_stock/tests/test_sale_stock.py
@@ -494,4 +494,68 @@ class TestSaleStock(TestSale):
})
so1.picking_ids.button_validate()
self.assertEqual(so1.picking_ids.state, 'done')
- self.assertEqual(so1.order_line.mapped('qty_delivered'), [1, 1, 1]) \ No newline at end of file
+ self.assertEqual(so1.order_line.mapped('qty_delivered'), [1, 1, 1])
+
+ def test_08_quantities(self):
+ """Change the picking code of the receipts to internal. Make a SO for 10 units, go to the
+ picking and return 5, edit the SO line to 15 units.
+
+ The purpose of the test is to check the consistencies across the delivered quantities and the
+ procurement quantities.
+ """
+ # Change the code of the picking type receipt
+ self.env['stock.picking.type'].search([('code', '=', 'incoming')]).write({'code': 'internal'})
+
+ # Sell and deliver 10 units
+ item1 = self.products['prod_order']
+ uom_unit = self.env.ref('uom.product_uom_unit')
+ so1 = self.env['sale.order'].create({
+ 'partner_id': self.partner.id,
+ 'order_line': [
+ (0, 0, {
+ 'name': item1.name,
+ 'product_id': item1.id,
+ 'product_uom_qty': 10,
+ 'product_uom': uom_unit.id,
+ 'price_unit': item1.list_price,
+ }),
+ ],
+ })
+ so1.action_confirm()
+
+ picking = so1.picking_ids
+ wiz_act = picking.button_validate()
+ wiz = self.env[wiz_act['res_model']].browse(wiz_act['res_id'])
+ wiz.process()
+
+ # Return 5 units
+ stock_return_picking_form = Form(self.env['stock.return.picking'].with_context(
+ active_ids=picking.ids,
+ active_id=picking.ids[0],
+ active_model='stock.picking'
+ ))
+ return_wiz = stock_return_picking_form.save()
+ for return_move in return_wiz.product_return_moves:
+ return_move.write({
+ 'quantity': 5,
+ 'to_refund': True
+ })
+ res = return_wiz.create_returns()
+ return_pick = self.env['stock.picking'].browse(res['res_id'])
+ wiz_act = return_pick.button_validate()
+ wiz = self.env[wiz_act['res_model']].browse(wiz_act['res_id'])
+ wiz.process()
+
+ self.assertEqual(so1.order_line.qty_delivered, 5)
+
+ # Deliver 15 instead of 10.
+ so1.write({
+ 'order_line': [
+ (1, so1.order_line[0].id, {'product_uom_qty': 15}),
+ ]
+ })
+
+ # A new move of 10 unit (15 - 5 units)
+ self.assertEqual(so1.order_line.qty_delivered, 5)
+ self.assertEqual(so1.picking_ids[-1].move_lines.product_qty, 10)
+