summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-11-01 14:17:27 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-11-01 14:17:27 +0700
commit196d8939a3f1118fe0e635dd261d19f887c4be2d (patch)
tree43663249f9c99d86516c2489b523c0209095a25b
parentb2ac5d8be2d426dd968cbc9244377ecf3040800b (diff)
Banner Rest API & similar product method rest api
-rw-r--r--indoteknik_api/controllers/api_v1/__init__.py1
-rw-r--r--indoteknik_api/controllers/api_v1/banner.py31
-rw-r--r--indoteknik_api/controllers/api_v1/product.py2
-rwxr-xr-xindoteknik_custom/models/coupon_program.py10
-rwxr-xr-xindoteknik_custom/models/x_banner_banner.py4
-rwxr-xr-xindoteknik_custom/models/x_banner_category.py3
-rwxr-xr-xindoteknik_custom/views/coupon_program.xml3
-rwxr-xr-xindoteknik_custom/views/x_banner_banner.xml2
-rwxr-xr-xindoteknik_custom/views/x_banner_category.xml5
9 files changed, 41 insertions, 20 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..26a7f1ec 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -84,7 +84,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_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/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>