summaryrefslogtreecommitdiff
path: root/addons/purchase/tests/test_create_picking.py
diff options
context:
space:
mode:
authorArnold Moyaux <arm@odoo.com>2017-11-21 14:15:21 +0100
committerArnold Moyaux <arm@odoo.com>2017-11-27 14:50:52 +0100
commit9e0724088ba674b22c23d03c723d789e10101e77 (patch)
tree1f64f5e3fd679139149c1a1704a96ee4fb079d18 /addons/purchase/tests/test_create_picking.py
parent4e333607f1d37c7d76ac614647c064705ddf5752 (diff)
[FIX] purchase: cancel rfq set destination move to mts
Use case to reproduce: - Create a SO with a product MTO and confirm the PO -> PO -- Stock -- SO - Cancel the SO -> PO -- Stock canceled SO - Set the quotation to draft and confirm it again -> PO -- Stock RFQ -- Stock -- SO - If the user cancel the RFQ we will get this diagram: -> PO -- Stock Stock -- SO The user can't reserve the chain correctly. Also a new RFQ will be generated each time the user delete the existing one even if the PO already exists. It happens because the move keep the procure methode MTO although the moves origin and destination links are broken. This commit changes the move destination from purchase order line to MTS if the RFQ is deleted. This implies that RFQ are not automatically generated by the scheduler.
Diffstat (limited to 'addons/purchase/tests/test_create_picking.py')
-rw-r--r--addons/purchase/tests/test_create_picking.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/addons/purchase/tests/test_create_picking.py b/addons/purchase/tests/test_create_picking.py
index c276c1f2264..b29e85b3825 100644
--- a/addons/purchase/tests/test_create_picking.py
+++ b/addons/purchase/tests/test_create_picking.py
@@ -90,3 +90,87 @@ class TestCreatePicking(common.TestProductCommon):
# PO approved by manager
self.po.button_approve()
self.assertEqual(self.po.state, 'purchase', 'PO state should be "Purchase".')
+
+ def test_02_check_mto_chain(self):
+ """ Simulate a mto chain with a purchase order. Cancel the
+ purchase order should also change the procure_method of the
+ following move to MTS in order to be able to link it to a
+ manually created purchase order.
+ """
+ stock_location = self.env['ir.model.data'].xmlid_to_object('stock.stock_location_stock')
+ customer_location = self.env['ir.model.data'].xmlid_to_object('stock.stock_location_customers')
+ # route buy should be there by default
+ partner = self.env['res.partner'].create({
+ 'name': 'Jhon'
+ })
+
+ vendor = self.env['res.partner'].create({
+ 'name': 'Roger'
+ })
+
+ seller = self.env['product.supplierinfo'].create({
+ 'name': partner.id,
+ 'price': 12.0,
+ })
+
+ product = self.env['product.product'].create({
+ 'name': 'product',
+ 'type': 'product',
+ 'route_ids': [(4, self.ref('stock.route_warehouse0_mto')), (4, self.ref('purchase.route_warehouse0_buy'))],
+ 'seller_ids': [(6, 0, [seller.id])],
+ 'categ_id': self.env.ref('product.product_category_all').id,
+ })
+
+ customer_move = self.env['stock.move'].create({
+ 'name': 'move out',
+ 'location_id': stock_location.id,
+ 'location_dest_id': customer_location.id,
+ 'product_id': product.id,
+ 'product_uom': product.uom_id.id,
+ 'product_uom_qty': 100.0,
+ 'procure_method': 'make_to_order',
+ })
+
+ customer_move._action_confirm()
+
+ purchase_order = self.env['purchase.order'].search([('partner_id', '=', partner.id)])
+ self.assertTrue(purchase_order, 'No purchase order created.')
+
+ # Check purchase order line data.
+ purchase_order_line = purchase_order.order_line
+ self.assertEqual(purchase_order_line.product_id, product, 'The product on the purchase order line is not correct.')
+ self.assertEqual(purchase_order_line.price_unit, seller.price, 'The purchase order line price should be the same than the seller.')
+ self.assertEqual(purchase_order_line.product_qty, customer_move.product_uom_qty, 'The purchase order line qty should be the same than the move.')
+ self.assertEqual(purchase_order_line.price_subtotal, 1200.0, 'The purchase order line subtotal should be equal to the move qty * seller price.')
+
+ purchase_order.button_cancel()
+ self.assertEqual(purchase_order.state, 'cancel', 'Purchase order should be cancelled.')
+ self.assertEqual(customer_move.procure_method, 'make_to_stock', 'Customer move should be passed to mts.')
+
+ purchase = purchase_order.create({
+ 'partner_id': vendor.id,
+ 'order_line': [
+ (0, 0, {
+ 'name': product.name,
+ 'product_id': product.id,
+ 'product_qty': 100.0,
+ 'product_uom': product.uom_po_id.id,
+ 'price_unit': 11.0,
+ 'date_planned': datetime.today().strftime(DEFAULT_SERVER_DATETIME_FORMAT),
+ })],
+ })
+ self.assertTrue(purchase, 'RFQ should be created')
+ purchase.button_confirm()
+
+ picking = purchase.picking_ids
+ self.assertTrue(picking, 'Picking should be created')
+
+ # Process pickings
+ picking.action_confirm()
+ picking.move_lines.quantity_done = 100.0
+ picking.button_validate()
+
+ self.assertEqual(self.env['stock.quant']._get_available_quantity(product, stock_location), 100.0, 'Wrong quantity in stock.')
+
+ customer_move._action_assign()
+ self.assertEqual(customer_move.state, 'assigned', 'Reservation should work with the new quantity provided by the PO.')