Merge branch 'master-website-advance-pricelist' into 'master'

[ADD] Website Sale Advance Pricelist

See merge request flectra-hq/flectra!64
This commit is contained in:
Parthiv Patel 2018-06-12 05:40:29 +00:00
commit d7ad609d55
12 changed files with 834 additions and 0 deletions

View File

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Part of flectra. See LICENSE file for full copyright and licensing details.
from . import controllers
from . import models

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Part of flectra. See LICENSE file for full copyright and licensing details.
{
'name': 'Website Sale Advance Pricelist',
'version': '1.0.0',
'category': 'Sale',
'author': 'FlectraHQ',
'website': 'https://flectrahq.com',
'sequence': 25,
'summary': 'Add Price Rules, Cart Rules and Coupon Rules',
'depends': ['sale_advance_pricelist', 'website_sale'],
'data': [
'views/sale_order_view.xml',
'views/asset.xml',
'data/pricelist_view.xml',
],
'demo': [
'demo/sale_order_demo.xml',
],
'qweb': [
],
'auto_install': False
}

View File

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of flectra. See LICENSE file for full copyright and licensing details.
from . import main

View File

@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
# Part of flectra. See LICENSE file for full copyright and licensing details.
from flectra import http
from flectra.http import request
from flectra.addons.website_sale.controllers.main import WebsiteSale
from flectra.addons.portal.controllers.portal import _build_url_w_params
from flectra.tools.misc import formatLang
class WebsiteSale(WebsiteSale):
@http.route(['/shop/pricelist'], type='http', auth="public", website=True)
def pricelist(self, promo, **post):
redirect = post.get('r', '/shop/cart')
if request.website.pricelist_id.pricelist_type == 'basic':
return super(WebsiteSale, self).pricelist(promo)
else:
sale_order_id = request.session.get('sale_order_id')
sale_order = request.env['sale.order'].sudo().browse(
sale_order_id).exists() if sale_order_id else None
pricelist_id = request.website.pricelist_id
if pricelist_id and not pricelist_id.apply_coupon_code:
return request.redirect("%s?apply_coupon_code=1" % redirect)
coupon_obj = request.env['coupon.code']
coupon_code_id = coupon_obj.sudo().get_coupon_records(
promo, request.website.pricelist_id)
params = {}
if not coupon_code_id:
return request.redirect("%s?coupon_code_id=1" % redirect)
if coupon_code_id.usage_limit > 0 \
and coupon_code_id.remaining_limit <= 0:
return request.redirect("%s?coupon_exceeds_limit=1" % redirect)
min_order_amount = coupon_code_id.min_order_amount
if not sale_order.coupon_code_id and min_order_amount \
and sale_order.amount_untaxed < min_order_amount:
params['min_order_amount'] = \
formatLang(request.env, min_order_amount,
currency_obj=pricelist_id.currency_id)
params['subtotal'] = \
formatLang(request.env, sale_order.amount_untaxed,
currency_obj=pricelist_id.currency_id)
return request.redirect(_build_url_w_params(
"%s?coupon_min_order=1" % redirect, params))
if coupon_code_id.model_id:
partner_id = request.website.user_id.sudo().partner_id
check_coupon = coupon_obj.check_condition(
coupon_code_id, partner_id)
if check_coupon:
return request.redirect("%s?coupon_condition=1" % redirect)
check_coupon = True
for line in sale_order.order_line:
if line.product_uom_qty < \
coupon_code_id.number_of_x_product and not \
line.coupon_code_id and check_coupon:
check_coupon = True
else:
check_coupon = False
break
if check_coupon:
return request.redirect("%s?coupon_condition=1" % redirect)
sale_order.have_coupon_code = promo
sale_order.apply_coupon_code()
return request.redirect(redirect)
@http.route(['/website/discount'], type='http',
auth="public", website=True)
def website_discount(self, access_token=None, revive='', **post):
values = {}
order = request.website.sale_get_order()
data = order._get_discount_vals()
values.update({
'website_sale_order': order,
'data': data[0],
})
return request.render(
"website_sale_advance_pricelist.discount_popover", values,
headers={'Cache-Control': 'no-cache'})

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<flectra noupdate="1">
<!-- Pricelist with First Matched Rule -->
<record id="sale_advance_pricelist.advance_pricelist" model="product.pricelist">
<field name="selectable" eval="True"/>
<field name="website_ids" eval="[(4, ref('website.default_website'))]"/>
</record>
<!-- Pricelist with First Matched Rule and Coupon Code -->
<record id="sale_advance_pricelist.advance_pricelist_with_coupon" model="product.pricelist">
<field name="selectable" eval="True"/>
<field name="website_ids" eval="[(4, ref('website.default_website'))]"/>
</record>
<!-- Pricelist with All Matched Rule -->
<record id="sale_advance_pricelist.advance_pricelist_all" model="product.pricelist">
<field name="selectable" eval="True"/>
<field name="website_ids" eval="[(4, ref('website.default_website'))]"/>
</record>
</flectra>

