summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2017-07-24 19:41:30 +0200
committerChristophe Simonis <chs@odoo.com>2017-07-24 19:41:30 +0200
commit06b670e6bab5e856dce9e4cf501de9ef5ebecf52 (patch)
tree7b3469b43caa48c038626d3e2c44ab89c1e193a7
parentf07ca36b9b8ea47c62cf1aec0428f4fa251b0e40 (diff)
parente2a255717fb941fffa1fcc8ed0c5e390fba76618 (diff)
[MERGE] forward port branch 9.0 up to e2a255717fb
-rw-r--r--addons/purchase/purchase.py4
-rw-r--r--addons/sale/sale.py2
-rw-r--r--addons/sale/tests/test_product_id_change.py48
-rw-r--r--addons/stock/models/stock_move.py4
-rw-r--r--addons/stock/tests/test_stock_flow.py67
5 files changed, 121 insertions, 4 deletions
diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py
index 2f78f16478b..814b0e9b7ff 100644
--- a/addons/purchase/purchase.py
+++ b/addons/purchase/purchase.py
@@ -395,6 +395,10 @@ class PurchaseOrder(models.Model):
picking = self.env['stock.picking'].create(res)
moves = order.order_line.filtered(lambda r: r.product_id.type in ['product', 'consu'])._create_stock_moves(picking)
moves = moves.action_confirm()
+ seq = 0
+ for move in moves:
+ seq += 5
+ move.sequence = seq
moves.force_assign()
return True
diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index 328f0684c24..aa751f7ef8e 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -872,7 +872,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 ffac350cd5f..d7f8deacc33 100644
--- a/addons/sale/tests/test_product_id_change.py
+++ b/addons/sale/tests/test_product_id_change.py
@@ -64,3 +64,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/models/stock_move.py b/addons/stock/models/stock_move.py
index 3c526a66489..c35c73a9ba4 100644
--- a/addons/stock/models/stock_move.py
+++ b/addons/stock/models/stock_move.py
@@ -350,7 +350,7 @@ class StockMove(models.Model):
raise UserError(_('Cannot unreserve a done move'))
self.quants_unreserve()
if not self.env.context.get('no_state_change'):
- waiting = self.filtered(lambda move: move.get_ancestors())
+ waiting = self.filtered(lambda move: move.procure_method == 'make_to_order' or move.get_ancestors())
waiting.write({'state': 'waiting'})
(self - waiting).write({'state': 'confirmed'})
@@ -692,7 +692,7 @@ class StockMove(models.Model):
if len(reserved_quant_ids) == 0 and move.partially_available:
vals['partially_available'] = False
if move.state == 'assigned':
- if move.find_move_ancestors():
+ if move.procure_method == 'make_to_order' or move.find_move_ancestors():
vals['state'] = 'waiting'
else:
vals['state'] = 'confirmed'
diff --git a/addons/stock/tests/test_stock_flow.py b/addons/stock/tests/test_stock_flow.py
index 237329be363..87a42a36c9a 100644
--- a/addons/stock/tests/test_stock_flow.py
+++ b/addons/stock/tests/test_stock_flow.py
@@ -1683,4 +1683,69 @@ class TestStockFlow(TestStockCommon):
# force assign on the delivery order, it should be assigned
picking_out.force_assign()
- self.assertEquals(picking_out.state, "assigned") \ No newline at end of file
+ self.assertEquals(picking_out.state, "assigned")
+
+ def test_74_move_state_waiting_mto(self):
+ """ 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({
+ 'partner_id': self.partner_agrolite_id,
+ 'picking_type_id': self.picking_type_out,
+ 'location_id': self.stock_location,
+ 'location_dest_id': self.customer_location})
+ move_mto_alone = self.MoveObj.create({
+ 'name': self.productA.name,
+ 'product_id': self.productA.id,
+ 'product_uom_qty': 2,
+ 'product_uom': self.productA.uom_id.id,
+ 'picking_id': picking_out.id,
+ 'location_id': self.stock_location,
+ 'location_dest_id': self.customer_location,
+ 'procure_method':'make_to_order'})
+ move_with_ancestors = self.MoveObj.create({
+ 'name': self.productA.name,
+ 'product_id': self.productA.id,
+ 'product_uom_qty': 2,
+ 'product_uom': self.productA.uom_id.id,
+ 'picking_id': picking_out.id,
+ 'location_id': self.stock_location,
+ 'location_dest_id': self.customer_location})
+ self.MoveObj.create({
+ 'name': self.productA.name,
+ 'product_id': self.productA.id,
+ 'product_uom_qty': 2,
+ 'product_uom': self.productA.uom_id.id,
+ 'picking_id': picking_out.id,
+ 'location_id': self.stock_location,
+ 'location_dest_id': self.customer_location,
+ 'move_dest_id': move_with_ancestors.id})
+ other_move = self.MoveObj.create({
+ 'name': self.productA.name,
+ 'product_id': self.productA.id,
+ 'product_uom_qty': 2,
+ 'product_uom': self.productA.uom_id.id,
+ 'picking_id': picking_out.id,
+ 'location_id': self.stock_location,
+ 'location_dest_id': self.customer_location})
+
+ move_mto_alone.action_confirm()
+ move_with_ancestors.action_confirm()
+ other_move.action_confirm()
+
+ move_mto_alone.do_unreserve()
+ move_with_ancestors.do_unreserve()
+ other_move.do_unreserve()
+
+ self.assertEquals(move_mto_alone.state, "waiting")
+ self.assertEquals(move_with_ancestors.state, "waiting")
+ self.assertEquals(other_move.state, "confirmed")
+
+ move_mto_alone.recalculate_move_state()
+ move_with_ancestors.recalculate_move_state()
+ other_move.recalculate_move_state()
+
+ self.assertEquals(move_mto_alone.state, "waiting")
+ self.assertEquals(move_with_ancestors.state, "waiting")
+ self.assertEquals(other_move.state, "confirmed")