From d6fab71dd56a02564acbb6c987602983e5bc075f Mon Sep 17 00:00:00 2001 From: Ajmalcybrosys Date: Fri, 29 Nov 2019 17:30:46 +0530 Subject: [PATCH] [FIX] Bug Fixed --- website_coupon/__manifest__.py | 7 ++- website_coupon/controllers/main.py | 69 ++++++++++++++++++---- website_coupon/doc/RELEASE_NOTES.md | 7 +++ website_coupon/models/gift_voucher.py | 17 +++++- website_coupon/views/gift_voucher.xml | 1 + website_coupon/views/quantity.xml | 85 +++++++++++++++++++++++++++ website_coupon/views/templates.xml | 22 ++++--- 7 files changed, 183 insertions(+), 25 deletions(-) create mode 100644 website_coupon/views/quantity.xml diff --git a/website_coupon/__manifest__.py b/website_coupon/__manifest__.py index 3fd01c2d1..2328f8e8a 100644 --- a/website_coupon/__manifest__.py +++ b/website_coupon/__manifest__.py @@ -7,7 +7,7 @@ # Author: LINTO C T() # you can modify it under the terms of the GNU LESSER # GENERAL PUBLIC LICENSE (LGPL v3), Version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -20,7 +20,7 @@ ############################################################################## { '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', 'category': 'Website', 'author': 'Cybrosys Techno Solutions', @@ -33,10 +33,11 @@ 'views/gift_voucher.xml', 'views/applied_coupons.xml', 'views/templates.xml', + 'views/quantity.xml', 'security/ir.model.access.csv' ], 'images': ['static/description/banner.jpg'], - 'license': 'AGPL-3', + 'license': 'LGPL-3', 'installable': True, 'auto_install': False, 'application': False, diff --git a/website_coupon/controllers/main.py b/website_coupon/controllers/main.py index d165db804..aa583c29f 100644 --- a/website_coupon/controllers/main.py +++ b/website_coupon/controllers/main.py @@ -58,9 +58,11 @@ class WebsiteCoupon(WebsiteSale): flag = True if coupon and coupon.total_avail > 0: 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 curr_user.partner_id.id != coupon.partner_id.id: flag = False @@ -99,7 +101,7 @@ class WebsiteCoupon(WebsiteSale): categ_id = coupon.voucher.product_id for line in order.order_line: if line.product_id.name == categ_id.name: - flag_product = True + flag_product = True elif voucher_type == 'category': # the voucher type is category ---------------------------- product_id = coupon.voucher.product_categ @@ -131,19 +133,14 @@ class WebsiteCoupon(WebsiteSale): if line.product_id.categ_id.name == product_id.name: amount_final += (voucher_val / 100) * line.price_total 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}) 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-------------- - total = coupon.total_avail - 1 - coupon.write({'total_avail': total}) # 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: return request.redirect("/shop/cart?coupon_not_available=1") else: @@ -153,3 +150,51 @@ class WebsiteCoupon(WebsiteSale): return request.redirect("/shop/cart?coupon_not_available=1") 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) diff --git a/website_coupon/doc/RELEASE_NOTES.md b/website_coupon/doc/RELEASE_NOTES.md index 18e708d94..1e1554074 100644 --- a/website_coupon/doc/RELEASE_NOTES.md +++ b/website_coupon/doc/RELEASE_NOTES.md @@ -3,4 +3,11 @@ #### 02.04.2019 #### Version 12.0.1.0.0 + Initial Commit for Website Coupon. + +#### 02.04.2019 +#### Version 12.0.2.0.1 +#### FIX + +Bug Fixed diff --git a/website_coupon/models/gift_voucher.py b/website_coupon/models/gift_voucher.py index b082d405b..f423189bf 100644 --- a/website_coupon/models/gift_voucher.py +++ b/website_coupon/models/gift_voucher.py @@ -20,7 +20,7 @@ import string import random from odoo import models, fields, api, _ -from datetime import datetime,date +from datetime import datetime, date from odoo.exceptions import UserError @@ -66,13 +66,20 @@ class GiftCoupon(models.Model): type = fields.Selection([ ('fixed', 'Fixed Amount'), ('percentage', 'Percentage'), - ], store=True, default='fixed') + ], store=True, default='fixed') + count = fields.Char(string="count") @api.onchange('voucher_val') def check_val(self): if self.voucher_val > self.voucher.max_value or self.voucher_val < self.voucher.min_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): _name = 'partner.coupon' @@ -86,3 +93,9 @@ class PartnerExtended(models.Model): _inherit = 'res.partner' applied_coupon = fields.One2many('partner.coupon', 'partner_id', string="Coupons Applied") + + +class SaleCoupon(models.Model): + _inherit = 'sale.order' + + coupon_id = fields.Char(string='coupon') diff --git a/website_coupon/views/gift_voucher.xml b/website_coupon/views/gift_voucher.xml index bcc4c245c..7f31848e5 100644 --- a/website_coupon/views/gift_voucher.xml +++ b/website_coupon/views/gift_voucher.xml @@ -64,6 +64,7 @@ + diff --git a/website_coupon/views/quantity.xml b/website_coupon/views/quantity.xml new file mode 100644 index 000000000..1ab28a96d --- /dev/null +++ b/website_coupon/views/quantity.xml @@ -0,0 +1,85 @@ + + + + + \ No newline at end of file diff --git a/website_coupon/views/templates.xml b/website_coupon/views/templates.xml index 7e96616a7..4dc060dfc 100644 --- a/website_coupon/views/templates.xml +++ b/website_coupon/views/templates.xml @@ -7,8 +7,8 @@ position="inside">

Voucher Code

- Have a voucher code? Fill this field and apply . -

+ Have a voucher code? Fill this field and apply . +

@@ -25,14 +25,14 @@ action="/shop/gift_coupon" method="post" class="mb32"> + t-att-value="request.csrf_token()"/>
- -
- Apply -
+ /> +
+ Apply +
@@ -48,5 +48,11 @@ 100 + + + + + \ No newline at end of file