diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2025-05-14 09:23:14 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2025-05-14 09:23:14 +0700 |
| commit | f120c760c6a837681ebed26d9eea33a8961cd1aa (patch) | |
| tree | 728ecdd5ffd1530d97d58a9f18b850186b39aa67 /indoteknik_api/controllers/api_v1/product.py | |
| parent | a571531bd8626f9bee25e89c62bbd9268ed30597 (diff) | |
| parent | 2469ee37cfe854f0419a8c3fbabed5bc32bcaa6e (diff) | |
Merge branch 'odoo-backup' into CR/form-merchant
# Conflicts:
# indoteknik_custom/models/__init__.py
# indoteknik_custom/security/ir.model.access.csv
Diffstat (limited to 'indoteknik_api/controllers/api_v1/product.py')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 87 |
1 files changed, 75 insertions, 12 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 32362582..a88c3368 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -1,13 +1,13 @@ 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 import math import json -_logger = logging.getLogger(__name__) +_logger = logging.getLogger(__name__) class Product(controller.Controller): @@ -33,9 +33,70 @@ 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='public', methods=['POST', 'OPTIONS'] , csrf=False) @controller.Controller.must_authorized() + def get_product_template_sla_by_id(self, **kwargs): + + raw_data = kwargs.get('products', '[]') + product_data = json.loads(raw_data) + + product_ids = [int(item["id"]) for item in product_data] + products = request.env['purchase.pricelist'].search([ + ('product_id', 'in', product_ids), + ('is_winner', '=', True) + ]) + + start_date = datetime.today().date() + additional_days = request.env['sale.order'].get_days_until_next_business_day(start_date) + include_instant = True + + if(len(products) != len(product_ids)): + products_data_params = {product["id"] : product for product in product_data } + + all_fast_products = all( + product.product_id.qty_free_bandengan >= products_data_params.get(product.product_id.id, {}).get("quantity", 0) + for product in products + ) + + if all_fast_products: + return self.response({ + 'include_instant': include_instant, + 'sla_duration': 1, + 'sla_additional_days': additional_days, + 'sla_total' : int(1) + int(additional_days), + 'sla_unit': 'Hari' + }) + + max_slatime = 1 + + for vendor in products: + vendor_sla = request.env['vendor.sla'].search([('id_vendor', '=', vendor.vendor_id.id)], limit=1) + slatime = 15 + if vendor_sla: + if vendor_sla.unit == 'hari': + vendor_duration = vendor_sla.duration * 24 * 60 + include_instant = False + else : + vendor_duration = vendor_sla.duration * 60 + include_instant = True + + estimation_sla = (1 * 24 * 60) + vendor_duration + estimation_sla_days = estimation_sla / (24 * 60) + slatime = math.ceil(estimation_sla_days) + + max_slatime = max(max_slatime, slatime) + + return self.response({ + 'include_instant': include_instant, + 'sla_duration': max_slatime, + 'sla_additional_days': additional_days, + 'sla_total' : int(max_slatime) + int(additional_days), + 'sla_unit': 'Hari' + }) + + @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) @@ -49,10 +110,11 @@ class Product(controller.Controller): ], limit=1) qty_available = product.qty_free_bandengan - - if qty_available < 0: - qty_available = 0 - + + + if qty_available < 1 : + qty_available = 0 + qty = 0 sla_date = '-' @@ -74,24 +136,25 @@ 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' data = { 'qty': qty, - 'sla_date': sla_date, + 'sla_date': sla_date } return self.response(data, headers=[('Cache-Control', 'max-age=600, private')]) |
