Permalink
Browse files

[IMP] purchase_stock:Move cancel propagation RFQ and PO.

-add a testcase test_move_cancel_propagation.
-In testcase we are check the state of receipts steps and delivery steps.
-when cancelled purchase order it will cancelled all related receiption steps not delivery steps.
  • Loading branch information...
anr-odoo committed Feb 1, 2019
1 parent a028fd7 commit 9224bd11b270755d7f358f4cb626d4169a7ed2af
@@ -14,3 +14,4 @@
from . import test_stockvaluation
from . import test_replenish_wizard
from . import test_reordering_rule
from . import test_move_cancel_propagation
@@ -0,0 +1,247 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import tagged
from .common import TestPurchase


@tagged('post_install', '-at_install')
class TestMoveCancelPropagation(TestPurchase):
def setUp(self):
super(TestMoveCancelPropagation, self).setUp()
self.warehouse = self.env.ref('stock.warehouse0')
cust_location = self.env.ref('stock.stock_location_customers')
self.customer = self.env['res.partner'].create({'name': 'abc'})
seller = self.env['product.supplierinfo'].create({
'name': self.customer.id,
'price': 100.0,
})
product = self.env['product.product'].create({
'name': 'Geyser',
'type': 'product',
'route_ids': [(4, self.route_mto), (4, self.route_buy)],
'seller_ids': [(6, 0, [seller.id])],
})
self.picking_out = self.env['stock.picking'].create({
'location_id': self.warehouse.out_type_id.default_location_src_id.id,
'location_dest_id': cust_location.id,
'partner_id': self.customer.id,
'picking_type_id': self.ref('stock.picking_type_out'),
})
self.move = self.env['stock.move'].create({
'name': product.name,
'product_id': product.id,
'product_uom_qty': 10,
'product_uom': product.uom_id.id,
'picking_id': self.picking_out.id,
'location_id': self.warehouse.out_type_id.default_location_src_id.id,
'location_dest_id': cust_location.id,
'procure_method': 'make_to_order',
})

self.procurement_group = self.env['procurement.group'].create({'partner_id': self.customer.id, 'name': self.picking_out.id})
self.picking_out.group_id = self.procurement_group.id
self.move.group_id = self.procurement_group.id

def test_cancel_draft_purchase_order_one_steps(self):
""" Check the picking and moves status related PO, When canceling purchase order
Ex.
1) Set 1 steps of receiption and delivery on the warehouse.
2) Create SO and related RFQ should be generated.
3) Cancel 'draft' purchase order should cancel releted < Receiption Picking >
not < SHIP >
"""
self.warehouse.write({'delivery_steps': 'ship_only', 'reception_steps': 'one_step'})
self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
self.picking_out.action_confirm()

# Find PO related to picking.
purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.customer.id)])
# Po should be create related picking.
self.assertTrue(purchase_order, 'purchase order is created.')

# Check status of Purchase Order
self.assertEqual(purchase_order.state, 'draft', "Purchase order should be in 'draft' state.")

# Cancel Purchase order.
purchase_order.button_cancel()

# Check the status of picking after canceling po.
self.assertNotEqual(self.picking_out.state, 'cancel')

def test_cancel_confirm_purchase_order_one_steps(self):
""" Check the picking and moves status related PO, When canceling purchase order
Ex.
1) Set 1 steps of receiption and delivery on the warehouse.
2) Create SO and related RFQ should be generated.
3) Cancel 'confirm' purchase order should cancel releted < Receiption Picking IN>
not < SHIP >
"""
self.warehouse.write({'delivery_steps': 'ship_only', 'reception_steps': 'one_step'})
self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
self.picking_out.action_confirm()

# Find PO related to picking.
purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.customer.id)])
# Po should be create related picking.
self.assertTrue(purchase_order, 'purchase order is created.')

# Check status of Purchase Order
self.assertEqual(purchase_order.state, 'draft', "Purchase order should be in 'draft' state.")
purchase_order .button_confirm()
picking_in = purchase_order.picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.in_type_id)
# Cancel Purchase order.
purchase_order .button_cancel()

# Check the status of picking after canceling po.
self.assertEquals(picking_in.state, 'cancel')
self.assertNotEqual(self.picking_out.state, 'cancel')

def test_cancel_draft_purchase_order_two_steps(self):
""" Check the picking and moves status related PO, When canceling purchase order
Ex.
1) Set 2 steps of receiption and delivery on the warehouse.
2) Create SO and related RFQ should be generated.
3) Cancel 'draft' purchase order should cancel releted < Receiption Picking INT>
not < PICK, SHIP >
"""
self.warehouse.write({'delivery_steps': 'pick_ship', 'reception_steps': 'two_steps'})
self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
self.picking_out.action_confirm()

# Find PO related to picking.
purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.customer.id)])
# Po should be create related picking.
self.assertTrue(purchase_order, 'purchase order is created.')

picking_ids = self.env['stock.picking'].search([('group_id', '=', self.procurement_group.id)])

internal = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.int_type_id)
pick = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.pick_type_id)

# Check status of Purchase Order
self.assertEqual(purchase_order.state, 'draft', "Purchase order should be in 'draft' state.")
# Cancel Purchase order.
purchase_order.button_cancel()

# Check the status of picking after canceling po.
for res in internal:
self.assertEqual(res.state, 'cancel')
self.assertNotEqual(pick.state, 'cancel')
self.assertNotEqual(self.picking_out.state, 'cancel')

def test_cancel_confirm_purchase_order_two_steps(self):
""" Check the picking and moves status related PO, When canceling purchase order
Ex.
1) Set 2 steps of receiption and delivery on the warehouse.
2) Create SO and related RFQ should be generated.
3) Cancel 'comfirm' purchase order should cancel releted < Receiption Picking IN, INT>
not < PICK, SHIP >
"""
self.warehouse.write({'delivery_steps': 'pick_ship', 'reception_steps': 'two_steps'})
self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
self.picking_out.action_confirm()

# Find PO related to picking.
purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.customer.id)])
# Po should be create related picking.
self.assertTrue(purchase_order, 'purchase order is created.')

picking_ids = self.env['stock.picking'].search([('group_id', '=', self.procurement_group.id)])

internal = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.int_type_id)
pick = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.pick_type_id)

# Check status of Purchase Order
self.assertEqual(purchase_order.state, 'draft', "Purchase order should be in 'draft' state.")

purchase_order.button_confirm()
picking_in = purchase_order.picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.in_type_id)
# Cancel Purchase order.
purchase_order.button_cancel()

# Check the status of picking after canceling po.
self.assertEqual(picking_in.state, 'cancel')
for res in internal:
self.assertEqual(res.state, 'cancel')
self.assertNotEqual(pick.state, 'cancel')
self.assertNotEqual(self.picking_out.state, 'cancel')

def test_cancel_draft_purchase_order_three_steps(self):
""" Check the picking and moves status related PO, When canceling purchase order
Ex.
1) Set 3 steps of receiption and delivery on the warehouse.
2) Create SO and related RFQ should be generated.
3) Cancel 'draft' purchase order should cancel releted < Receiption Picking IN>
not < PICK, PACK, SHIP >
"""
self.warehouse.write({'delivery_steps': 'pick_pack_ship', 'reception_steps': 'three_steps'})
self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
self.picking_out.action_confirm()

# Find PO related to picking.
purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.customer.id)])
# Po should be create related picking.
self.assertTrue(purchase_order, 'purchase order is created.')

picking_ids = self.env['stock.picking'].search([('group_id', '=', self.procurement_group.id)])

internal = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.int_type_id)
pick = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.pick_type_id)
pack = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.pack_type_id)

# Check status of Purchase Order
self.assertEqual(purchase_order.state, 'draft', "Purchase order should be in 'draft' state.")
# Cancel Purchase order.
purchase_order.button_cancel()

# Check the status of picking after canceling po.
for res in internal:
self.assertEqual(res.state, 'cancel')
self.assertNotEqual(pick.state, 'cancel')
self.assertNotEqual(pack.state, 'cancel')
self.assertNotEqual(self.picking_out.state, 'cancel')

def test_cancel_confirm_purchase_order_three_steps(self):
""" Check the picking and moves status related PO, When canceling purchase order
Ex.
1) Set 3 steps of receiption and delivery on the warehouse.
2) Create SO and related RFQ should be generated.
3) Cancel 'comfirm' purchase order should cancel releted < Receiption Picking IN, INT>
not < PICK, PACK, SHIP >
"""
self.warehouse.write({'delivery_steps': 'pick_pack_ship', 'reception_steps': 'three_steps'})
self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id})
self.picking_out.action_confirm()

# Find PO related to picking.
purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.customer.id)])
# Po should be create related picking.
self.assertTrue(purchase_order, 'purchase order is created.')

picking_ids = self.env['stock.picking'].search([('group_id', '=', self.procurement_group.id)])

internal = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.int_type_id)
pick = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.pick_type_id)
pack = picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.pack_type_id)

# Check status of Purchase Order
self.assertEqual(purchase_order.state, 'draft', "Purchase order should be in 'draft' state.")

purchase_order.button_confirm()
picking_in = purchase_order.picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse.in_type_id)
# Cancel Purchase order.
purchase_order.button_cancel()

# Check the status of picking after canceling po.
self.assertEqual(picking_in.state, 'cancel')
for res in internal:
self.assertEqual(res.state, 'cancel')
self.assertNotEqual(pick.state, 'cancel')
self.assertNotEqual(pack.state, 'cancel')
self.assertNotEqual(self.picking_out.state, 'cancel')

0 comments on commit 9224bd1

Please sign in to comment.