summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/product.py80
1 files changed, 70 insertions, 10 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 32362582..7570015f 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -1,6 +1,6 @@
from .. import controller
from odoo import http
-from odoo.http import request
+from odoo.http import request, Response
from datetime import datetime, timedelta
import ast
import logging
@@ -33,9 +33,60 @@ class Product(controller.Controller):
categories.reverse()
return self.response(categories, headers=[('Cache-Control', 'max-age=3600, public')])
-
- @http.route(prefix + 'product_variant/<id>/stock', auth='public', methods=['GET', 'OPTIONS'])
+
+ @http.route(prefix + 'product/variants/sla', auth='none', type='json', csrf=False, cors='*', methods=['GET', 'OPTIONS'])
@controller.Controller.must_authorized()
+ def get_product_template_sla_by_id(self, **kw):
+ json_raw = json.loads(request.httprequest.data)
+
+ ids = json_raw.get('ids')
+ ids = list(map(int, ids))
+
+ if not ids or not isinstance(ids, list):
+ return ({'status' : 'Failed','message': 'Parameter "ids" harus berupa list dan tidak boleh kosong.'})
+
+ sla_days = 0
+ products = request.env['product.product'].search([('id', 'in', ids)])
+ if len(products) < 1:
+ return ({
+ 'status' : 'Failed',
+ 'message' : 'Produk Tidak Di Temukan.'
+ })
+
+ product_slas = request.env['product.sla'].search([('product_variant_id', 'in', ids)])
+ if len(product_slas) < 1:
+ return ({
+ 'status' : 'Failed',
+ 'message' : 'Produk Tidak Di Temukan.'
+ })
+
+ # Mapping SLA untuk mempermudah lookup
+ sla_map = {sla.product_variant_id.id: sla for sla in product_slas}
+
+ for product in products:
+ product_sla = sla_map.get(product.id)
+ if product_sla:
+ sla_days = max(sla_days, product_sla.sla_vendor_id.duration)
+ if product.qty_free_bandengan < 1 :
+ if product_sla.sla_vendor_id.unit != 'jam':
+ return ({
+ 'status' : 'Success',
+ 'data' : [{
+ 'include_instant': False,
+ 'sla_days': sla_days
+ }],
+ })
+ # Jika semua loop selesai tanpa include_instant menjadi False
+ return ({
+ 'status' : 'Success',
+ 'data' : [{
+ 'include_instant': True,
+ 'sla_days': sla_days
+ }],
+ })
+
+ @http.route(prefix + 'product_variant/<id>/stock', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
def get_product_template_stock_by_id(self, **kw):
id = int(kw.get('id'))
date_7_days_ago = datetime.now() - timedelta(days=7)
@@ -47,12 +98,19 @@ class Product(controller.Controller):
('product_variant_id', '=', id),
('write_date', '>=', date_7_days_ago.strftime("%Y-%m-%d %H:%M:%S"))
], limit=1)
+
+ include_instant = False
qty_available = product.qty_free_bandengan
-
- if qty_available < 0:
- qty_available = 0
-
+
+
+ if qty_available > 0 :
+ include_instant = True
+ else :
+ qty_available = 0
+ if product_sla.sla_vendor_id.unit == 'jam':
+ include_instant = True
+
qty = 0
sla_date = '-'
@@ -74,17 +132,18 @@ class Product(controller.Controller):
if qty_available > 0:
qty = qty_available + total_adem + total_excell
+ sla_date = product_sla.sla or 1
elif qty_altama > 0 or qty_vendor > 0:
qty = total_adem if qty_altama > 0 else total_excell
- sla_date = '2-4 Hari'
+ sla_date = product_sla.sla
else:
- sla_date = '3-7 Hari'
+ sla_date = product_sla.sla
except:
print('error')
else:
if qty_available > 0:
qty = qty_available
- sla_date = product_sla.sla or '-'
+ sla_date = product_sla.sla or 'Indent'
elif qty_vendor > 0:
qty = total_excell
sla_date = '2-4 Hari'
@@ -92,6 +151,7 @@ class Product(controller.Controller):
data = {
'qty': qty,
'sla_date': sla_date,
+ 'can_instant': include_instant
}
return self.response(data, headers=[('Cache-Control', 'max-age=600, private')])