Browse Source

[FIX] Bug Fixed

pull/150/head
Ajmalcybrosys 6 years ago
parent
commit
d6fab71dd5
  1. 7
      website_coupon/__manifest__.py
  2. 69
      website_coupon/controllers/main.py
  3. 7
      website_coupon/doc/RELEASE_NOTES.md
  4. 17
      website_coupon/models/gift_voucher.py
  5. 1
      website_coupon/views/gift_voucher.xml
  6. 85
      website_coupon/views/quantity.xml
  7. 22
      website_coupon/views/templates.xml

7
website_coupon/__manifest__.py

@ -7,7 +7,7 @@
# Author: LINTO C T(<https://www.cybrosys.com>) # Author: LINTO C T(<https://www.cybrosys.com>)
# you can modify it under the terms of the GNU LESSER # you can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. # GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -20,7 +20,7 @@
############################################################################## ##############################################################################
{ {
'name': 'Website Coupon Code', 'name': 'Website Coupon Code',
'version': '12.0.1.0.0', 'version': '12.0.2.0.1',
'summary': 'Manage Website Coupon Codes for Products/Categories/All Products & Its Redeem Operations', 'summary': 'Manage Website Coupon Codes for Products/Categories/All Products & Its Redeem Operations',
'category': 'Website', 'category': 'Website',
'author': 'Cybrosys Techno Solutions', 'author': 'Cybrosys Techno Solutions',
@ -33,10 +33,11 @@
'views/gift_voucher.xml', 'views/gift_voucher.xml',
'views/applied_coupons.xml', 'views/applied_coupons.xml',
'views/templates.xml', 'views/templates.xml',
'views/quantity.xml',
'security/ir.model.access.csv' 'security/ir.model.access.csv'
], ],
'images': ['static/description/banner.jpg'], 'images': ['static/description/banner.jpg'],
'license': 'AGPL-3', 'license': 'LGPL-3',
'installable': True, 'installable': True,
'auto_install': False, 'auto_install': False,
'application': False, 'application': False,

69
website_coupon/controllers/main.py

@ -58,9 +58,11 @@ class WebsiteCoupon(WebsiteSale):
flag = True flag = True
if coupon and coupon.total_avail > 0: if coupon and coupon.total_avail > 0:
applied_coupons = request.env['partner.coupon'].sudo().search([('coupon', '=', promo_voucher), applied_coupons = request.env['partner.coupon'].sudo().search([('coupon', '=', promo_voucher),
('partner_id', '=', curr_user.partner_id.id)], limit=1) (
'partner_id', '=', curr_user.partner_id.id)],
limit=1)
# checking voucher date and limit for each user for this coupon--------------------- # checking voucher date and limit for each user for this coupon---------------------
if coupon.partner_id: if coupon.partner_id:
if curr_user.partner_id.id != coupon.partner_id.id: if curr_user.partner_id.id != coupon.partner_id.id:
flag = False flag = False
@ -99,7 +101,7 @@ class WebsiteCoupon(WebsiteSale):
categ_id = coupon.voucher.product_id categ_id = coupon.voucher.product_id
for line in order.order_line: for line in order.order_line:
if line.product_id.name == categ_id.name: if line.product_id.name == categ_id.name:
flag_product = True flag_product = True
elif voucher_type == 'category': elif voucher_type == 'category':
# the voucher type is category ---------------------------- # the voucher type is category ----------------------------
product_id = coupon.voucher.product_categ product_id = coupon.voucher.product_categ
@ -131,19 +133,14 @@ class WebsiteCoupon(WebsiteSale):
if line.product_id.categ_id.name == product_id.name: if line.product_id.categ_id.name == product_id.name:
amount_final += (voucher_val / 100) * line.price_total amount_final += (voucher_val / 100) * line.price_total
elif voucher_type == 'all': elif voucher_type == 'all':
amount_final = (voucher_val/100) * order.amount_total amount_final = (voucher_val / 100) * order.amount_total
coupon_product.product_tmpl_id.write({'list_price': -amount_final}) coupon_product.product_tmpl_id.write({'list_price': -amount_final})
order._cart_update(product_id=coupon_product.id, set_qty=1, add_qty=1) order._cart_update(product_id=coupon_product.id, set_qty=1, add_qty=1)
order = request.website.sale_get_order()
order.update({'coupon_id': promo_voucher})
# updating coupon balance-------------- # updating coupon balance--------------
total = coupon.total_avail - 1
coupon.write({'total_avail': total})
# creating a record for this partner, i.e he is used this coupon once----------- # creating a record for this partner, i.e he is used this coupon once-----------
if not applied_coupons:
curr_user.partner_id.write({'applied_coupon': [(0, 0, {'partner_id': curr_user.partner_id.id,
'coupon': coupon.code,
'number': 1})]})
else:
applied_coupons.write({'number': applied_coupons.number + 1})
else: else:
return request.redirect("/shop/cart?coupon_not_available=1") return request.redirect("/shop/cart?coupon_not_available=1")
else: else:
@ -153,3 +150,51 @@ class WebsiteCoupon(WebsiteSale):
return request.redirect("/shop/cart?coupon_not_available=1") return request.redirect("/shop/cart?coupon_not_available=1")
return request.redirect("/shop/cart") return request.redirect("/shop/cart")
@http.route(['/shop/payment'], type='http', auth="public", website=True, sitemap=False)
def payment(self, **post):
""" Payment step. This page proposes several payment means based on available
payment.acquirer. State at this point :
- a draft sales order with lines; otherwise, clean context / session and
back to the shop
- no transaction in context / session, or only a draft one, if the customer
did go to a payment.acquirer website but closed the tab without
paying / canceling
"""
order = request.website.sale_get_order()
curr_user = request.env.user
sales_order = request.env['sale.order.line'].sudo().search([('order_id', '=', order.id)])
applied_coupons = request.env['partner.coupon'].sudo().search([('coupon', '=', order.coupon_id),
('partner_id', '=', curr_user.partner_id.id)],
limit=1)
coupon = request.env['gift.coupon'].sudo().search([('code', '=', order.coupon_id)], limit=1)
products = []
for data in sales_order:
products.append(data.name)
if 'Gift Coupon' in products:
print("gigt coupon in products")
total = coupon.total_avail - 1
coupon.write({'total_avail': total})
if not applied_coupons:
curr_user.partner_id.write(
{'applied_coupon': [(0, 0, {'partner_id': curr_user.partner_id.id,
'coupon': coupon.code,
'number': 1})]})
else:
applied_coupons.write({'number': applied_coupons.number + 1})
redirection = self.checkout_redirection(order)
if redirection:
return redirection
render_values = self._get_shop_payment_values(order, **post)
render_values['only_services'] = order and order.only_services or False
if render_values['errors']:
render_values.pop('acquirers', '')
render_values.pop('tokens', '')
return request.render("website_sale.payment", render_values)

7
website_coupon/doc/RELEASE_NOTES.md

@ -3,4 +3,11 @@
#### 02.04.2019 #### 02.04.2019
#### Version 12.0.1.0.0 #### Version 12.0.1.0.0
Initial Commit for Website Coupon. Initial Commit for Website Coupon.
#### 02.04.2019
#### Version 12.0.2.0.1
#### FIX
Bug Fixed

17
website_coupon/models/gift_voucher.py

@ -20,7 +20,7 @@
import string import string
import random import random
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from datetime import datetime,date from datetime import datetime, date
from odoo.exceptions import UserError from odoo.exceptions import UserError
@ -66,13 +66,20 @@ class GiftCoupon(models.Model):
type = fields.Selection([ type = fields.Selection([
('fixed', 'Fixed Amount'), ('fixed', 'Fixed Amount'),
('percentage', 'Percentage'), ('percentage', 'Percentage'),
], store=True, default='fixed') ], store=True, default='fixed')
count = fields.Char(string="count")
@api.onchange('voucher_val') @api.onchange('voucher_val')
def check_val(self): def check_val(self):
if self.voucher_val > self.voucher.max_value or self.voucher_val < self.voucher.min_value: if self.voucher_val > self.voucher.max_value or self.voucher_val < self.voucher.min_value:
raise UserError(_("Please check the voucher value")) raise UserError(_("Please check the voucher value"))
@api.model
def create(self, vals):
res = super(GiftCoupon, self).create(vals)
vals['count'] = vals['total_avail']
return res
class CouponPartner(models.Model): class CouponPartner(models.Model):
_name = 'partner.coupon' _name = 'partner.coupon'
@ -86,3 +93,9 @@ class PartnerExtended(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
applied_coupon = fields.One2many('partner.coupon', 'partner_id', string="Coupons Applied") applied_coupon = fields.One2many('partner.coupon', 'partner_id', string="Coupons Applied")
class SaleCoupon(models.Model):
_inherit = 'sale.order'
coupon_id = fields.Char(string='coupon')

1
website_coupon/views/gift_voucher.xml

@ -64,6 +64,7 @@
<group string="Conditions"> <group string="Conditions">
<group> <group>
<field name="total_avail" /> <field name="total_avail" />
<field name="count" invisible="1"/>
</group> </group>
<group> <group>
<field name="partner_id" /> <field name="partner_id" />

85
website_coupon/views/quantity.xml

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="website_sale.cart_lines" name="Shopping Cart Lines">
<div t-if="not website_sale_order or not website_sale_order.website_order_line" class="js_cart_lines alert alert-info">
Your cart is empty!
</div>
<table class="mb16 table table-striped table-sm js_cart_lines" id="cart_products" t-if="website_sale_order and website_sale_order.website_order_line">
<thead>
<tr>
<th class="td-img">Product</th>
<th></th>
<th class="text-center td-qty">Quantity</th>
<th class="text-center td-price">Price</th>
<th class="text-center td-action"></th>
</tr>
</thead>
<tbody>
<t t-foreach="website_sale_order.website_order_line" t-as="line">
<tr t-att-class="'optional_product info' if line.linked_line_id else None">
<td colspan="2" t-if="not line.product_id.product_tmpl_id" class='td-img'></td>
<td align="center" t-if="line.product_id.product_tmpl_id" class='td-img'>
<span t-field="line.product_id.image_small" t-options="{'widget': 'image', 'class': 'rounded'}" />
</td>
<td t-if="line.product_id.product_tmpl_id" class='td-product_name'>
<div>
<t t-call="website_sale.cart_line_product_link">
<strong t-field="line.name_short" />
</t>
</div>
<t t-call="website_sale.cart_line_description_following_lines">
<t t-set="div_class" t-value="'d-none d-md-block'"/>
</t>
</td>
<td class="text-center td-qty">
<div t-if="not line.linked_line_id" class="css_quantity input-group mx-auto oe_website_spinner">
<t t-if="line.name != 'Gift Coupon'">
<div class="input-group-prepend">
<a t-attf-href="#" class="btn btn-link js_add_cart_json d-none d-md-inline-block" aria-label="Remove one" title="Remove one">
<i class="fa fa-minus"/>
</a>
</div>
</t>
<t t-if="line.name != 'Gift Coupon'">
<input type="text" class="js_quantity form-control quantity" t-att-data-line-id="line.id" t-att-data-product-id="line.product_id.id" t-att-value="int(line.product_uom_qty) == line.product_uom_qty and int(line.product_uom_qty) or line.product_uom_qty" />
</t>
<t t-if="line.name == 'Gift Coupon'">
<input type="text" class="js_quantity form-control quantity" t-att-data-line-id="line.id" t-att-data-product-id="line.product_id.id" t-att-value="int(line.product_uom_qty) == line.product_uom_qty and int(line.product_uom_qty) or line.product_uom_qty" readonly="1"/>
</t>
<t t-if="line.name != 'Gift Coupon'">
<div class="input-group-append">
<a t-attf-href="#" class="btn btn-link float_left js_add_cart_json d-none d-md-inline-block" aria-label="Add one" title="Add one">
<i class="fa fa-plus"/>
</a>
</div>
</t>
</div>
<t t-if="line.linked_line_id">
<span class="js_quantity text-muted" t-att-data-line-id="line.id" t-att-data-product-id="line.product_id.id" t-esc="int(line.product_uom_qty)"/>
</t>
</td>
<td class="text-center td-price" name="price">
<t t-set="combination" t-value="line.product_id.product_template_attribute_value_ids + line.product_no_variant_attribute_value_ids"/>
<t t-set="combination_info" t-value="line.product_id.product_tmpl_id._get_combination_info(combination)"/>
<t t-set="list_price_converted" t-value="website.currency_id._convert(combination_info['list_price'], website_sale_order.currency_id, website_sale_order.company_id, date)"/>
<t groups="account.group_show_line_subtotals_tax_excluded" t-if="(website_sale_order.pricelist_id.discount_policy == 'without_discount' and website_sale_order.currency_id.compare_amounts(list_price_converted, line.price_reduce_taxexcl) == 1) or website_sale_order.currency_id.compare_amounts(line.price_unit, line.price_reduce) == 1" name="order_line_discount">
<del t-attf-class="#{'text-danger mr8'}" style="white-space: nowrap;" t-esc="list_price_converted" t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}" />
</t>
<span t-field="line.price_reduce_taxexcl" style="white-space: nowrap;" t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}" groups="account.group_show_line_subtotals_tax_excluded" />
<t groups="account.group_show_line_subtotals_tax_included" t-if="(website_sale_order.pricelist_id.discount_policy == 'without_discount' and website_sale_order.currency_id.compare_amounts(list_price_converted, line.price_reduce_taxinc) == 1) or website_sale_order.currency_id.compare_amounts(line.price_unit, line.price_reduce) == 1" name="order_line_discount">
<del t-attf-class="#{'text-danger mr8'}" style="white-space: nowrap;" t-esc="list_price_converted" t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}" />
</t>
<span t-field="line.price_reduce_taxinc" style="white-space: nowrap;" t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}" groups="account.group_show_line_subtotals_tax_included" />
</td>
<td class="td-action">
<a href='#' aria-label="Remove from cart" title="Remove from cart" class='js_delete_product no-decoration'> <small><i class='fa fa-trash-o'></i></small></a>
</td>
</tr>
</t>
</tbody>
</table>
</template>
</odoo>

22
website_coupon/views/templates.xml

@ -7,8 +7,8 @@
position="inside"> position="inside">
<h4>Voucher Code</h4> <h4>Voucher Code</h4>
<p> <p>
Have a voucher code? Fill this field and apply . Have a voucher code? Fill this field and apply .
</p> </p>
<t t-if="coupon_not_available"> <t t-if="coupon_not_available">
<t t-if="coupon_not_available == '1'"> <t t-if="coupon_not_available == '1'">
@ -25,14 +25,14 @@
action="/shop/gift_coupon" method="post" action="/shop/gift_coupon" method="post"
class="mb32"> class="mb32">
<input type="hidden" name="csrf_token" <input type="hidden" name="csrf_token"
t-att-value="request.csrf_token()" /> t-att-value="request.csrf_token()"/>
<div class="input-group"> <div class="input-group">
<input name="promo_voucher" class="form-control" <input name="promo_voucher" id="code" class="form-control"
type="text" placeholder="code..." type="text" placeholder="code..."
t-att-value="website_sale_order.pricelist_id.code or None" /> />
<div class="input-group-append"> <div class="input-group-append">
<a href="#" role="button" class="btn btn-secondary a-submit">Apply</a> <a href="#" role="button" class="btn btn-secondary a-submit">Apply</a>
</div> </div>
</div> </div>
</form> </form>
</xpath> </xpath>
@ -48,5 +48,11 @@
<xpath expr="//table[@id='cart_products']/thead/tr/th[4]" position="attributes"> <xpath expr="//table[@id='cart_products']/thead/tr/th[4]" position="attributes">
<attribute name="width">100</attribute> <attribute name="width">100</attribute>
</xpath> </xpath>
</template>
<template id="contact" inherit_id="sale.product_configurator_configure">
<xpath expr="//div[@class='input-group-append']" readonly="1"/>
</template> </template>
</odoo> </odoo>
Loading…
Cancel
Save