summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-05-27 10:19:09 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-05-27 10:19:09 +0700
commitf0f414383b3bd34e6fce12e68e171014c08d2a55 (patch)
treef9eef4c1331f6507fadc680bdd801656ff9f8ea7 /indoteknik_api/controllers
parent431229f2a6f1203fbdfe470229e55da8ebd3ea01 (diff)
parentd3f530b94569059106164172485aaa9665e80709 (diff)
Merge branch 'odoo-backup' into CR/repeat-order
Diffstat (limited to 'indoteknik_api/controllers')
-rw-r--r--indoteknik_api/controllers/api_v1/banner.py30
-rw-r--r--indoteknik_api/controllers/api_v1/flash_sale.py2
-rw-r--r--indoteknik_api/controllers/api_v1/product.py96
-rw-r--r--indoteknik_api/controllers/api_v1/sale_order.py26
-rw-r--r--indoteknik_api/controllers/api_v1/stock_picking.py9
-rw-r--r--indoteknik_api/controllers/api_v1/user.py1
6 files changed, 110 insertions, 54 deletions
diff --git a/indoteknik_api/controllers/api_v1/banner.py b/indoteknik_api/controllers/api_v1/banner.py
index 308d2765..64a6167b 100644
--- a/indoteknik_api/controllers/api_v1/banner.py
+++ b/indoteknik_api/controllers/api_v1/banner.py
@@ -15,7 +15,8 @@ class Banner(controller.Controller):
limit = int(kw.get('limit', 0))
offset = int(kw.get('offset', 0))
order = kw.get('order', 'write_date DESC')
-
+ keyword = kw.get('keyword')
+
query = [('x_status_banner', '=', 'tayang')]
if type:
query += [('x_banner_category.x_studio_field_KKVl4', '=', type)]
@@ -25,9 +26,27 @@ class Banner(controller.Controller):
if manufacture_id:
query += [('x_relasi_manufacture', '=', int(manufacture_id))]
-
- banners = request.env['x_banner.banner'].search(query, limit=limit, offset=offset, order=order)
-
+
+ banner_kumpulan = []
+ banner_ids = set() # Set untuk menyimpan ID banner agar tidak duplikat
+
+ if keyword:
+ keyword_list = [word.strip() for word in keyword.split() if word.strip()] # Pisahkan berdasarkan spasi
+
+ for word in keyword_list:
+ keyword_query = query + [('x_keyword_banner', 'ilike', word)] # Buat query baru dengan keyword
+ banners = request.env['x_banner.banner'].search(keyword_query, limit=limit, offset=offset, order=order)
+
+ for banner in banners:
+ if banner.id not in banner_ids: # Pastikan tidak ada duplikasi
+ banner_kumpulan.append(banner)
+ banner_ids.add(banner.id)
+
+ if not keyword:
+ banners = request.env['x_banner.banner'].search(query, limit=limit, offset=offset, order=order)
+ else:
+ banners = banner_kumpulan if len(banner_kumpulan) > 0 else request.env['x_banner.banner'].search(query, limit=limit, offset=offset, order=order)
+
week_number = self.get_week_number_of_current_month()
end_datas = []
@@ -41,7 +60,8 @@ class Banner(controller.Controller):
'group_by_week': banner.group_by_week,
'image': request.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', banner.id),
'headline_banner': banner.x_headline_banner,
- 'description_banner': banner.x_description_banner
+ 'description_banner': banner.x_description_banner,
+ 'keyword_banner': banner.x_keyword_banner
}
if banner.group_by_week and int(banner.group_by_week) < week_number and type == 'index-a-1':
diff --git a/indoteknik_api/controllers/api_v1/flash_sale.py b/indoteknik_api/controllers/api_v1/flash_sale.py
index 6c4ad8c0..1038500c 100644
--- a/indoteknik_api/controllers/api_v1/flash_sale.py
+++ b/indoteknik_api/controllers/api_v1/flash_sale.py
@@ -14,7 +14,7 @@ class FlashSale(controller.Controller):
def _get_flash_sale_header(self, **kw):
try:
# base_url = request.env['ir.config_parameter'].get_param('web.base.url')
- active_flash_sale = request.env['product.pricelist'].get_is_show_program_flash_sale()
+ active_flash_sale = request.env['product.pricelist'].get_is_show_program_flash_sale(is_show_program=kw.get('is_show_program'))
data = []
for pricelist in active_flash_sale:
query = [
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 557215ea..a88c3368 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -34,60 +34,66 @@ class Product(controller.Controller):
categories.reverse()
return self.response(categories, headers=[('Cache-Control', 'max-age=3600, public')])
- @http.route(prefix + 'product/variants/sla', 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):
- body_params = kwargs.get('ids')
- if not body_params:
- return self.response('Failed', code=400, description='id is required')
+ raw_data = kwargs.get('products', '[]')
+ product_data = json.loads(raw_data)
- ids = [int(id.strip()) for id in body_params.split(',') if id.strip().isdigit()]
-
- sla_duration = 0
- sla_unit = 'Hari'
- include_instant = True
- products = request.env['product.product'].search([('id', 'in', ids)])
- if len(products) < 1:
- return self.response(
- 'Failed',
- code=400,
- description='Produk Tidak Di Temukan.'
- )
+ product_ids = [int(item["id"]) for item in product_data]
+ products = request.env['purchase.pricelist'].search([
+ ('product_id', 'in', product_ids),
+ ('is_winner', '=', True)
+ ])
- product_slas = request.env['product.sla'].search([('product_variant_id', 'in', ids)])
- if len(product_slas) < 1:
- return self.response(
- 'Failed',
- code=400,
- description='SLA 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_duration = max(sla_duration, int(product_sla.sla))
- sla_unit = product_sla.sla_vendor_id.unit
- if product.qty_free_bandengan < 1 :
- if product_sla.sla_vendor_id.unit != 'jam':
- include_instant = False
- break
-
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
+ )
- # Jika semua loop selesai tanpa include_instant menjadi False
+ 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': sla_duration,
- 'sla_additional_days': additional_days,
- 'sla_total' : int(sla_duration) + int(additional_days),
- 'sla_unit': 'Hari' if additional_days > 0 else sla_unit
- }
- )
+ '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()
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py
index 3219fc07..39fa0e13 100644
--- a/indoteknik_api/controllers/api_v1/sale_order.py
+++ b/indoteknik_api/controllers/api_v1/sale_order.py
@@ -54,6 +54,20 @@ class SaleOrder(controller.Controller):
# sales = request.env['sale.order'].search_read([('name', '=', sale_number)], fields=['id', 'name', 'amount_total', 'state'])
sales = request.env['sale.order'].search(query, limit=1)
data = []
+ INDONESIAN_MONTHS = {
+ 1: 'Januari',
+ 2: 'Februari',
+ 3: 'Maret',
+ 4: 'April',
+ 5: 'Mei',
+ 6: 'Juni',
+ 7: 'Juli',
+ 8: 'Agustus',
+ 9: 'September',
+ 10: 'Oktober',
+ 11: 'November',
+ 12: 'Desember',
+ }
for sale in sales:
product_name = ''
product_not_in_id = 0
@@ -69,6 +83,7 @@ class SaleOrder(controller.Controller):
'amount_untaxed': sale.amount_untaxed,
'amount_tax': sale.amount_tax,
'amount_total': sale.amount_total,
+ 'expected_ready_to_ship': f"{sale.expected_ready_to_ship.day} {INDONESIAN_MONTHS[sale.expected_ready_to_ship.month]} {sale.expected_ready_to_ship.year}",
'product_name': product_name,
'product_not_in_id': product_not_in_id,
'details': [request.env['sale.order.line'].api_single_response(x, context='with_detail') for x in sale.order_line]
@@ -186,6 +201,15 @@ class SaleOrder(controller.Controller):
sale_order = request.env['sale.order'].search(domain)
if sale_order:
data = request.env['sale.order'].api_v1_single_response(sale_order, context='with_detail')
+ if sale_order.expected_ready_to_ship:
+ bulan_id = [
+ "Januari", "Februari", "Maret", "April", "Mei", "Juni",
+ "Juli", "Agustus", "September", "Oktober", "November", "Desember"
+ ]
+ tanggal = sale_order.expected_ready_to_ship.day
+ bulan = bulan_id[sale_order.expected_ready_to_ship.month - 1]
+ tahun = sale_order.expected_ready_to_ship.year
+ data['expected_ready_to_ship'] = f"{tanggal} {bulan} {tahun}"
return self.response(data)
@@ -510,6 +534,8 @@ class SaleOrder(controller.Controller):
'program_line_id': cart['id'],
'quantity': cart['quantity']
})
+
+ sale_order._compute_etrts_date()
request.env['sale.order.promotion'].create(promotions)
diff --git a/indoteknik_api/controllers/api_v1/stock_picking.py b/indoteknik_api/controllers/api_v1/stock_picking.py
index 55e07152..31706b99 100644
--- a/indoteknik_api/controllers/api_v1/stock_picking.py
+++ b/indoteknik_api/controllers/api_v1/stock_picking.py
@@ -116,10 +116,10 @@ class StockPicking(controller.Controller):
return self.response(picking.get_tracking_detail())
- @http.route(prefix + 'stock-picking/<picking_code>/documentation', auth='public', methods=['PUT', 'OPTIONS'], csrf=False)
+ @http.route(prefix + 'stock-picking/<scanid>/documentation', auth='public', methods=['PUT', 'OPTIONS'], csrf=False)
@controller.Controller.must_authorized()
def write_partner_stock_picking_documentation(self, **kw):
- picking_code = int(kw.get('picking_code', 0))
+ scanid = int(kw.get('scanid', 0))
sj_document = kw.get('sj_document', False)
paket_document = kw.get('paket_document', False)
@@ -128,7 +128,10 @@ class StockPicking(controller.Controller):
'driver_arrival_date': datetime.utcnow(),
}
- picking_data = request.env['stock.picking'].search([('picking_code', '=', picking_code)], limit=1)
+ picking_data = request.env['stock.picking'].search([('id', '=', scanid)], limit=1)
+
+ if not picking_data:
+ picking_data = request.env['stock.picking'].search([('picking_code', '=', scanid)], limit=1)
if not picking_data:
return self.response(code=404, description='picking not found')
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py
index 8523d90b..b5b7e055 100644
--- a/indoteknik_api/controllers/api_v1/user.py
+++ b/indoteknik_api/controllers/api_v1/user.py
@@ -131,6 +131,7 @@ class User(controller.Controller):
nama_wajib_pajak = kw.get('nama_wajib_pajak', False)
is_pkp = kw.get('is_pkp')
is_terdaftar = kw.get('is_terdaftar', False)
+ is_terdaftar = False if is_terdaftar == 'false' else is_terdaftar
type_acc = kw.get('type_acc', 'individu') or 'individu'
if not name or not email or not password: