diff --git a/models/sale_order.py b/models/sale_order.py index e0f91648823..0d11cd8c159 100644 --- a/models/sale_order.py +++ b/models/sale_order.py @@ -13,14 +13,14 @@ class SaleOrder(models.Model): lines = self.order_line.filtered(lambda line: line.is_delivery or line.product_id in free_delivery_product) return lines + super(SaleOrder, self)._get_no_effect_on_threshold_lines() - def _get_order_lines_tax_included_amount(self): + def _get_paid_order_lines(self): """ Returns the taxes included sale order total amount without the rewards amount""" free_reward_product = self.env['sale.coupon.program'].search([('reward_type', '=', 'product')]).mapped('discount_line_product_id') - return sum([x.price_total for x in self.order_line.filtered(lambda x: not (x.is_reward_line or x.is_delivery) or x.product_id in free_reward_product)]) + return self.order_line.filtered(lambda x: not (x.is_reward_line or x.is_delivery) or x.product_id in free_reward_product) def _get_reward_line_values(self, program): if program.reward_type == 'free_shipping': - return self._get_reward_values_free_shipping(program) + return [self._get_reward_values_free_shipping(program)] else: return super(SaleOrder, self)._get_reward_line_values(program) @@ -40,9 +40,9 @@ class SaleOrder(models.Model): 'tax_id': [(4, tax.id, False) for tax in taxes], } - def _get_lines_unit_prices(self): + def _get_cheapest_line(self): # Unit prices tax included - return [x.price_total / x.product_uom_qty for x in self.order_line.filtered(lambda x: not x.is_delivery and not x.is_reward_line)] + return min(self.order_line.filtered(lambda x: not x.is_reward_line and not x.is_delivery and x.price_unit > 0), key=lambda x: x['price_unit']) class SalesOrderLine(models.Model): _inherit = "sale.order.line" diff --git a/tests/test_free_shipping_reward.py b/tests/test_free_shipping_reward.py index 5c8cce3d1a4..175a06d0c76 100644 --- a/tests/test_free_shipping_reward.py +++ b/tests/test_free_shipping_reward.py @@ -120,6 +120,9 @@ class TestSaleCouponProgramRules(TestSaleCouponCommon): self.assertEqual(len(order.order_line.ids), 3, "We should get the delivery line but not the free delivery since we are below 872.73$ with the 10% discount") p_minimum_threshold_free_delivery.sequence = 10 + (order.order_line - sol1).unlink() + order.carrier_id = self.env['delivery.carrier'].search([])[1] + order.delivery_set() order.recompute_coupon_lines() self.assertEqual(len(order.order_line.ids), 4, "We should get both promotion line since the free delivery will be applied first and won't change the SO total") @@ -193,5 +196,5 @@ class TestSaleCouponProgramRules(TestSaleCouponCommon): }) p_specific_product.discount_apply_on = 'cheapest_product' order.recompute_coupon_lines() - # 872.73 - (20% of 1 iPad) = 872.73 - 64 = 808.73 - self.assertEqual(order.amount_untaxed, 808.73, "One iPad should be discounted by 20%") + # 872.73 - (20% of 1 iPad) = 872.73 - 58.18 = 814.55 + self.assertEqual(order.amount_untaxed, 814.55, "One iPad should be discounted by 20%")