summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-09-07 17:12:02 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-09-07 17:12:02 +0700
commit5c5c0bbcb7ad09a8951b8ee2800b73e7a2ab8c8d (patch)
treef303fae4186a35f64f34a49ceaf82fbcc2d5c41e
parent6e1f4a72b2166a418584c9229b04f7a2ab98e41f (diff)
Update clean term condition when empty and generate default on get voucher API
-rw-r--r--indoteknik_api/controllers/api_v1/voucher.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py
index e176803d..a76d57e6 100644
--- a/indoteknik_api/controllers/api_v1/voucher.py
+++ b/indoteknik_api/controllers/api_v1/voucher.py
@@ -1,6 +1,7 @@
from .. import controller
from odoo import http
from odoo.http import request
+from bs4 import BeautifulSoup
class Voucher(controller.Controller):
@@ -56,7 +57,6 @@ class Voucher(controller.Controller):
continue
voucher_info = voucher.apply(order_line)
- voucher_tnc = voucher.terms_conditions or voucher.generate_tnc()
voucher_discount = voucher_info['discount']['all']
valid_order = voucher_info['valid_order']
@@ -66,7 +66,10 @@ class Voucher(controller.Controller):
voucher_res = voucher.format()
voucher_res['can_apply'] = can_apply
voucher_res['discount_voucher'] = voucher_discount
- voucher_res['terms_conditions'] = voucher_tnc
+
+ cleaned_tnc = BeautifulSoup(voucher.terms_conditions, "html.parser").get_text()
+ voucher_res['terms_conditions'] = voucher.terms_conditions if cleaned_tnc else voucher.generate_tnc()
+
results.append(voucher_res)
sorted_results = sorted(results, key=lambda x: x['can_apply'], reverse=True)