[MIG] sale_sourced_by_line: to Odoo 13.0

This commit is contained in:
Jared Kipe
2020-10-31 08:48:59 -07:00
parent 56be117f49
commit 3f99c57fe2
3 changed files with 113 additions and 15 deletions

View File

@@ -3,21 +3,61 @@ from odoo.tests import common
class TestSaleSources(common.TransactionCase):
def test_plan_two_warehouses(self):
partner = self.env.ref('base.res_partner_2')
product_1 = self.env.ref('product.product_product_24_product_template')
product_2 = self.env.ref('product.product_product_16_product_template')
wh_1 = self.env.ref('stock.stock_warehouse_shop0')
wh_2 = self.env.ref('stock.warehouse0')
def setUp(self):
super(TestSaleSources, self).setUp()
self.partner = self.env.ref('base.res_partner_2')
self.product_1 = self.env['product.product'].create({
'type': 'consu',
'name': 'Test Product 1',
})
self.product_2 = self.env['product.product'].create({
'type': 'consu',
'name': 'Test Product 2',
})
self.wh_1 = self.env.ref('stock.warehouse0')
self.wh_2 = self.env['stock.warehouse'].create({
'name': 'Test WH2',
'code': 'TWH2',
})
def test_plan_one_warehouse(self):
so = self.env['sale.order'].create({
'warehouse_id': wh_1.id,
'partner_id': partner.id,
'warehouse_id': self.wh_1.id,
'partner_id': self.partner.id,
'date_planned': '2018-01-01',
'order_line': [(0, 0, {'product_id': product_1.product_variant_id.id}),
(0, 0, {'product_id': product_2.product_variant_id.id, 'date_planned': '2018-02-01', 'warehouse_id': wh_2.id})]
'order_line': [(0, 0, {
'product_id': self.product_1.id,
'product_uom_qty': 1.0,
'product_uom': self.product_1.uom_id.id,
'price_unit': 10.0,
}),
(0, 0, {
'product_id': self.product_2.id,
'product_uom_qty': 1.0,
'product_uom': self.product_2.uom_id.id,
'price_unit': 10.0,
})]
})
so.action_confirm()
self.assertTrue(so.state in ('sale', 'done'))
self.assertEqual(len(so.picking_ids), 1)
self.assertEqual(len(so.picking_ids.filtered(lambda p: p.picking_type_id.warehouse_id == self.wh_1)), 1)
self.assertEqual(len(so.picking_ids.filtered(lambda p: p.picking_type_id.warehouse_id == self.wh_2)), 0)
def test_plan_two_warehouses(self):
so = self.env['sale.order'].create({
'warehouse_id': self.wh_1.id,
'partner_id': self.partner.id,
'date_planned': '2018-01-01',
'order_line': [(0, 0, {'product_id': self.product_1.id}),
(0, 0, {'product_id': self.product_2.id,
'date_planned': '2018-02-01', 'warehouse_id': self.wh_2.id})]
})
# in 13 default computation, this would result in a failure
self.assertTrue(so.order_line.filtered(lambda l: l.warehouse_id))
so.action_confirm()
self.assertTrue(so.state in ('sale', 'done'))
self.assertEqual(len(so.picking_ids), 2)
self.assertEqual(len(so.picking_ids.filtered(lambda p: p.picking_type_id.warehouse_id == wh_1)), 1)
self.assertEqual(len(so.picking_ids.filtered(lambda p: p.picking_type_id.warehouse_id == wh_2)), 1)
self.assertEqual(len(so.picking_ids.filtered(lambda p: p.picking_type_id.warehouse_id == self.wh_1)), 1)
self.assertEqual(len(so.picking_ids.filtered(lambda p: p.picking_type_id.warehouse_id == self.wh_2)), 1)