diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-06-09 15:11:05 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-06-09 15:11:05 +0700 |
| commit | 1bc03c1482a664ffcd58f19022a40e65e21774c6 (patch) | |
| tree | f491d00cd1d371c8fd76ad25e014ac8d662c3d02 /indoteknik_api | |
| parent | 1bd3a91889f8616d7042c0d15315c2f25c974ed3 (diff) | |
| parent | f43855aa55265794c7774af79089258e830b0df4 (diff) | |
(andri) fix merge biteship with odoo-backup
Diffstat (limited to 'indoteknik_api')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 114 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/sale_order.py | 2 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/stock_picking.py | 2 | ||||
| -rw-r--r-- | indoteknik_api/models/sale_order.py | 16 |
4 files changed, 111 insertions, 23 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() diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index e8c2c75a..12eac2e5 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -462,7 +462,7 @@ class SaleOrder(controller.Controller): if params['value']['type'] == 'sale_order': parameters['approval_status'] = 'pengajuan1' - sale_order = request.env['sale.order'].create([parameters]) + sale_order = request.env['sale.order'].with_context(from_website_checkout=True).create([parameters]) sale_order.onchange_partner_contact() user_id = params['value']['user_id'] diff --git a/indoteknik_api/controllers/api_v1/stock_picking.py b/indoteknik_api/controllers/api_v1/stock_picking.py index 7cbd3c96..c5a4f7ed 100644 --- a/indoteknik_api/controllers/api_v1/stock_picking.py +++ b/indoteknik_api/controllers/api_v1/stock_picking.py @@ -3,6 +3,7 @@ from odoo import http from odoo.http import request from pytz import timezone from datetime import datetime +import json class StockPicking(controller.Controller): @@ -103,7 +104,6 @@ class StockPicking(controller.Controller): picking = picking_model.browse(id) if not picking: return self.response(None) - hostori = picking.get_tracking_detail() return self.response(picking.get_tracking_detail()) @http.route(prefix + 'stock-picking/<id>/tracking', auth='public', method=['GET', 'OPTIONS']) diff --git a/indoteknik_api/models/sale_order.py b/indoteknik_api/models/sale_order.py index baba7c37..45461974 100644 --- a/indoteknik_api/models/sale_order.py +++ b/indoteknik_api/models/sale_order.py @@ -29,13 +29,23 @@ class SaleOrder(models.Model): 'pickings': [] } for picking in sale_order.picking_ids: - if not picking.name.startswith('BU/OUT'): + picking_model = self.env['stock.picking'].sudo().search([('id', '=', picking.id), ('name', 'like', '%BU/OUT/%')], limit=1) + if not picking_model: continue + response = picking_model.get_tracking_detail() + data['pickings'].append({ + 'waybill_number' : response['waybill_number'] or '', + 'delivered_date': response['delivered_date'], + 'delivery_order' : { + 'carrier' : response['delivery_order']['carrier'] or '', + 'service' : response['delivery_order']['service'] or '' + }, + 'eta' : response['eta'], 'id': picking.id, 'name': picking.name, - 'tracking_number': picking.delivery_tracking_no or '', - 'delivered': picking.waybill_id.delivered or picking.driver_arrival_date != False or picking.sj_return_date != False, + # 'tracking_number': picking.delivery_tracking_no or '', + # 'delivered': picking.waybill_id.delivered or picking.driver_arrival_date != False or picking.sj_return_date != False, }) if sale_order.state == 'cancel': data['status'] = 'cancel' |
