diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index be116a45504..87d73cfbef1 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -410,6 +410,10 @@ class PurchaseOrder(models.Model): picking = pickings[0] moves = order.order_line._create_stock_moves(picking) moves = moves.filtered(lambda x: x.state not in ('done', 'cancel')).action_confirm() + seq = 0 + for move in moves: + seq += 5 + move.sequence = seq moves.force_assign() picking.message_post_with_view('mail.message_origin_link', values={'self': picking, 'origin': order}, diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 0499cb07f44..38a4036f609 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -918,7 +918,7 @@ class SaleOrderLine(models.Model): lang=self.order_id.partner_id.lang, partner=self.order_id.partner_id.id, quantity=self.product_uom_qty, - date_order=self.order_id.date_order, + date=self.order_id.date_order, pricelist=self.order_id.pricelist_id.id, uom=self.product_uom.id, fiscal_position=self.env.context.get('fiscal_position') diff --git a/addons/sale/tests/test_product_id_change.py b/addons/sale/tests/test_product_id_change.py index 4a795baa4c8..bf61c8d644f 100644 --- a/addons/sale/tests/test_product_id_change.py +++ b/addons/sale/tests/test_product_id_change.py @@ -68,3 +68,51 @@ class TestOnchangeProductId(TransactionCase): so_line = so.order_line[0] so_line.product_id_change() self.assertEquals(100, so_line.price_unit, "The included tax must be subtracted to the price") + + def test_pricelist_application(self): + """ Test different prices are correctly applied based on dates """ + support_product = self.env.ref('product.product_product_2') + support_product.list_price = 100 + partner = self.res_partner_model.create(dict(name="George")) + + christmas_pricelist = self.env['product.pricelist'].create({ + 'name': 'Christmas pricelist', + 'item_ids': [(0, 0, { + 'date_start': "2017-12-01", + 'date_end': "2017-12-24", + 'compute_price': 'percentage', + 'base': 'list_price', + 'percent_price': 20, + 'applied_on': '3_global', + 'name': 'Pre-Christmas discount' + }), (0, 0, { + 'date_start': "2017-12-25", + 'date_end': "2017-12-31", + 'compute_price': 'percentage', + 'base': 'list_price', + 'percent_price': 50, + 'applied_on': '3_global', + 'name': 'Post-Christmas super-discount' + })] + }) + + so = self.env['sale.order'].create({ + 'partner_id': partner.id, + 'date_order': '2017-12-20', + 'pricelist_id': christmas_pricelist.id, + }) + + order_line = self.env['sale.order.line'].new({ + 'order_id': so.id, + 'product_id': support_product.id, + }) + + # force compute uom and prices + order_line.product_id_change() + order_line.product_uom_change() + + self.assertEqual(order_line.price_unit, 80, "First date pricelist rule not applied") + + so.date_order = '2017-12-30' + order_line.product_id_change() + self.assertEqual(order_line.price_unit, 50, "Second date pricelist rule not applied") diff --git a/addons/stock/tests/test_stock_flow.py b/addons/stock/tests/test_stock_flow.py index 415214b7ca5..dbe76227118 100644 --- a/addons/stock/tests/test_stock_flow.py +++ b/addons/stock/tests/test_stock_flow.py @@ -1728,8 +1728,8 @@ class TestStockFlow(TestStockCommon): self.assertEquals(picking_out.state, "assigned") def test_74_move_state_waiting_mto(self): - """ This test will check that when a move is unreserved, it state change to 'waiting' if - it has ancestors or is has a 'procure_method' equal to 'make_to_order' else the state + """ This test will check that when a move is unreserved, its state changes to 'waiting' if + it has ancestors or if it has a 'procure_method' equal to 'make_to_order' else the state changes to 'confirmed'. """ picking_out = self.PickingObj.create({ @@ -1754,7 +1754,7 @@ class TestStockFlow(TestStockCommon): 'picking_id': picking_out.id, 'location_id': self.stock_location, 'location_dest_id': self.customer_location}) - the_ancestor = self.MoveObj.create({ + self.MoveObj.create({ 'name': self.productA.name, 'product_id': self.productA.id, 'product_uom_qty': 2,