diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-07-26 13:48:31 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-07-26 13:48:31 +0700 |
| commit | e394d734ca4e53bd63b767c9c7fe77a5ebe49245 (patch) | |
| tree | 2e1397c560b490e930a4f5b123286b11f57cc215 | |
| parent | 4b855ffcaeee0d961bb900f4cc9d4665cee87dd4 (diff) | |
<iman> add website categories lob
4 files changed, 47 insertions, 13 deletions
diff --git a/indoteknik_api/controllers/api_v1/__init__.py b/indoteknik_api/controllers/api_v1/__init__.py index 5952a929..2d774071 100644 --- a/indoteknik_api/controllers/api_v1/__init__.py +++ b/indoteknik_api/controllers/api_v1/__init__.py @@ -21,6 +21,7 @@ from . import user from . import wishlist from . import brand_homepage from . import category_management +from . import category_management_lob from . import customer from . import content from . import midtrans diff --git a/indoteknik_api/controllers/api_v1/category_management_lob.py b/indoteknik_api/controllers/api_v1/category_management_lob.py new file mode 100644 index 00000000..0f666f2f --- /dev/null +++ b/indoteknik_api/controllers/api_v1/category_management_lob.py @@ -0,0 +1,36 @@ +from odoo import http +from odoo.http import request +from .. import controller +import json + +class BrandHomepage(controller.Controller): + prefix = '/api/v1/' + + @http.route(prefix + 'lob_homepage', auth='public', methods=['GET', 'OPTIONS'], csrf=False) + @controller.Controller.must_authorized() + def get_brand_homepage(self, **kw): + base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') + + query = [('status', '=', 'tayang')] + lob = request.env['website.categories.lob'].search(query, order='sequence') + + data = [] + for category in lob: + category_ids = [ + { + 'id': cat.id, + 'name': cat.name + } for cat in category.category_ids + ] + data.append({ + 'id': category.id, + 'sequence': category.sequence, + 'industries': category.category_id.name if category.category_id else '', + 'image': base_url + '/api/image/website.categories.lob/image/' + str(category.id) if category.image else '', + 'category_ids': category_ids + }) + + return request.make_response( + json.dumps(data), + headers=[('Cache-Control', 'max-age=3600, public'), ('Content-Type', 'application/json')] + ) diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 4bf0b88d..2143fbe2 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -66,11 +66,8 @@ class ProductTemplate(models.Model): variant_codes = ', '.join([x.default_code or '' for x in template.product_variant_ids]) # Mengumpulkan semua kategori - category_ids = [] - category_names = [] - for category in template.public_categ_ids: - category_ids.append(category.id) - category_names.append(category.name) + category_ids = [category.id for category in template.public_categ_ids] + category_names = [category.name for category in template.public_categ_ids] document = solr_model.get_doc('product', template.id) document.update({ @@ -93,7 +90,7 @@ class ProductTemplate(models.Model): "variants_code_t": variant_codes, "search_rank_i": template.search_rank, "search_rank_weekly_i": template.search_rank_weekly, - "category_id_i": ','.join(map(str, category_ids)), # ID kategori sebagai string yang dipisahkan koma + "category_id_ids": category_ids, # ID kategori sebagai string yang dipisahkan koma "category_name_s": ', '.join(category_names), # Nama kategori sebagai string yang dipisahkan koma "category_name": category_names, # Nama kategori sebagai list "description_t": template.website_description or '', @@ -102,12 +99,12 @@ class ProductTemplate(models.Model): 'sni_b': template.unpublished, 'tkdn_b': template.unpublished, "qty_sold_f": template.qty_sold, - "voucher_pastihemat" : { - "min_purchase" : voucher.min_purchase_amount, - "discount_type" : voucher.discount_type, - "discount_amount" : voucher.discount_amount, - "max_discount" : voucher.max_discount_amount - } + # "voucher_pastihemat" : { + # "min_purchase" : voucher.min_purchase_amount, + # "discount_type" : voucher.discount_type, + # "discount_amount" : voucher.discount_amount, + # "max_discount" : voucher.max_discount_amount + # } }) print(document) diff --git a/indoteknik_custom/models/website_categories_lob.py b/indoteknik_custom/models/website_categories_lob.py index 5fd7bfef..88182ba5 100644 --- a/indoteknik_custom/models/website_categories_lob.py +++ b/indoteknik_custom/models/website_categories_lob.py @@ -5,7 +5,7 @@ class WebsiteCategoriesLob(models.Model): _name = 'website.categories.lob' _rec_name = 'category_id' - category_id = fields.Many2one('res.partner.industry', string='Category', help='table ecommerce category') + category_id = fields.Many2one('res.partner.industry', string='Industri', help='table ecommerce category') image = fields.Binary(string='Image') sequence = fields.Integer(string='Sequence') status = fields.Selection([ |
