On the ecommerce, we may activate an option that allows a user to enter a coupon code related to a pricelist.
On the website_sale_coupon module, we are also able to enter a code to activate a reward related to a program.
Theses 2 boxes may appear on the same page.
This commit merges the 2 boxes into a single one. When a coupon is entered, it will
- Check if a coupon program or a promotion program is linked to this code
- If yes, it applied the reward accordingly
- If not, it will check if a pricelist is linked to this coupon code
- If yes, it will modify the prices accordingly
- If not, it will display a warning to explain that the code is invalid
26 lines
1.1 KiB
Python
26 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import http
|
|
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
|
from odoo.http import request
|
|
|
|
|
|
class WebsiteSale(WebsiteSale):
|
|
|
|
@http.route(['/shop/pricelist'])
|
|
def pricelist(self, promo, **post):
|
|
order = request.website.sale_get_order()
|
|
coupon_status = request.env['sale.coupon.apply.code'].sudo().apply_coupon(order, promo)
|
|
print coupon_status.get('error', False)
|
|
if coupon_status.get('error', False):
|
|
return super(WebsiteSale, self).pricelist(promo, **post)
|
|
return request.redirect("/shop/cart")
|
|
|
|
@http.route(['/shop/pricelist_payment'], type='http', auth="public", website=True)
|
|
def pricelist_payment(self, promo, **post):
|
|
order = request.website.sale_get_order()
|
|
coupon_status = request.env['sale.coupon.apply.code'].sudo().apply_coupon(order, promo)
|
|
print coupon_status.get('error', False)
|
|
if coupon_status.get('error', False):
|
|
return super(WebsiteSale, self).pricelist(promo, **post)
|
|
return request.redirect("/shop/payment")
|