[MERGE] forward port branch 9.0 up to e2a255717f
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
+1
-1
@@ -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')
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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")
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user