diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2025-07-28 15:09:55 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2025-07-28 15:09:55 +0700 |
| commit | d15ce4e186e2b77f01e8dfd03886298cc733d4c1 (patch) | |
| tree | 1b32a4c29c4fcea85070fcecb5b77a7d55d30029 /indoteknik_api/controllers/api_v1/product.py | |
| parent | deba962d7368a5c4e30441b5a640102608e3dde6 (diff) | |
| parent | 36a53535dbdc5777266fd9276b4c557259dab6be (diff) | |
<hafid> merging odoo-backup
Diffstat (limited to 'indoteknik_api/controllers/api_v1/product.py')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 114 |
1 files changed, 96 insertions, 18 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index a88c3368..e97a7ff8 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -2,6 +2,7 @@ from .. import controller from odoo import http from odoo.http import request, Response from datetime import datetime, timedelta +import pytz import ast import logging import math @@ -46,12 +47,15 @@ class Product(controller.Controller): ('product_id', 'in', product_ids), ('is_winner', '=', True) ]) + jakarta = pytz.timezone("Asia/Jakarta") + start_date = datetime.now(jakarta) + + offset, is3pm = request.env['sale.order'].get_days_until_next_business_day(start_date) + additional_days = offset - 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)): + if(len(products) == len(product_ids)): products_data_params = {product["id"] : product for product in product_data } all_fast_products = all( @@ -63,8 +67,8 @@ class Product(controller.Controller): return self.response({ 'include_instant': include_instant, 'sla_duration': 1, - 'sla_additional_days': additional_days, - 'sla_total' : int(1) + int(additional_days), + 'sla_additional_days': int(additional_days), + 'sla_total' : int(additional_days), 'sla_unit': 'Hari' }) @@ -96,27 +100,40 @@ class Product(controller.Controller): }) @http.route(prefix + 'product_variant/<id>/stock', auth='public', methods=['GET', 'OPTIONS']) - @controller.Controller.must_authorized() + @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) - product = request.env['product.product'].search( - [('id', '=', id)], limit=1) - product_sla = request.env['product.sla'].search( - [('product_variant_id', '=', id)], limit=1) + product_pruchase = request.env['purchase.pricelist'].search([ + ('product_id', '=', id), + ('is_winner', '=', True) + ]) stock_vendor = request.env['stock.vendor'].search([ ('product_variant_id', '=', id), ('write_date', '>=', date_7_days_ago.strftime("%Y-%m-%d %H:%M:%S")) ], limit=1) + + product = product_pruchase.product_id + + vendor_sla = request.env['vendor.sla'].search([('id_vendor', '=', product_pruchase.vendor_id.id)], limit=1) + slatime = 15 + if vendor_sla: + if vendor_sla.unit == 'hari': + vendor_duration = vendor_sla.duration * 24 * 60 + else : + vendor_duration = vendor_sla.duration * 60 + + estimation_sla = (1 * 24 * 60) + vendor_duration + estimation_sla_days = estimation_sla / (24 * 60) + slatime = math.ceil(estimation_sla_days) qty_available = product.qty_free_bandengan - if qty_available < 1 : qty_available = 0 qty = 0 - sla_date = '-' + sla_date = f'{slatime} Hari' # Qty Stock Vendor qty_vendor = stock_vendor.quantity @@ -136,28 +153,89 @@ class Product(controller.Controller): if qty_available > 0: qty = qty_available + total_adem + total_excell - sla_date = product_sla.sla or 1 + sla_date = '1 Hari' elif qty_altama > 0 or qty_vendor > 0: qty = total_adem if qty_altama > 0 else total_excell - sla_date = product_sla.sla + sla_date = f'{slatime} Hari' else: - sla_date = product_sla.sla + sla_date = f'{slatime} Hari' except: print('error') else: if qty_available > 0: qty = qty_available - sla_date = product_sla.sla or 'Indent' + sla_date = f'1 Hari' elif qty_vendor > 0: qty = total_excell - sla_date = '2-4 Hari' + sla_date = f'{slatime} Hari' data = { 'qty': qty, 'sla_date': sla_date } - return self.response(data, headers=[('Cache-Control', 'max-age=600, private')]) + return self.response(data, headers=[('Cache-Control', 'max-age=600, private')]) + # def get_product_template_stock_by_id(self, **kw): + # id = int(kw.get('id')) + # date_7_days_ago = datetime.now() - timedelta(days=7) + # product = request.env['product.product'].search( + # [('id', '=', id)], limit=1) + # product_sla = request.env['product.sla'].search( + # [('product_variant_id', '=', id)], limit=1) + # stock_vendor = request.env['stock.vendor'].search([ + # ('product_variant_id', '=', id), + # ('write_date', '>=', date_7_days_ago.strftime("%Y-%m-%d %H:%M:%S")) + # ], limit=1) + + # qty_available = product.qty_free_bandengan + + + # if qty_available < 1 : + # qty_available = 0 + + # qty = 0 + # sla_date = '-' + + # # Qty Stock Vendor + # qty_vendor = stock_vendor.quantity + # qty_vendor -= int(qty_vendor * 0.1) + # qty_vendor = math.ceil(float(qty_vendor)) + # total_excell = qty_vendor + + # is_altama_product = product.x_manufacture.id in [10, 122, 89] + # if is_altama_product: + # try: + # # Qty Altama + # qty_altama = request.env['product.template'].get_stock_altama( + # product.default_code) + # qty_altama -= int(qty_altama * 0.1) + # qty_altama = math.ceil(float(qty_altama)) + # total_adem = qty_altama + + # 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 = product_sla.sla + # else: + # sla_date = product_sla.sla + # except: + # print('error') + # else: + # if qty_available > 0: + # qty = qty_available + # 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 + # } + + # return self.response(data, headers=[('Cache-Control', 'max-age=600, private')]) @http.route(prefix + 'product_variant/<id>/qty_available', auth='public', methods=['GET', 'OPTIONS']) @controller.Controller.must_authorized() |
