diff --git a/website_coupon/controllers/main.py b/website_coupon/controllers/main.py index 72bf1b616..f01032689 100644 --- a/website_coupon/controllers/main.py +++ b/website_coupon/controllers/main.py @@ -113,8 +113,19 @@ class WebsiteCoupon(http.Controller): return request.redirect("/shop/cart?coupon_not_available=3") elif type == 'percentage': # coupon type is percentage ------------------------------------- - amount_final = (voucher_val/100) * order.amount_total - res = coupon_product.product_tmpl_id.write({'list_price': -amount_final}) + if voucher_type == 'product': + for line in order.order_line: + if line.product_id.name == categ_id.name: + amount_final = (voucher_val / 100) * line.price_total + break + elif voucher_type == 'category': + amount_final = 0 + for line in order.order_line: + 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 + res = coupon_product.product_tmpl_id.write({'list_price': -amount_final}) value = order._cart_update(product_id=coupon_product.id, set_qty=1, add_qty=1) # updating coupon balance--------------