From 5cf60908a43f8c74281111438415581f997efa96 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Feb 2024 09:39:38 +0700 Subject: Add get all voucher api --- indoteknik_api/controllers/api_v1/voucher.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index 3c056ecd..1888fe29 100644 --- a/indoteknik_api/controllers/api_v1/voucher.py +++ b/indoteknik_api/controllers/api_v1/voucher.py @@ -1,31 +1,39 @@ -from .. import controller +from bs4 import BeautifulSoup from odoo import http from odoo.http import request -from bs4 import BeautifulSoup + +from .. import controller class Voucher(controller.Controller): - prefix = '/api/v1/' + PREFIX_API = '/api/v1/' + + @http.route(PREFIX_API + 'voucher', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def get_vouchers(self, **kw): + vouchers = request.env['voucher'].get_active_voucher([('visibility', 'in', ['public'])]) + vouchers = vouchers.res_format() + return self.response(vouchers) - @http.route(prefix + 'user//voucher', auth='public', methods=['GET', 'OPTIONS']) + @http.route(PREFIX_API + 'user//voucher', auth='public', methods=['GET', 'OPTIONS']) @controller.Controller.must_authorized(private=True, private_key='user_id') - def get_vouchers(self, **kw): + def get_vouchers_by_user_id(self, **kw): cart = request.env['website.user.cart'] code = kw.get('code') user_id = int(kw.get('user_id', 0)) source = kw.get('source') visibility = ['public'] - parameter = [] + domain = [] if code: visibility.append('private') - parameter += [('code', '=', code)] + domain += [('code', '=', code)] user_pricelist = request.env.context.get('user_pricelist') if user_pricelist: - parameter += [('excl_pricelist_ids', 'not in', [user_pricelist.id])] + domain += [('excl_pricelist_ids', 'not in', [user_pricelist.id])] - parameter += [('visibility', 'in', visibility)] - vouchers = request.env['voucher'].get_active_voucher(parameter) + domain += [('visibility', 'in', visibility)] + vouchers = request.env['voucher'].get_active_voucher(domain) checkout = cart.get_user_checkout(user_id, source=source) products = checkout['products'] -- cgit v1.2.3 From 03ba190bca443625075ddbd637d895bfc1a27fcd Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Feb 2024 09:55:41 +0700 Subject: Add active field on promotion program line --- indoteknik_custom/models/promotion/promotion_program_line.py | 1 + 1 file changed, 1 insertion(+) diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py index 18a7e184..43daf93b 100644 --- a/indoteknik_custom/models/promotion/promotion_program_line.py +++ b/indoteknik_custom/models/promotion/promotion_program_line.py @@ -30,6 +30,7 @@ class PromotionProgramLine(models.Model): discount_amount = fields.Float('Discount Amount') order_promotion_ids = fields.One2many('sale.order.promotion', 'program_line_id', 'Promotions') + active = fields.Boolean(default=True) def get_active_promotions(self, product_id): current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') -- cgit v1.2.3 From 3861a02e3080d75b507ad9a763fa7f635b463ec8 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Feb 2024 11:43:08 +0700 Subject: Add description on apache solr queue --- indoteknik_custom/models/solr/apache_solr_queue.py | 4 +++- indoteknik_custom/views/apache_solr_queue.xml | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/solr/apache_solr_queue.py b/indoteknik_custom/models/solr/apache_solr_queue.py index 07274295..f8c57919 100644 --- a/indoteknik_custom/models/solr/apache_solr_queue.py +++ b/indoteknik_custom/models/solr/apache_solr_queue.py @@ -18,6 +18,7 @@ class ApacheSolrQueue(models.Model): ('not_found', 'Record not found') ], 'Execute Status') execute_date = fields.Datetime('Execute Date') + description = fields.Text('Description') def _compute_display_name(self): for rec in self: @@ -57,7 +58,8 @@ class ApacheSolrQueue(models.Model): rec.execute_status = 'success' else: rec.execute_status = 'not_found' - except: + except Exception as e: + rec.description = e rec.execute_status = 'failed' rec.execute_date = datetime.utcnow() self.env.cr.commit() diff --git a/indoteknik_custom/views/apache_solr_queue.xml b/indoteknik_custom/views/apache_solr_queue.xml index 13869b4c..8de9eb46 100644 --- a/indoteknik_custom/views/apache_solr_queue.xml +++ b/indoteknik_custom/views/apache_solr_queue.xml @@ -4,6 +4,7 @@ apache.solr.queue + -- cgit v1.2.3 From 078ee431a58dfdfd554d3c9b91c67271f5bcce5c Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Feb 2024 13:32:38 +0700 Subject: Delete image on promotion program line --- indoteknik_custom/models/solr/promotion_program_line.py | 1 - 1 file changed, 1 deletion(-) diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py index 6e182324..cd692ed3 100644 --- a/indoteknik_custom/models/solr/promotion_program_line.py +++ b/indoteknik_custom/models/solr/promotion_program_line.py @@ -41,7 +41,6 @@ class PromotionProgramLine(models.Model): 'id': rec.id, 'program_id_i': rec.program_id.id, 'name_s': rec.name, - 'image_s': self.env['ir.attachment'].api_image(self._name, 'image', rec.id) if rec.image else '', 'type_value_s': promotion_type['value'], 'type_label_s': promotion_type['label'], 'package_limit_i': rec.package_limit, -- cgit v1.2.3 From aa9f502540c7a88643abb49bdca8f3d81257d4ec Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Feb 2024 13:34:08 +0700 Subject: Update program line's program_id to 0 when no parent --- indoteknik_custom/models/solr/promotion_program_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py index cd692ed3..edee259f 100644 --- a/indoteknik_custom/models/solr/promotion_program_line.py +++ b/indoteknik_custom/models/solr/promotion_program_line.py @@ -39,7 +39,7 @@ class PromotionProgramLine(models.Model): document.update({ 'id': rec.id, - 'program_id_i': rec.program_id.id, + 'program_id_i': rec.program_id.id or 0, 'name_s': rec.name, 'type_value_s': promotion_type['value'], 'type_label_s': promotion_type['label'], -- cgit v1.2.3 From ad0759513cc296e4a41196b2dccac35885d834e3 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Feb 2024 13:45:52 +0700 Subject: Fix get remaining time on promotion program line --- indoteknik_custom/models/promotion/promotion_program_line.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py index 43daf93b..9fab6e58 100644 --- a/indoteknik_custom/models/promotion/promotion_program_line.py +++ b/indoteknik_custom/models/promotion/promotion_program_line.py @@ -75,6 +75,9 @@ class PromotionProgramLine(models.Model): } def _get_remaining_time(self): + if not self.program_id.end_time: + return 0 + calculate_time = self.program_id.end_time - datetime.now() return round(calculate_time.total_seconds()) -- cgit v1.2.3 From 0f3132ffb296dd64015581ba7bbf13f1f6761d7c Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Feb 2024 14:52:22 +0700 Subject: Add promotion product view --- indoteknik_custom/__manifest__.py | 1 + .../views/promotion/promotion_product.xml | 45 ++++++++++++++++++++++ .../views/promotion/promotion_program_line.xml | 1 + 3 files changed, 47 insertions(+) create mode 100644 indoteknik_custom/views/promotion/promotion_product.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 9c505916..6d1ca7b0 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -77,6 +77,7 @@ 'views/brand_vendor.xml', 'views/promotion/promotion_program.xml', 'views/promotion/promotion_program_line.xml', + 'views/promotion/promotion_product.xml', 'views/requisition.xml', 'views/landedcost.xml', 'views/product_sla.xml', diff --git a/indoteknik_custom/views/promotion/promotion_product.xml b/indoteknik_custom/views/promotion/promotion_product.xml new file mode 100644 index 00000000..eac42a45 --- /dev/null +++ b/indoteknik_custom/views/promotion/promotion_product.xml @@ -0,0 +1,45 @@ + + + Promotion Product Tree + promotion.product + + + + + + + + + + Promotion Product Form + promotion.product + +
+ + + + + + + + + +
+
+
+ + + Promotion Product + ir.actions.act_window + promotion.product + tree,form + + + +
\ No newline at end of file diff --git a/indoteknik_custom/views/promotion/promotion_program_line.xml b/indoteknik_custom/views/promotion/promotion_program_line.xml index 346a08c9..280bdfba 100644 --- a/indoteknik_custom/views/promotion/promotion_program_line.xml +++ b/indoteknik_custom/views/promotion/promotion_program_line.xml @@ -21,6 +21,7 @@ + -- cgit v1.2.3 From fd275ea8c25246e349ae3e177ac6d0acdda249c6 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Sat, 17 Feb 2024 11:13:09 +0700 Subject: Add open target record on apache solr queue --- indoteknik_custom/models/solr/apache_solr_queue.py | 10 ++++++++++ indoteknik_custom/views/apache_solr_queue.xml | 1 + 2 files changed, 11 insertions(+) diff --git a/indoteknik_custom/models/solr/apache_solr_queue.py b/indoteknik_custom/models/solr/apache_solr_queue.py index f8c57919..02ad5bb8 100644 --- a/indoteknik_custom/models/solr/apache_solr_queue.py +++ b/indoteknik_custom/models/solr/apache_solr_queue.py @@ -39,6 +39,16 @@ class ApacheSolrQueue(models.Model): if elapsed_time > max_exec_time: break rec.execute_queue() + + def open_target_record(self): + return { + 'name': '', + 'view_mode': 'form', + 'res_model': self.res_model, + 'target': 'current', + 'type': 'ir.actions.act_window', + 'res_id': self.res_id + } def execute_queue(self): for rec in self: diff --git a/indoteknik_custom/views/apache_solr_queue.xml b/indoteknik_custom/views/apache_solr_queue.xml index 8de9eb46..7577e569 100644 --- a/indoteknik_custom/views/apache_solr_queue.xml +++ b/indoteknik_custom/views/apache_solr_queue.xml @@ -4,6 +4,7 @@ apache.solr.queue +