Skip to content
Snippets Groups Projects
Commit 5456f198 authored by Walid HANNICHE (waha)'s avatar Walid HANNICHE (waha)
Browse files

[FIX] sale_coupon: move global coupons to the end of the SO


Steps to reproduce:
 - Install website_sale_coupon
 - Load demo data
 - Create a promotion program that applies on the order
 - Go to the webshop and add 2 different products to the cart

Bug:
The line of promotion is in second place, instead of at the end.

Fix:
move the old sale order line to the end if it applies on all the order

opw-2985632

closes odoo/odoo#102700

Signed-off-by: default avatarWilliam Braeckman (wbr) <wbr@odoo.com>
parent e03fae1f
No related branches found
No related tags found
No related merge requests found
......@@ -406,6 +406,10 @@ class SaleOrder(models.Model):
def update_line(order, lines, values):
'''Update the lines and return them if they should be deleted'''
lines_to_remove = self.env['sale.order.line']
# move global coupons to the end of the SO
if program.discount_apply_on == 'on_order':
values['sequence'] = max(order.order_line.mapped('sequence')) + 1
# Check commit 6bb42904a03 for next if/else
# Remove reward line if price or qty equal to 0
if values['product_uom_qty'] and values['price_unit']:
......
......@@ -50,3 +50,38 @@ class TestSaleInvoicing(TestSaleCouponCommon):
self.assertEqual(order.order_line, invoiceable_lines)
account_move = order._create_invoices()
self.assertEqual(len(account_move.invoice_line_ids), 2)
def test_coupon_on_order_sequence(self):
# discount_coupon_program
self.env['sale.coupon.program'].create({
'name': '10% Discount', # Default behavior
'program_type': 'coupon_program',
'reward_type': 'discount',
'discount_apply_on': 'on_order',
'promo_code_usage': 'no_code_needed',
})
order = self.empty_order
# orderline1
self.env['sale.order.line'].create({
'product_id': self.env.ref('product.product_product_6').id,
'name': 'largeCabinet',
'product_uom_qty': 1.0,
'order_id': order.id,
})
order.recompute_coupon_lines()
self.assertEqual(len(order.order_line), 2, 'Coupon correctly applied')
# orderline2
self.env['sale.order.line'].create({
'product_id': self.env.ref('product.product_product_11').id,
'name': 'conferenceChair',
'product_uom_qty': 1.0,
'order_id': order.id,
})
order.recompute_coupon_lines()
self.assertEqual(len(order.order_line), 3, 'Coupon correctly applied')
self.assertTrue(order.order_line.sorted(lambda x: x.sequence)[-1].is_reward_line, 'Global coupons appear on the last line')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment