diff options
| -rw-r--r-- | indoteknik_api/controllers/api_v1/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/banner.py | 31 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 14 | ||||
| -rw-r--r-- | indoteknik_api/controllers/controller.py | 6 | ||||
| -rw-r--r-- | indoteknik_api/models/product_template.py | 6 | ||||
| -rwxr-xr-x | indoteknik_custom/models/coupon_program.py | 10 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 11 | ||||
| -rwxr-xr-x | indoteknik_custom/models/x_banner_banner.py | 4 | ||||
| -rwxr-xr-x | indoteknik_custom/models/x_banner_category.py | 3 | ||||
| -rwxr-xr-x | indoteknik_custom/views/coupon_program.xml | 3 | ||||
| -rwxr-xr-x | indoteknik_custom/views/x_banner_banner.xml | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/views/x_banner_category.xml | 5 |
12 files changed, 70 insertions, 26 deletions
diff --git a/indoteknik_api/controllers/api_v1/__init__.py b/indoteknik_api/controllers/api_v1/__init__.py index 275313ff..c8280c9a 100644 --- a/indoteknik_api/controllers/api_v1/__init__.py +++ b/indoteknik_api/controllers/api_v1/__init__.py @@ -1,3 +1,4 @@ +from . import banner from . import blog from . import category from . import flash_sale diff --git a/indoteknik_api/controllers/api_v1/banner.py b/indoteknik_api/controllers/api_v1/banner.py new file mode 100644 index 00000000..60f9be85 --- /dev/null +++ b/indoteknik_api/controllers/api_v1/banner.py @@ -0,0 +1,31 @@ +from .. import controller +from odoo import http +from odoo.http import request + + +class Banner(controller.Controller): + prefix = '/api/v1/' + + @http.route(prefix + 'banner', auth='public', methods=['GET']) + def get_banner(self, **kw): + if not self.authenticate(): + return self.response(code=401, description='Unauthorized') + + base_url = request.env['ir.config_parameter'].get_param('web.base.url') + type = kw.get('type') + if not type: + return self.response(code=400, description='type is required') + + data = [] + banner_category = request.env['x_banner.category'].search([('x_studio_field_KKVl4', '=', type)], limit=1) + + if banner_category: + for banner in banner_category.banner_ids: + if banner.x_status_banner == 'tayang': + data.append({ + 'name': banner.x_name, + 'url': banner.x_url_banner, + 'image': base_url + 'api/image/x_banner.banner/x_banner_image/' + str(banner.id) if banner.x_banner_image else '', + }) + + return self.response(data)
\ No newline at end of file diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 15f75d98..904670e7 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -15,15 +15,16 @@ class Product(controller.Controller): manufactures = kw.get('manufactures') categories = kw.get('categories') ready_stock = kw.get('ready_stock') + solr_flag = kw.get('solr_flag') - require_betweens = ['name', 'manufactures', 'categories', 'ready_stock'] + require_betweens = ['name', 'manufactures', 'categories', 'ready_stock', 'solr_flag'] is_fulfill = False for required in require_betweens: if kw.get(required): is_fulfill = True if not is_fulfill: - return self.response(code=400, description='name or manufactures or categories is required') + return self.response(code=400, description='name or manufactures or categories or ready_stock or solr_flag is required') query = [('sale_ok', '=', True)] @@ -44,6 +45,11 @@ class Product(controller.Controller): if ready_stock == '1': query.append(('virtual_qty', '>', 0)) + if solr_flag: + query.append(('solr_flag', '=', int(solr_flag))) + + is_with_detail = True if kw.get('with_detail') == '1' else False + price_from = kw.get('price_from') if price_from and int(price_from): query.append(('web_price_sorting', '>=', int(price_from))) @@ -63,7 +69,7 @@ class Product(controller.Controller): product_templates = request.env['product.template'].search(query, limit=limit, offset=offset, order=order) data = { 'product_total': request.env['product.template'].search_count(query), - 'products': [request.env['product.template'].api_single_response(x) for x in product_templates] + 'products': [request.env['product.template'].api_single_response(x, with_detail=is_with_detail) for x in product_templates] } return self.response(data) @@ -84,7 +90,7 @@ class Product(controller.Controller): return self.response(data) - @http.route(prefix + 'product/<id>/similar', auth='public', methods=['GET'], cors="*") + @http.route(prefix + 'product/<id>/similar', auth='public', methods=['GET', 'OPTIONS']) def get_product_similar_by_id(self, **kw): if not self.authenticate(): return self.response(code=401, description='Unauthorized') diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py index c02f6b60..4653bd1e 100644 --- a/indoteknik_api/controllers/controller.py +++ b/indoteknik_api/controllers/controller.py @@ -50,7 +50,11 @@ class Controller(http.Controller): response.update({'result': data}) response = json.dumps(response) - return request.make_response(response, [('Content-Type', 'application/json')]) + return request.make_response(response, [ + ('Access-Control-Allow-Origin', '*'), + ('Access-Control-Allow-Headers', '*'), + ('Content-Type', 'application/json'), + ]) def search_filter(self, model: str, kw: dict, query: array = []): """ To search data by default API Params if exist """ diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py index e99b2c2d..a1e2e5a4 100644 --- a/indoteknik_api/models/product_template.py +++ b/indoteknik_api/models/product_template.py @@ -25,6 +25,8 @@ class ProductTemplate(models.Model): 'image': base_url + 'api/image/product.template/image_512/' + str(product_template.id) if product_template.image_512 else '', 'variants': [], 'description': product_template.website_description or '', + 'solr_flag': product_template.solr_flag, + 'product_rating': product_template.product_rating, } for variant in product_template.product_variant_ids: data_with_detail['variants'].append({ @@ -34,7 +36,9 @@ class ProductTemplate(models.Model): 'price': self.env['product.pricelist'].compute_price(product_pricelist_default_discount_id, variant.id), 'stock': variant.qty_stock_vendor, 'weight': variant.weight, - 'attributes': [x.name for x in variant.product_template_attribute_value_ids] + 'attributes': [x.name for x in variant.product_template_attribute_value_ids], + 'solr_flag': product_template.solr_flag, + 'product_rating': product_template.product_rating, }) data.update(data_with_detail) return data diff --git a/indoteknik_custom/models/coupon_program.py b/indoteknik_custom/models/coupon_program.py index 4c839c9f..033ee4a3 100755 --- a/indoteknik_custom/models/coupon_program.py +++ b/indoteknik_custom/models/coupon_program.py @@ -7,14 +7,4 @@ class CouponProgram(models.Model): x_studio_banner_promo = fields.Binary(string="Banner Promo") x_studio_field_2Ul77 = fields.Binary(string="Icon Program Promo 2") x_studio_field_Ifopn = fields.Binary(string="Icon Program Promo") - x_studio_field_xaRIr = fields.One2many( - comodel_name="x_banner.banner", - inverse_name="x_studio_field_7ppSi", - string="New One2many" - ) - x_studio_field_xo3cl = fields.One2many( - comodel_name="x_banner.banner", - inverse_name="x_studio_field_7ppSi", - string="Relasi Banner" - ) x_studio_image_promo = fields.Binary(string="Image Promo") diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 28356a86..13654ab3 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -33,13 +33,17 @@ class ProductTemplate(models.Model): web_price_sorting = fields.Float('Web Price Sorting', help='Hanya digunakan untuk sorting di web, harga tidak berlaku', default=0.0) virtual_qty = fields.Float(string='Virtual Qty', default=0) solr_flag = fields.Integer(string='Solr Flag', default=0) + + def write(self, vals): + vals['solr_flag'] = 2 + return super().write(vals) def _compute_qty_stock_vendor(self): for product_template in self: product_template.qty_stock_vendor = 0 for product_variant in product_template.product_variant_ids: product_template.qty_stock_vendor += int(product_variant.qty_stock_vendor) - + def _compute_web_price(self): for template in self: product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) @@ -144,6 +148,11 @@ class ProductProduct(models.Model): 'Qty Stock Vendor', compute='_compute_stock_vendor', help="Stock Vendor") solr_flag = fields.Integer(string='Solr Flag', default=0) + + def write(self, vals): + self.product_tmpl_id.solr_flag = 2 + vals['solr_flag'] = 2 + return super().write(vals) def _compute_web_price(self): for product in self: diff --git a/indoteknik_custom/models/x_banner_banner.py b/indoteknik_custom/models/x_banner_banner.py index a402789a..bc80e2a9 100755 --- a/indoteknik_custom/models/x_banner_banner.py +++ b/indoteknik_custom/models/x_banner_banner.py @@ -10,11 +10,9 @@ class XBannerBanner(models.Model): x_url_banner = fields.Char(string="URL Banner") x_banner_image = fields.Binary(string="Image") x_banner_category = fields.Many2one('x_banner.category', string="Banner Category") - # x_banner_tags = fields.Many2many('blog.tag', string="Banner Tags") x_relasi_manufacture = fields.Many2one('x_manufactures', string="Relasi Merek") x_sequence_banner = fields.Integer(string="Sequence") x_status_banner = fields.Selection([ ('tayang', 'Tayang'), ('tidak_tayang', 'Tidak Tayang') - ], string="Status") - x_studio_field_7ppSi = fields.Many2one('coupon.program', string="Coupon Program")
\ No newline at end of file + ], string="Status")
\ No newline at end of file diff --git a/indoteknik_custom/models/x_banner_category.py b/indoteknik_custom/models/x_banner_category.py index 7c91bd78..fe4f6025 100755 --- a/indoteknik_custom/models/x_banner_category.py +++ b/indoteknik_custom/models/x_banner_category.py @@ -8,4 +8,5 @@ class XBannerCategory(models.Model): x_name = fields.Char(string="Name") x_banner_subtitle = fields.Char(string="Sub Title") - x_studio_field_KKVl4 = fields.Char(string="URL") + x_studio_field_KKVl4 = fields.Char(string="Slug") + banner_ids = fields.One2many('x_banner.banner', 'x_banner_category', 'Banner') diff --git a/indoteknik_custom/views/coupon_program.xml b/indoteknik_custom/views/coupon_program.xml index e4ad0bd8..54449777 100755 --- a/indoteknik_custom/views/coupon_program.xml +++ b/indoteknik_custom/views/coupon_program.xml @@ -16,9 +16,6 @@ <field name="x_studio_image_promo" width="80" widget="image"/> <field name="x_studio_banner_promo" width="80" widget="image"/> </xpath> - <xpath expr="//form[1]/sheet[1]" position="inside"> - <field name="x_studio_field_xo3cl" string="Relasi Banner"/> - </xpath> </field> </record> </odoo>
\ No newline at end of file diff --git a/indoteknik_custom/views/x_banner_banner.xml b/indoteknik_custom/views/x_banner_banner.xml index f48b20c4..a83ae5ab 100755 --- a/indoteknik_custom/views/x_banner_banner.xml +++ b/indoteknik_custom/views/x_banner_banner.xml @@ -9,7 +9,6 @@ <field name="x_name"/> <field name="x_banner_category"/> <field name="x_relasi_manufacture"/> - <field name="x_studio_field_7ppSi"/> <field name="x_url_banner"/> <field name="x_status_banner"/> </tree> @@ -29,7 +28,6 @@ <field name="x_relasi_manufacture"/> <field name="x_url_banner"/> <field name="x_status_banner"/> - <field name="x_studio_field_7ppSi"/> </group> <group> <field name="x_banner_image" widget="image"/> diff --git a/indoteknik_custom/views/x_banner_category.xml b/indoteknik_custom/views/x_banner_category.xml index 0c2e053d..45ad7940 100755 --- a/indoteknik_custom/views/x_banner_category.xml +++ b/indoteknik_custom/views/x_banner_category.xml @@ -27,6 +27,11 @@ </group> <group></group> </group> + <notebook> + <page string="Banner"> + <field name="banner_ids"/> + </page> + </notebook> </sheet> </form> </field> |