View File

@ -0,0 +1,387 @@
<?xml version="1.0" encoding="utf-8"?>
<flectra noupdate="1">
<record id="sale_order_ap_website_1" model="sale.order">
<field name="partner_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_invoice_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_shipping_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="user_id" ref="base.user_demo"/>
<field name="pricelist_id" ref="sale_advance_pricelist.advance_pricelist"/>
<field name="team_id" ref="sales_team.salesteam_website_sales"/>
<field name="date_order" eval="(datetime.now()-timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')"/>
</record>
<record id="sale_order_line_1_1_website" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_1"/>
<field name="name">Graphics Card</field>
<field name="product_id" ref="product.product_product_24"/>
<field name="product_uom_qty">5</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">885.0</field>
</record>
<record id="sale_order_line_1_2_website" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_1"/>
<field name="name">Laptop E5023</field>
<field name="product_id" ref="product.product_product_25"/>
<field name="product_uom_qty">3</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">2950.00</field>
</record>
<function model="sale.order" name="_check_cart_rules"
eval="[ref('sale_order_ap_website_1')]"/>
<function model="sale.order" name="action_confirm" eval="[[ref('sale_order_ap_website_1')]]"/>
<!-- Abandoned Carts -->
<!-- Without Coupon Code -->
<record id="sale_order_ap_website_2" model="sale.order">
<field name="partner_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_invoice_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_shipping_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="user_id" ref="base.user_demo"/>
<field name="pricelist_id" ref="sale_advance_pricelist.advance_pricelist"/>
<field name="team_id" ref="sales_team.salesteam_website_sales"/>
<field name="date_order" eval="DateTime.today() - timedelta(days=4)"/>
</record>
<record id="sale_order_line_2_1_website" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_2"/>
<field name="name">Graphics Card</field>
<field name="product_id" ref="product.product_product_24"/>
<field name="product_uom_qty">5</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">885.0</field>
</record>
<record id="sale_order_line_2_2_website" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_2"/>
<field name="name">Laptop E5023</field>
<field name="product_id" ref="product.product_product_25"/>
<field name="product_uom_qty">3</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">2950.00</field>
</record>
<record id="sale_order_line_2_3_website" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_2"/>
<field name="name">Computer Case</field>
<field name="product_id" ref="product.product_product_16"/>
<field name="product_uom_qty">3</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">25</field>
</record>
<function model="sale.order" name="_check_cart_rules"
eval="[ref('sale_order_ap_website_2')]"/>
<!-- Coupon Code Percentage -->
<record id="sale_order_ap_website_3" model="sale.order">
<field name="partner_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_invoice_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_shipping_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="user_id" ref="base.user_demo"/>
<field name="pricelist_id" ref="sale_advance_pricelist.advance_pricelist_with_coupon"/>
<field name="team_id" ref="sales_team.salesteam_website_sales"/>
<field name="date_order" eval="DateTime.today() - timedelta(days=2)"/>
</record>
<record id="website_sale_order_line_ap_3_1" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_3"/>
<field name="name">Graphics Card</field>
<field name="product_id" ref="product.product_product_24"/>
<field name="product_uom_qty">5</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">885.0</field>
</record>
<record id="website_sale_order_line_ap_3_2" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_3"/>
<field name="name">Laptop E5023</field>
<field name="product_id" ref="product.product_product_25"/>
<field name="product_uom_qty">3</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">2950.00</field>
</record>
<function model="sale.order" name="_check_cart_rules"
eval="[ref('sale_order_ap_website_3')]"/>
<record id="website_sale_advance_pricelist.sale_order_ap_website_3" model="sale.order">
<field name="have_coupon_code">Get10Peroff</field>
</record>
<function model="sale.order" name="apply_coupon_code"
eval="[ref('sale_order_ap_website_3')]"/>
<!-- Coupon Code Fixed -->
<record id="sale_order_ap_website_4" model="sale.order">
<field name="partner_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_invoice_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_shipping_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="user_id" ref="base.user_demo"/>
<field name="pricelist_id" ref="sale_advance_pricelist.advance_pricelist_with_coupon"/>
<field name="team_id" ref="sales_team.salesteam_website_sales"/>
<field name="date_order" eval="DateTime.today() - timedelta(days=4)"/>
</record>
<record id="website_sale_order_line_ap_fixed_4_1" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_4"/>
<field name="name">Graphics Card</field>
<field name="product_id" ref="product.product_product_24"/>
<field name="product_uom_qty">5</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">885.0</field>
</record>
<record id="website_sale_order_line_ap_fixed_4_2" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_4"/>
<field name="name">Laptop E5023</field>
<field name="product_id" ref="product.product_product_25"/>
<field name="product_uom_qty">3</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">2950.00</field>
</record>
<function model="sale.order" name="_check_cart_rules"
eval="[ref('sale_order_ap_website_4')]"/>
<record id="website_sale_advance_pricelist.sale_order_ap_website_4" model="sale.order">
<field name="have_coupon_code">Get20off</field>
</record>
<function model="sale.order" name="apply_coupon_code"
eval="[ref('sale_order_ap_website_4')]"/>
<!-- Coupon Code Buy X Product Get Y Product Free -->
<record id="sale_order_ap_website_5" model="sale.order">
<field name="partner_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_invoice_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_shipping_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="user_id" ref="base.user_demo"/>
<field name="pricelist_id" ref="sale_advance_pricelist.advance_pricelist_with_coupon"/>
<field name="team_id" ref="sales_team.salesteam_website_sales"/>
<field name="date_order" eval="DateTime.today() - timedelta(days=4)"/>
</record>
<record id="website_sale_order_line_ap_bxgy_free_5_1" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_5"/>
<field name="name">Graphics Card</field>
<field name="product_id" ref="product.product_product_24"/>
<field name="product_uom_qty">5</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">885.0</field>
</record>
<record id="website_sale_order_line_ap_bxgy_free_5_2" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_5"/>
<field name="name">Laptop E5023</field>
<field name="product_id" ref="product.product_product_25"/>
<field name="product_uom_qty">3</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">2950.00</field>
</record>
<function model="sale.order" name="_check_cart_rules"
eval="[ref('sale_order_ap_website_5')]"/>
<record id="website_sale_advance_pricelist.sale_order_ap_website_5" model="sale.order">
<field name="have_coupon_code">BXGYFree</field>
</record>
<function model="sale.order" name="apply_coupon_code"
eval="[ref('sale_order_ap_website_5')]"/>
<!-- Coupon Code Buy X Product Get Y Other Product Free -->
<record id="sale_order_ap_website_6" model="sale.order">
<field name="partner_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_invoice_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_shipping_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="user_id" ref="base.user_demo"/>
<field name="pricelist_id" ref="sale_advance_pricelist.advance_pricelist_with_coupon"/>
<field name="team_id" ref="sales_team.salesteam_website_sales"/>
<field name="date_order" eval="DateTime.today() - timedelta(days=4)"/>
</record>
<record id="website_sale_order_line_ap_bxgyother_free_6_1" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_6"/>
<field name="name">Graphics Card</field>
<field name="product_id" ref="product.product_product_24"/>
<field name="product_uom_qty">5</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">885.0</field>
</record>
<record id="website_sale_order_line_ap_bxgyother_free_6_2" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_6"/>
<field name="name">Laptop E5023</field>
<field name="product_id" ref="product.product_product_25"/>
<field name="product_uom_qty">3</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">2950.00</field>
</record>
<function model="sale.order" name="_check_cart_rules"
eval="[ref('sale_order_ap_website_6')]"/>
<record id="website_sale_advance_pricelist.sale_order_ap_website_6" model="sale.order">
<field name="have_coupon_code">BXGYOtherFree</field>
</record>
<function model="sale.order" name="apply_coupon_code"
eval="[ref('sale_order_ap_website_6')]"/>
<!-- Coupon Code Buy X Product Get Percentage Free -->
<record id="sale_order_ap_website_7" model="sale.order">
<field name="partner_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_invoice_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_shipping_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="user_id" ref="base.user_demo"/>
<field name="pricelist_id" ref="sale_advance_pricelist.advance_pricelist_with_coupon"/>
<field name="team_id" ref="sales_team.salesteam_website_sales"/>
<field name="date_order" eval="DateTime.today() - timedelta(days=4)"/>
</record>
<record id="website_sale_order_line_ap_bxgpfree_7_1" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_7"/>
<field name="name">Graphics Card</field>
<field name="product_id" ref="product.product_product_24"/>
<field name="product_uom_qty">5</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">885.0</field>
</record>
<record id="website_sale_order_line_ap_bxgpfree_7_2" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_7"/>
<field name="name">Laptop E5023</field>
<field name="product_id" ref="product.product_product_25"/>
<field name="product_uom_qty">2</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">2950.00</field>
</record>
<function model="sale.order" name="_check_cart_rules"
eval="[ref('sale_order_ap_website_7')]"/>
<record id="website_sale_advance_pricelist.sale_order_ap_website_7" model="sale.order">
<field name="have_coupon_code">BXGPercentFree</field>
</record>
<function model="sale.order" name="apply_coupon_code"
eval="[ref('sale_order_ap_website_7')]"/>
<!-- Coupon Code Clubbed Discount -->
<record id="sale_order_ap_website_8" model="sale.order">
<field name="partner_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_invoice_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_shipping_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="user_id" ref="base.user_demo"/>
<field name="pricelist_id" ref="sale_advance_pricelist.advance_pricelist_with_coupon"/>
<field name="team_id" ref="sales_team.salesteam_website_sales"/>
<field name="date_order" eval="DateTime.today() - timedelta(days=4)"/>
</record>
<record id="website_sale_order_line_ap_clubbed_8_1" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_8"/>
<field name="name">Graphics Card</field>
<field name="product_id" ref="product.product_product_24"/>
<field name="product_uom_qty">5</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">885.0</field>
</record>
<record id="website_sale_order_line_ap_clubbed_8_2" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_8"/>
<field name="name">Laptop E5023</field>
<field name="product_id" ref="product.product_product_25"/>
<field name="product_uom_qty">3</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">2950.00</field>
</record>
<function model="sale.order" name="_check_cart_rules"
eval="[ref('sale_order_ap_website_8')]"/>
<record id="website_sale_advance_pricelist.sale_order_ap_website_8" model="sale.order">
<field name="have_coupon_code">CD15Per</field>
</record>
<function model="sale.order" name="apply_coupon_code"
eval="[ref('sale_order_ap_website_8')]"/>
<!-- All Matched Rules -->
<record id="sale_order_ap_website_9" model="sale.order">
<field name="partner_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_invoice_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_shipping_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="user_id" ref="base.user_demo"/>
<field name="pricelist_id" ref="sale_advance_pricelist.advance_pricelist_all"/>
<field name="team_id" ref="sales_team.salesteam_website_sales"/>
<field name="date_order" eval="DateTime.today() - timedelta(days=4)"/>
</record>
<record id="website_sale_order_line_ap_all_9_1" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_9"/>
<field name="name">Graphics Card</field>
<field name="product_id" ref="product.product_product_24"/>
<field name="product_uom_qty">5</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">885.0</field>
</record>
<record id="website_sale_order_line_ap_all_9_2" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_9"/>
<field name="name">Laptop E5023</field>
<field name="product_id" ref="product.product_product_25"/>
<field name="product_uom_qty">3</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">2950.00</field>
</record>
<function model="sale.order" name="_check_cart_rules"
eval="[ref('sale_order_ap_website_9')]"/>
<!-- Payment -->
<record id="sale_order_ap_website_10" model="sale.order">
<field name="partner_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_invoice_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="partner_shipping_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
<field name="user_id" ref="base.user_demo"/>
<field name="team_id" ref="sales_team.salesteam_website_sales"/>
<field name="payment_term_id" ref="account.account_payment_term_immediate"/>
<field name="pricelist_id" ref="sale_advance_pricelist.advance_pricelist_with_coupon"/>
<field name="state">sent</field>
<field name="date_order" eval="(datetime.now()-timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')"/>
</record>
<record id="website_sale_order_line_10_1" model="sale.order.line">
<field name="order_id" ref="sale_order_ap_website_10"/>
<field name="name">Graphics Card</field>
<field name="product_id" ref="product.product_product_24"/>
<field name="product_uom_qty">5</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">885.0</field>
</record>
<record id="website_ap_payment_transaction" model="payment.transaction">
<field name="create_date" eval="datetime.now()"/>
<field name="acquirer_id" ref="payment.payment_acquirer_transfer"/>
<field name="type">form</field>
<field name="sale_order_id" ref="sale_order_ap_website_10"/>
<field name="reference" ref="sale_order_ap_website_10"/>
<field name="state">pending</field>
<field name="amount">4208.18</field>
<field name="currency_id" ref="base.USD"/>
<field name="partner_id" ref="sale_advance_pricelist.res_partner_advance_pricelist"/>
</record>
<function model="sale.order" name="_check_cart_rules"
eval="[ref('sale_order_ap_website_10')]"/>
<record id="website_sale_advance_pricelist.sale_order_ap_website_10" model="sale.order">
<field name="payment_acquirer_id" ref="payment.payment_acquirer_transfer"/>
<field name="payment_tx_id" ref="website_ap_payment_transaction"/>
</record>
</flectra>

