summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-11-03 17:09:24 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-11-03 17:09:24 +0700
commit03dfa0271a0da453c83de83c73398dabb0e16fc7 (patch)
treeaa0e6ad88df68c9b54d790b907396a227883fea8
parent7f0ba3734ffbfa22813e199fbf8a556750a350f7 (diff)
Get manufacture API
-rw-r--r--indoteknik_api/__manifest__.py2
-rw-r--r--indoteknik_api/controllers/api_v1/manufacture.py31
-rw-r--r--indoteknik_api/models/__init__.py1
-rw-r--r--indoteknik_api/models/x_manufactures.py14
4 files changed, 40 insertions, 8 deletions
diff --git a/indoteknik_api/__manifest__.py b/indoteknik_api/__manifest__.py
index b1ebd9a1..fa6902cc 100644
--- a/indoteknik_api/__manifest__.py
+++ b/indoteknik_api/__manifest__.py
@@ -8,7 +8,7 @@
'author': 'PT. Indoteknik Dotcom Gemilang',
'website': '',
'images': ['assets/favicon.ico'],
- 'depends': ['base', 'sale'],
+ 'depends': ['base', 'sale', 'indoteknik_custom'],
'data': [],
'demo': [],
'css': [],
diff --git a/indoteknik_api/controllers/api_v1/manufacture.py b/indoteknik_api/controllers/api_v1/manufacture.py
index 3cb7b70c..3188f671 100644
--- a/indoteknik_api/controllers/api_v1/manufacture.py
+++ b/indoteknik_api/controllers/api_v1/manufacture.py
@@ -7,11 +7,32 @@ import ast
class Manufacture(controller.Controller):
prefix = '/api/v1/'
- @http.route(prefix + 'manufacture/page/<page>', auth='public', methods=['GET'])
+ @http.route(prefix + 'manufacture', auth='public', methods=['GET', 'OPTIONS'])
def get_manufacture(self, **kw):
if not self.authenticate():
return self.response(code=401, description='Unauthorized')
+ query = []
+
+ limit = int(kw.get('limit'))
+ offset = int(kw.get('offset'))
+
+ level = kw.get('level')
+ if level:
+ if level not in ['prioritas', 'gold', 'silver']:
+ return self.response(code=400, description='level possible value is prioritas, gold, silver')
+ query.append(('x_manufacture_level', '=', level))
+
+ manufactures = request.env['x_manufactures'].search(query, limit=limit, offset=offset)
+ data = [request.env['x_manufactures'].api_single_response(x) for x in manufactures]
+
+ return self.response(data)
+
+ @http.route(prefix + 'manufacture/page/<page>', auth='public', methods=['GET'])
+ def get_manufacture_by_page(self, **kw):
+ if not self.authenticate():
+ return self.response(code=401, description='Unauthorized')
+
manufacture_ids = []
page = kw.get('page')
if page == 'flash-sale':
@@ -39,11 +60,7 @@ class Manufacture(controller.Controller):
return self.response(code=400, description='page possible value is flash-sale, ready-stock, category, promotion')
manufactures = request.env['x_manufactures'].search([('id', 'in', manufacture_ids)])
- data = []
- for manufacture in manufactures:
- data.append({
- 'id': manufacture.id,
- 'name': manufacture.x_name
- })
+ data = [request.env['x_manufactures'].api_single_response(x) for x in manufactures]
+
return self.response(data)
\ No newline at end of file
diff --git a/indoteknik_api/models/__init__.py b/indoteknik_api/models/__init__.py
index de2a2804..bca7d9fe 100644
--- a/indoteknik_api/models/__init__.py
+++ b/indoteknik_api/models/__init__.py
@@ -1,3 +1,4 @@
from . import blog_post
from . import product_pricelist
from . import product_template
+from . import x_manufactures \ No newline at end of file
diff --git a/indoteknik_api/models/x_manufactures.py b/indoteknik_api/models/x_manufactures.py
new file mode 100644
index 00000000..6755ac66
--- /dev/null
+++ b/indoteknik_api/models/x_manufactures.py
@@ -0,0 +1,14 @@
+from odoo import models
+
+
+class Manufactures(models.Model):
+ _inherit = 'x_manufactures'
+
+ def api_single_response(self, manufacture, with_detail=False):
+ base_url = self.env['ir.config_parameter'].get_param('web.base.url')
+ data = {
+ 'id': manufacture.id,
+ 'logo': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(manufacture.id) if manufacture.x_logo_manufacture else '',
+ 'name': manufacture.x_name,
+ }
+ return data \ No newline at end of file