summaryrefslogtreecommitdiff
path: root/indoteknik_api
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-05-09 14:47:45 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-05-09 14:47:45 +0700
commit2262f57b0b56b7aa1535600de20b1a1dd611a991 (patch)
tree0de5a4c64b6877c801de5e95e6caa6f89e806889 /indoteknik_api
parentc50611bce3b2a57a7436f3f8b921207e36ff7f27 (diff)
parentd97277a0847bc57c0bc704c5ea62f75fadb461dc (diff)
Merge branch 'release' into staging
Diffstat (limited to 'indoteknik_api')
-rw-r--r--indoteknik_api/controllers/api_v1/__init__.py1
-rw-r--r--indoteknik_api/controllers/api_v1/banner.py1
-rw-r--r--indoteknik_api/controllers/api_v1/courier.py26
-rw-r--r--indoteknik_api/controllers/api_v1/flash_sale.py1
-rw-r--r--indoteknik_api/controllers/api_v1/user.py2
-rw-r--r--indoteknik_api/controllers/controller.py4
-rw-r--r--indoteknik_api/models/product_template.py9
-rw-r--r--indoteknik_api/models/res_users.py1
8 files changed, 42 insertions, 3 deletions
diff --git a/indoteknik_api/controllers/api_v1/__init__.py b/indoteknik_api/controllers/api_v1/__init__.py
index 5d5f723b..d05cdf3a 100644
--- a/indoteknik_api/controllers/api_v1/__init__.py
+++ b/indoteknik_api/controllers/api_v1/__init__.py
@@ -23,3 +23,4 @@ from . import customer
from . import content
from . import midtrans
from . import wati
+from . import courier
diff --git a/indoteknik_api/controllers/api_v1/banner.py b/indoteknik_api/controllers/api_v1/banner.py
index 4db320ed..1bd0fea6 100644
--- a/indoteknik_api/controllers/api_v1/banner.py
+++ b/indoteknik_api/controllers/api_v1/banner.py
@@ -31,6 +31,7 @@ class Banner(controller.Controller):
data.append({
'name': banner.x_name,
'url': banner.x_url_banner,
+ 'background_color': banner.background_color,
'image': request.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', banner.id),
})
diff --git a/indoteknik_api/controllers/api_v1/courier.py b/indoteknik_api/controllers/api_v1/courier.py
new file mode 100644
index 00000000..cd3e35c0
--- /dev/null
+++ b/indoteknik_api/controllers/api_v1/courier.py
@@ -0,0 +1,26 @@
+from .. import controller
+from odoo import http
+from odoo.http import request
+
+
+class Courier(controller.Controller):
+ prefix = '/api/v1/'
+
+ @http.route(prefix + 'courier', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def get_courier(self):
+ base_url = request.env['ir.config_parameter'].get_param('web.base.url')
+ query = [
+ ('publish', '=', True),
+ ]
+
+ couriers = request.env['rajaongkir.kurir'].search(query)
+ data = []
+ for courier in couriers:
+ data.append({
+ 'id': courier.delivery_carrier_id.id,
+ 'name': courier.name,
+ 'image': base_url + 'api/image/rajaongkir.kurir/image/'+str(courier.id)
+ })
+ return self.response(data)
+ \ No newline at end of file
diff --git a/indoteknik_api/controllers/api_v1/flash_sale.py b/indoteknik_api/controllers/api_v1/flash_sale.py
index a0aaa44e..dc7c3928 100644
--- a/indoteknik_api/controllers/api_v1/flash_sale.py
+++ b/indoteknik_api/controllers/api_v1/flash_sale.py
@@ -27,6 +27,7 @@ class FlashSale(controller.Controller):
'name': pricelist.name,
'banner': request.env['ir.attachment'].api_image('product.pricelist', 'banner', pricelist.id),
'banner_mobile': request.env['ir.attachment'].api_image('product.pricelist', 'banner_mobile', pricelist.id),
+ 'banner_top': request.env['ir.attachment'].api_image('product.pricelist', 'banner_top', pricelist.id),
'duration': round((pricelist.end_date - datetime.now()).total_seconds()),
'product_total': request.env['product.pricelist.item'].search_count(query),
})
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py
index 5edb208e..d82152b7 100644
--- a/indoteknik_api/controllers/api_v1/user.py
+++ b/indoteknik_api/controllers/api_v1/user.py
@@ -16,7 +16,7 @@ class User(controller.Controller):
])
def response_with_token(self, user):
- data = request.env['res.users'].api_single_response(user)
+ data = request.env['res.users'].sudo().api_single_response(user)
data['token'] = self.create_user_token(user)
return data
diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py
index 5b20f7d4..b850bdde 100644
--- a/indoteknik_api/controllers/controller.py
+++ b/indoteknik_api/controllers/controller.py
@@ -76,7 +76,8 @@ class Controller(http.Controller):
alias = next((r.replace('alias:', '') for r in rules if r.startswith('alias:')), key)
default = next((r.replace('default:', '') for r in rules if r.startswith('default:')), None)
- if (value := kw.get(key, '')) in ['null', 'undefined']:
+ value = kw.get(key, '')
+ if value in ['null', 'undefined']:
value = ''
if 'required' in rules and not value:
result['reason'].append(f"{key} is required")
@@ -157,6 +158,7 @@ class Controller(http.Controller):
partner_child_ids = [x['id'] for x in partner.child_ids] + [partner.id]
if partner.parent_id:
partner_child_ids += [x['id'] for x in partner.parent_id.child_ids]
+ partner_child_ids += [partner.parent_id.id]
return partner_child_ids
@http.route('/api/token', auth='public', methods=['GET', 'OPTIONS'])
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py
index b9df0f5f..c3df97a5 100644
--- a/indoteknik_api/models/product_template.py
+++ b/indoteknik_api/models/product_template.py
@@ -68,10 +68,17 @@ class ProductTemplate(models.Model):
}
if with_detail != '':
+ variants = [self.env['product.product'].v2_api_single_response(variant, pricelist=pricelist) for variant in product_template.product_variant_ids]
+ lowest_price = variants[0]['price']
+ for variant in variants:
+ if variant["price"]["price_discount"] < lowest_price["price_discount"]:
+ lowest_price = variant['price']
+
data_with_detail = {
+ 'lowest_price': lowest_price,
'image': self.env['ir.attachment'].api_image('product.template', 'image_512', product_template.id),
'display_name': product_template.display_name,
- 'variants': [self.env['product.product'].v2_api_single_response(variant, pricelist=pricelist) for variant in product_template.product_variant_ids],
+ 'variants': variants,
'description': product_template.website_description or '',
}
data.update(data_with_detail)
diff --git a/indoteknik_api/models/res_users.py b/indoteknik_api/models/res_users.py
index efe98815..80de083d 100644
--- a/indoteknik_api/models/res_users.py
+++ b/indoteknik_api/models/res_users.py
@@ -53,6 +53,7 @@ class ResUsers(models.Model):
'industry_id': user.industry_id.id or None,
'tax_name': user.nama_wajib_pajak or '',
'npwp': user.npwp or '',
+ 'rajaongkir_city_id': user.kota_id.rajaongkir_id or 0,
}
if user.kota_id: