[FIX] website_sale_coupon: update freeshipping on delivery change

Since this module is not bridged to website_sale_delivery, there was no support for changing the freeshipping line
when changing the delivery carrier

Now it has, at the price of ugly code

OPW 1871526

closes odoo/enterprise#2651
This commit is contained in:
Lucas Perais (lpe)
2018-10-10 14:25:41 +00:00
parent 64484e0544
commit 76e7a7082b
3 changed files with 38 additions and 0 deletions
+24
View File
@@ -27,3 +27,27 @@ class WebsiteSale(WebsiteSale):
order = request.website.sale_get_order()
order.recompute_coupon_lines()
return super(WebsiteSale, self).cart(**post)
def _update_website_sale_coupon(self, **post):
order = request.website.sale_get_order()
order.recompute_coupon_lines()
free_shipping_lines = order._get_free_shipping_lines()
currency = order.currency_id
result = {}
if free_shipping_lines:
amount_free_shipping = sum(free_shipping_lines.mapped('price_subtotal'))
result.update({
'new_amount_delivery': self._format_amount(0.0, currency),
'new_amount_untaxed': self._format_amount(order.amount_untaxed, currency),
'new_amount_tax': self._format_amount(order.amount_tax, currency),
'new_amount_total': self._format_amount(order.amount_total, currency),
'new_amount_order_discounted': self._format_amount(order.reward_amount - amount_free_shipping, currency)
})
return result
# Override
# Add in the rendering the free_shipping_line
def _get_shop_payment_values(self, order, **kwargs):
values = super(WebsiteSale, self)._get_shop_payment_values(order, **kwargs)
values['free_shipping_lines'] = order._get_free_shipping_lines()
return values
+8
View File
@@ -61,3 +61,11 @@ class SaleOrder(models.Model):
res = super(SaleOrder, self)._cart_update(product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty, attributes=attributes, **kwargs)
self.recompute_coupon_lines()
return res
def _get_free_shipping_lines(self):
self.ensure_one()
free_shipping_prgs_ids = self.no_code_promo_program_ids.filtered(lambda p: p.reward_type == 'free_shipping')
if not free_shipping_prgs_ids:
return self.env['sale.order.line']
free_shipping_product_ids = free_shipping_prgs_ids.mapped('discount_line_product_id')
return self.order_line.filtered(lambda l: l.product_id in free_shipping_product_ids)
+6
View File
@@ -79,4 +79,10 @@
</div>
</xpath>
</template>
<template id="payment" name="Payment" inherit_id="website_sale.payment">
<xpath expr="//table[@id='cart_products']/tbody/tr/td[hasclass('td-price')]/child::*" position="attributes">
<attribute name="t-att-style">'display: None;' if line in free_shipping_lines else ''</attribute>
</xpath>
</template>
</odoo>