View File

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of flectra. See LICENSE file for full copyright and licensing details.
from . import sale

View File

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# Part of flectra. See LICENSE file for full copyright and licensing details.
from flectra import api, models
class SaleOrder(models.Model):
_inherit = "sale.order"
@api.multi
def _cart_update(self, product_id=None, line_id=None, add_qty=0, set_qty=0,
attributes=None, **kwargs):
res = super(SaleOrder, self)._cart_update(product_id, line_id, add_qty,
set_qty, **kwargs)
line = self.env['sale.order.line'].browse(res.get('line_id'))
if res.get('quantity') <= 0 \
or line.order_id.pricelist_id.pricelist_type == 'basic':
return res
if line.order_id.have_coupon_code and \
line.coupon_code_id and not line.check_coupon:
return res
if line.order_id.pricelist_id.discount_policy == 'with_discount':
if not line.check_coupon:
line.discount = 0.0
line.product_id_change()
line.order_id._check_cart_rules()
return res
class Website(models.Model):
_inherit = 'website'
@api.multi
def sale_get_order(self, force_create=False, code=None,
update_pricelist=False, force_pricelist=False):
res = super(Website, self).sale_get_order(
force_create, code, update_pricelist, force_pricelist)
if res.have_coupon_code:
for line in res.order_line:
if line.coupon_code_id and not line.check_coupon:
line.write({'discount': 0.0, 'price_unit': 0.0})
return res

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -0,0 +1,57 @@
flectra.define('website_sale_advance_pricelist.discount', function (require) {
"use strict";
require('web.dom_ready');
var core = require('web.core');
var _t = core._t;
var discount_counter;
function popover_discount($discount) {
$discount.popover({
trigger: 'manual',
html: true,
animation: true,
title: function () {
return _t("Discount Calculation Details");
},
container: 'body',
placement: 'auto',
}).on("mouseenter",function () {
var self = this;
clearTimeout(discount_counter);
$discount.not(self).popover('hide');
discount_counter = setTimeout(function(){
if($(self).is(':hover')){
$.get("/website/discount", {'type': 'popover'})
.then(function (data) {
$(self).data("bs.popover").options.content = data;
$(self).popover("show");
$(".popover").on("mouseleave", function () {
$(self).trigger('mouseleave');
});
});
}
}, 100);
}).on("mouseleave", function () {
var self = this;
setTimeout(function () {
if (!$(".popover:hover").length) {
if(!$(self).is(':hover')) {
$(self).popover('hide');
}
}
}, 100);
});
}
$(function(e){
popover_discount($('a[href$="/website/discount"]'));
$(document).on("change", ".oe_cart input.js_quantity[data-product-id]", function () {
setTimeout(function() {
var $discount = $(document).find('a[href="/website/discount"]');
popover_discount($discount);
},2000);
});
});
});

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<flectra>
<template id="advance_assets_frontend" inherit_id="website.assets_frontend" name="Discount">
<xpath expr="." position="inside">
<script type="text/javascript" src="/website_sale_advance_pricelist/static/src/js/discount.js"></script>
</xpath>
</template>
</flectra>

View File

@ -0,0 +1,203 @@
<?xml version="1.0" encoding="utf-8"?>
<flectra>
<template id="discount_template" inherit_id="website_sale.cart_lines" name="Discount">
<xpath expr="//table/thead/tr/th[hasclass('td-qty')]" position="after">
<th class="text-center td-qty">Discount (%)</th>
</xpath>
<xpath expr="//table/tbody/t/tr/td[hasclass('td-qty')]" position="after">
<td class="text-center td-qty">
<span t-field="line.discount" style="white-space: nowrap;"/>
</td>
</xpath>
</template>
<template id="discount_payment_template" inherit_id="website_sale.payment" name="Discount Payment">
<xpath expr="//th[hasclass('td-qty')]" position="after">
<th class="text-center td-qty">Discount (%)</th>
</xpath>
<xpath expr="//td[hasclass('td-qty')]" position="after">
<td class="text-center td-qty">
<span t-field="line.discount" style="white-space: nowrap;"/>
</td>
</xpath>
</template>
<template id="discount_confirmation_template" inherit_id="website_sale.confirmation" name="Discount Confirmation">
<xpath expr="//th[hasclass('td-price')]" position="after">
<th class="text-center td-qty">Discount (%)</th>
</xpath>
<xpath expr="//td[hasclass('td-price')]" position="after">
<td class="text-center td-qty">
<span t-field="line.discount" style="white-space: nowrap;"/>
</td>
</xpath>
</template>
<template id="discount_popover" name="Discount Popover">
<t t-if="website_sale_order and website_sale_order.discount">
<div>
<table>
<tr>
<td><small><strong>Discount Amount to Words:</strong></small></td>
<td class="text-success" style="text-align:right;">
<small><strong>
<span t-field="website_sale_order.discount"/>
</strong></small>
</td>
</tr>
<tr>
<td class="text-success" colspan="2" style="text-align:center;padding-top:8px;padding-bottom:8px;">
<small><strong>
<t t-esc="data['amount_words']"></t>
</strong></small>
</td>
</tr>
<tr >
<td><small><strong>Gross Amount: </strong></small></td>
<td style="text-align:right;">
<small>
<span t-field="website_sale_order.gross_amount"/>
</small>
</td>
</tr>
<tr>
<td><small><strong>Pricelist (-): </strong></small></td>
<td style="text-align:right;">
<small>
<t t-if="data['position'] == 'before'">
<t t-esc="data['currency']"/>
</t>
<t t-esc="data['price_list_discount']"></t>
<t t-if="data['position'] == 'after'">
<t t-esc="data['currency']"/>
</t>
</small>
</td>
</tr>
<tr>
<td><small><strong>Price Rule (-): </strong></small></td>
<td style="text-align:right;">
<small>
<t t-if="data['position'] == 'before'">
<t t-esc="data['currency']"/>
</t>
<t t-esc="data['price_rule_discount']"></t>
<t t-if="data['position'] == 'after'">
<t t-esc="data['currency']"/>
</t>
</small>
</td>
</tr>
<tr>
<td><small><strong>Cart Rule (-): </strong></small></td>
<td style="text-align:right;">
<small>
<t t-if="data['position'] == 'before'">
<t t-esc="data['currency']"/>
</t>
<t t-esc="data['cart_rule_discount']"></t>
<t t-if="data['position'] == 'after'">
<t t-esc="data['currency']"/>
</t>
</small>
</td>
</tr>
<tr>
<td><small><strong>Coupon Code (-): </strong></small></td>
<td style="text-align:right; padding-bottom:6px;">
<small>
<t t-if="data['position'] == 'before'">
<t t-esc="data['currency']"/>
</t>
<t t-esc="data['coupon_code_discount']"></t>
<t t-if="data['position'] == 'after'">
<t t-esc="data['currency']"/>
</t>
</small>
</td>
</tr>
<tr class="border-black" style="border-top:1px solid #dddddd;">
<td><small><strong>Untaxed Amount: </strong></small></td>
<td style="text-align:right; padding-top:6px;">
<small>
<span t-field="website_sale_order.amount_untaxed"/>
</small>
</td>
</tr>
</table>
</div>
</t>
</template>
<template id="discount_table_template" inherit_id="website_sale.total" name="Discount Table">
<xpath expr="//div[@id='order_total_untaxed']" position="before">
<div class="row" id="order_gross_amount">
<span class="col-xs-6 text-right text-muted">Gross Amount:</span>
<span class="col-xs-6 text-right-not-xs text-left-xs text-muted">
<span t-field="website_sale_order.gross_amount" style="white-space: nowrap;" t-options="{'widget': 'monetary','from_currency': website_sale_order.pricelist_id.currency_id,'display_currency': website.currency_id}" />
</span>
</div>
<div class="row" id="order_total_discount">
<span class="col-xs-6 text-right text-muted">
<t t-if="website_sale_order and website_sale_order.discount">
<a href="/website/discount" onClick="return false;" style="padding-right:2px">
<i class="fa fa-info-circle"></i>
</a></t> Discount:
</span>
<span class="col-xs-6 text-right-not-xs text-left-xs text-muted">
<span t-field="website_sale_order.discount" style="white-space: nowrap;" t-options="{'widget': 'monetary','from_currency': website_sale_order.pricelist_id.currency_id,'display_currency': website.currency_id}" />
</span>
</div>
</xpath>
</template>
<template id="advance_coupon_check_template" inherit_id="website_sale.coupon_form" name="advance_coupon_check">
<xpath expr="//t[@name='code_not_available']" position="after">
<t t-if="request.params.get('apply_coupon_code')" name="apply_coupon_code">
<p class="bg-warning">Coupon code does not apply to sale order pricelist!</p>
</t>
<t t-if="request.params.get('coupon_code_id')" name="coupon_code_id">
<p class="bg-warning">Coupon code not found!</p>
</t>
<t t-if="request.params.get('coupon_exceeds_limit')" name="coupon_exceed_limit">
<p class="bg-warning">Coupon code Remaining Limit exceeds!</p>
</t>
<!-- <p t-esc="request.params.get('min_order_amount')"/> -->
<t t-if="request.params.get('coupon_min_order')" name="coupon_min_order">
<p class="bg-warning">Subtotal (<span t-esc="request.params.get('subtotal')"/>) must be greater than Min Order Amount (<span t-esc="request.params.get('min_order_amount')"/>) which required for the apply coupon code!</p>
</t>
<t t-if="request.params.get('coupon_condition')" name="coupon_condition">
<p class="bg-warning">Coupon code condition criteria not match!</p>
</t>
</xpath>
<xpath expr="//input[@name='promo']" position="replace">
<input name="promo" class="form-control" type="text" placeholder="code..." t-att-value="website_sale_order.have_coupon_code or website_sale_order.pricelist_id.code or None" />
</xpath>
<xpath expr="//div[hasclass('input-group')]" position="after">
<t t-if="website_sale_order.have_coupon_code">
<p class="text-success fa fa-check" style="padding-top: 5px;">Coupon Applied Successfully.</p>
</t>
</xpath>
</template>
<template id="advance_confirmation" inherit_id="website_sale.confirmation" name="advance_confirmation">
<xpath expr="//table/tr" position="before">
<tr>
<td class="col-md-8"></td>
<td class="text-right-not-xs text-left-xs col-sm-2 col-xs-3">Gross Amount:</td>
<td class="text-right col-sm-2 col-xs-3">
<span t-field="order.gross_amount" style="white-space: nowrap;" t-options="{'widget': 'monetary','from_currency': order.pricelist_id.currency_id,'display_currency': website.currency_id}" />
</td>
</tr>
<tr>
<td class='noborder'></td>
<td class="text-right noborder">Discount:</td>
<td class="text-right-not-xs text-left-xs noborder">
<span t-field="order.discount" style="white-space: nowrap;" t-options="{'widget': 'monetary','from_currency': order.pricelist_id.currency_id,'display_currency': website.currency_id}" />
</td>
</tr>
</xpath>
</template>
</flectra>