From db7481a490b87e3a1768112395bf096b93969562 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 7 Jun 2023 13:58:24 +0700 Subject: Add promotion program keyword and api homepage promotion --- indoteknik_api/controllers/api_v1/promotion.py | 66 +++++++++++++++++++++- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/promotion_program.py | 9 ++- .../models/promotion_program_keyword.py | 8 +++ indoteknik_custom/models/promotion_program_line.py | 3 - indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/promotion_program.xml | 10 ++++ .../views/promotion_program_free_item.xml | 1 - .../views/promotion_program_keyword.xml | 44 +++++++++++++++ indoteknik_custom/views/promotion_program_line.xml | 1 - 11 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 indoteknik_custom/models/promotion_program_keyword.py create mode 100644 indoteknik_custom/views/promotion_program_keyword.xml diff --git a/indoteknik_api/controllers/api_v1/promotion.py b/indoteknik_api/controllers/api_v1/promotion.py index b137fe2e..5ee2acb1 100644 --- a/indoteknik_api/controllers/api_v1/promotion.py +++ b/indoteknik_api/controllers/api_v1/promotion.py @@ -1,7 +1,7 @@ from .. import controller from odoo import http from odoo.http import request -import ast +from datetime import datetime class Promotion(controller.Controller): @@ -26,4 +26,66 @@ class Promotion(controller.Controller): } return self.response(data) - \ No newline at end of file + + @http.route(prefix + 'promotion/home', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def v1_get_promotion_home(self): + current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + programs = request.env['promotion.program'].search([ + ('start_time', '<=', current_time), + ('end_time', '>=', current_time), + ]) + if not programs: + return self.response(None) + + data = [] + for program in programs: + data_program = { + 'id': program.id, + 'name': program.name, + 'banner': request.env['ir.attachment'].api_image('promotion.program', 'banner', program.id), + 'icon': request.env['ir.attachment'].api_image('promotion.program', 'icon', program.id) + } + data.append(data_program) + + return self.response(data) + + @http.route(prefix + 'promotion/home/', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def v1_get_promotion_home_detail(self, id): + program_lines = request.env['promotion.program.line'].search([ + ('display_on_homepage', '=', True), + ('promotion_type', '=', 'specific_product'), + ('program_id', '=', int(id)) + ]) + pricelist = self.user_pricelist() + data = [] + for line in program_lines: + product = request.env['product.product'].v2_api_single_response(line.product_id, pricelist=pricelist) + product_template = line.product_id.product_tmpl_id + + product.update({ + 'id': product['parent']['id'], + 'image': product['parent']['image'], + 'name': product['parent']['name'], + 'variant_total': len(product_template.product_variant_ids), + 'lowest_price': product['price'], + 'stock_total': product['stock'], + 'icon': { + 'top': request.env['ir.attachment'].api_image('promotion.program', 'icon_top', line.program_id.id), + 'bottom': request.env['ir.attachment'].api_image('promotion.program', 'icon_bottom', line.program_id.id) + } + }) + price = product['lowest_price']['price'] + if line.discount_type == 'percentage': + product['lowest_price']['discount_percentage'] = line.discount_amount + product['lowest_price']['price_discount'] = price - (price * line.discount_amount / 100) + if line.discount_type == 'fixed_price': + product['lowest_price']['price_discount'] = line.discount_amount + product['lowest_price']['discount_percentage'] = (price - line.discount_amount) / price * 100 + + product.pop('parent', None) + product.pop('price', None) + product.pop('stock', None) + data.append(product) + return self.response(data) \ No newline at end of file diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 6386497b..c116ff0c 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -77,6 +77,7 @@ 'views/promotion_program.xml', 'views/promotion_program_line.xml', 'views/promotion_program_free_item.xml', + 'views/promotion_program_keyword.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 42f011bf..3123d608 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -18,6 +18,7 @@ from . import product_template from . import promotion_program from . import promotion_program_line from . import promotion_program_free_item +from . import promotion_program_keyword from . import purchase_order_line from . import purchase_order from . import purchase_outstanding diff --git a/indoteknik_custom/models/promotion_program.py b/indoteknik_custom/models/promotion_program.py index 7c264b65..bc7f2c49 100644 --- a/indoteknik_custom/models/promotion_program.py +++ b/indoteknik_custom/models/promotion_program.py @@ -6,6 +6,9 @@ class PromotionProgram(models.Model): name = fields.Char(string="Name") banner = fields.Binary(string="Banner") + icon = fields.Binary(string="Icon", help="Image 1:1 ratio") + icon_top = fields.Binary(string="Icon Top", help="Icon ini ditampilkan sebagai atribut pada atas gambar di product card pada website") + icon_bottom = fields.Binary(string="Icon Bottom", help="Icon ini ditampilkan sebagai atribut pada bawah gambar di product card pada website") start_time = fields.Datetime(string="Start Time") end_time = fields.Datetime(string="End Time") applies_to = fields.Selection(selection=[ @@ -14,6 +17,6 @@ class PromotionProgram(models.Model): ]) program_line = fields.One2many( comodel_name="promotion.program.line", inverse_name="program_id", string="Program Line") - - # TODO: Add search many2many tags input untuk ditampilkan ketika ada query search - # TODO: Add ribbon atas, ribbon bawah, image 1:1 \ No newline at end of file + keywords = fields.One2many( + comodel_name="promotion.program.keyword", inverse_name="program_id", string="Keywords" + ) diff --git a/indoteknik_custom/models/promotion_program_keyword.py b/indoteknik_custom/models/promotion_program_keyword.py new file mode 100644 index 00000000..79b938e2 --- /dev/null +++ b/indoteknik_custom/models/promotion_program_keyword.py @@ -0,0 +1,8 @@ +from odoo import fields, models + + +class PromotionProgramKeyword(models.Model): + _name = "promotion.program.keyword" + + name = fields.Char(string="Keyword") + program_id = fields.Many2one(comodel_name="promotion.program") diff --git a/indoteknik_custom/models/promotion_program_line.py b/indoteknik_custom/models/promotion_program_line.py index 3d314f76..a8ee2c43 100644 --- a/indoteknik_custom/models/promotion_program_line.py +++ b/indoteknik_custom/models/promotion_program_line.py @@ -68,6 +68,3 @@ class PromotionProgramLine(models.Model): data = {'product_id': product.id, 'qty': 1, 'line_id': program_line.id} line_free_item.create(data) - - # TODO: Add show on homepage boolean untuk priority specific product - # TODO: Discount loading otomatis membuat line dengan product_id yang sama dengan parent diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 3b35615f..f782046d 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -51,4 +51,5 @@ access_rajaongkir_kurir,access.rajaongkir.kurir,model_rajaongkir_kurir,,1,1,1,1 access_brand_vendor,access.brand.vendor,model_brand_vendor,,1,1,1,1 access_promotion_program,access.promotion.program,model_promotion_program,,1,1,1,1 access_promotion_program_line,access.promotion.program.line,model_promotion_program_line,,1,1,1,1 -access_promotion_program_free_item,access.promotion.program.free_item,model_promotion_program_free_item,,1,1,1,1 \ No newline at end of file +access_promotion_program_free_item,access.promotion.program.free_item,model_promotion_program_free_item,,1,1,1,1 +access_promotion_program_keyword,access.promotion.program.keyword,model_promotion_program_keyword,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/promotion_program.xml b/indoteknik_custom/views/promotion_program.xml index e309cc29..5dff80e6 100644 --- a/indoteknik_custom/views/promotion_program.xml +++ b/indoteknik_custom/views/promotion_program.xml @@ -21,6 +21,7 @@ + @@ -33,6 +34,15 @@ + + + + + + + + + diff --git a/indoteknik_custom/views/promotion_program_free_item.xml b/indoteknik_custom/views/promotion_program_free_item.xml index c17a752d..52d421fe 100644 --- a/indoteknik_custom/views/promotion_program_free_item.xml +++ b/indoteknik_custom/views/promotion_program_free_item.xml @@ -18,7 +18,6 @@ - diff --git a/indoteknik_custom/views/promotion_program_keyword.xml b/indoteknik_custom/views/promotion_program_keyword.xml new file mode 100644 index 00000000..fd279665 --- /dev/null +++ b/indoteknik_custom/views/promotion_program_keyword.xml @@ -0,0 +1,44 @@ + + + Promotion Program Keyword Tree + promotion.program.keyword + + + + + + + + + + Promotion Program Keyword Form + promotion.program.keyword + +
+ + + + + + + + +
+
+
+ + + Promotion Program Keyword + ir.actions.act_window + promotion.program.keyword + tree,form + + + +
\ No newline at end of file diff --git a/indoteknik_custom/views/promotion_program_line.xml b/indoteknik_custom/views/promotion_program_line.xml index 60334d6b..bb625a8f 100644 --- a/indoteknik_custom/views/promotion_program_line.xml +++ b/indoteknik_custom/views/promotion_program_line.xml @@ -23,7 +23,6 @@ - -- cgit v1.2.3