[FIX] website_sale_coupon: Merge the price coupon code and sale coupon code boxes
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
This commit is contained in:
+19
-5
@@ -1,11 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import http
|
||||
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
||||
from odoo.http import request
|
||||
|
||||
class Website_coupon(http.Controller):
|
||||
|
||||
@http.route(['/shop/apply_coupon'], type='json', auth="public", website=True)
|
||||
def shop_apply_coupon(self, promo_code, **post):
|
||||
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_code)
|
||||
return coupon_status
|
||||
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")
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
odoo.define('website_sale_coupon', function (require) {
|
||||
"use strict";
|
||||
|
||||
var ajax = require('web.ajax');
|
||||
var core = require('web.core');
|
||||
var _t = core._t;
|
||||
|
||||
$(document).ready(function () {
|
||||
$('body').on('click', '.check_coupon', function (ev) {
|
||||
var promocode = $("div.coupon_box").find("input[name='promo_code']").val();
|
||||
ajax.jsonRpc('/shop/apply_coupon', 'call', {'promo_code': promocode})
|
||||
.then(function(data) {
|
||||
if (data['error']){
|
||||
if ($("div.coupon_box").parent().find(".nocoupon_alert").length == 0){
|
||||
$("div.coupon_box").append(
|
||||
'<div class="alert alert-danger alert-dismissable nocoupon_alert" style="position: absolute; width: 262px; z-index:9999;">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
data['error']+
|
||||
'</div>');
|
||||
}
|
||||
}
|
||||
if (data['generated_coupon']){
|
||||
if ($("div.coupon_box").parent().find(".nocoupon_alert").length == 0){
|
||||
$("div.coupon_box").append(
|
||||
'<div class="alert alert-success alert-dismissable nocoupon_alert" style="position: absolute; width: 262px; z-index:9999;">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
_.str.sprintf(_t("Your reward <b>%s</b> is available on a next order with this coupon code: %s"), data['generated_coupon']['reward'], data['generated_coupon']['code'])+
|
||||
'</div>');
|
||||
}
|
||||
}
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
@@ -1,16 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<template id="assets_frontend" inherit_id="website.assets_frontend" name="Sale Coupon Assets">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/website_sale_coupon/static/src/js/sale_coupon.js"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="sales_coupon_code_payment" inherit_id="website_sale.cart" active="True">
|
||||
<xpath expr="//div[@id='right_column']" position="inside">
|
||||
<t t-call="website_sale_coupon.sale_coupon_apply"/>
|
||||
</xpath>
|
||||
</template>
|
||||
<template id="website_sale_coupon_cart_hide_qty" inherit_id="website_sale.cart_lines" active="True">
|
||||
<xpath expr="//td[hasclass('td-qty')]/div" position="attributes">
|
||||
<attribute name="t-if">not line.is_reward_line</attribute>
|
||||
@@ -23,34 +13,78 @@
|
||||
</div>
|
||||
</xpath>
|
||||
</template>
|
||||
<template id="sale_coupon_apply">
|
||||
<t t-att-class="hidden" t-if="website_sale_order and website_sale_order.order_line">
|
||||
<div class="coupon_box">
|
||||
<h4>Promo Code</h4>
|
||||
<p>Have a promo code? Fill in this field and apply.</p>
|
||||
<div class="input-group">
|
||||
<input name="promo_code" class='form-control' type="text" placeholder="Promo Code..."/>
|
||||
<div class="input-group-btn">
|
||||
<a class="btn btn-default a-submit check_coupon">Apply</a>
|
||||
</div>
|
||||
</div>
|
||||
<t t-if="website_sale_order and website_sale_order.applied_coupon_ids">
|
||||
<t t-foreach="website_sale_order.applied_coupon_ids" t-as="coupon">
|
||||
<div class="panel panel-success mt16">
|
||||
<div class="panel-heading clearfix">
|
||||
<span class="pull-left">You have successfully applied coupon: <b t-esc="coupon.code"/></span>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
<t t-if="website_sale_order and website_sale_order.promo_code">
|
||||
<template id="sale_coupon_result" inherit_id="website_sale.reduction_code">
|
||||
<xpath expr="//form[@name='coupon_code']" position="after">
|
||||
<t t-if="website_sale_order and website_sale_order.applied_coupon_ids">
|
||||
<t t-foreach="website_sale_order.applied_coupon_ids" t-as="coupon">
|
||||
<div class="panel panel-success mt16">
|
||||
<div class="panel-heading clearfix">
|
||||
<span class="pull-left">You have successfully applied coupon: <b t-esc="website_sale_order.promo_code"/></span>
|
||||
<span class="pull-left">You have successfully applied coupon: <b t-esc="coupon.code"/></span>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
<t t-if="website_sale_order and website_sale_order.promo_code">
|
||||
<div class="panel panel-success mt16">
|
||||
<div class="panel-heading clearfix">
|
||||
<span class="pull-left">You have successfully applied coupon: <b t-esc="website_sale_order.promo_code"/></span>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
<t t-if="website_sale_order and website_sale_order.generated_coupon_ids">
|
||||
<t t-foreach="website_sale_order.generated_coupon_ids" t-as="coupon">
|
||||
<div class="panel panel-success mt16">
|
||||
<div class="panel-heading clearfix">
|
||||
<span class="pull-left">Your reward <b t-esc="coupon.discount_line_product_id.name"/> is available on a next order with this coupon code: <b t-esc="coupon.code"/></span>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
<t t-if="code_not_available">
|
||||
<div class="panel panel-danger mt16">
|
||||
<div class="panel-heading clearfix">
|
||||
<span class="pull-left">Invalid or expired coupon code</span>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</xpath>
|
||||
<xpath expr="//t[@name='code_not_available']" position="replace"/>
|
||||
</template>
|
||||
<template id="sale_coupon_result_payment" inherit_id="website_sale.reduction_code_payment">
|
||||
<xpath expr="//form[@name='coupon_code']" position="after">
|
||||
<t t-if="website_sale_order and website_sale_order.applied_coupon_ids">
|
||||
<t t-foreach="website_sale_order.applied_coupon_ids" t-as="coupon">
|
||||
<div class="panel panel-success mt16">
|
||||
<div class="panel-heading clearfix">
|
||||
<span class="pull-left">You have successfully applied coupon: <b t-esc="coupon.code"/></span>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
<t t-if="website_sale_order and website_sale_order.promo_code">
|
||||
<div class="panel panel-success mt16">
|
||||
<div class="panel-heading clearfix">
|
||||
<span class="pull-left">You have successfully applied coupon: <b t-esc="website_sale_order.promo_code"/></span>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
<t t-if="website_sale_order and website_sale_order.generated_coupon_ids">
|
||||
<t t-foreach="website_sale_order.generated_coupon_ids" t-as="coupon">
|
||||
<div class="panel panel-success mt16">
|
||||
<div class="panel-heading clearfix">
|
||||
<span class="pull-left">Your reward <b t-esc="coupon.discount_line_product_id.name"/> is available on a next order with this coupon code: <b t-esc="coupon.code"/></span>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
<t t-if="code_not_available">
|
||||
<div class="panel panel-danger mt16">
|
||||
<div class="panel-heading clearfix">
|
||||
<span class="pull-left">Invalid or expired coupon code</span>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</xpath>
|
||||
<xpath expr="//t[@name='code_not_available']" position="replace"/>
|
||||
</template>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user