summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_api/controllers')
-rw-r--r--indoteknik_api/controllers/api_v1/product.py87
-rw-r--r--indoteknik_api/controllers/api_v1/stock_picking.py85
2 files changed, 117 insertions, 55 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index e97a7ff8..2f546078 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -103,17 +103,21 @@ class Product(controller.Controller):
@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)
+ # date_7_days_ago = datetime.now() - timedelta(days=7)
+ product = request.env['product.product'].search([('id', '=', id)], limit=1)
+ if not product:
+ return self.response({'qty': 0, 'sla_date': 'N/A'}, headers=[('Cache-Control', 'max-age=600, private')])
+
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)
+ # 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
+ # product = product_pruchase.product_id
vendor_sla = request.env['vendor.sla'].search([('id_vendor', '=', product_pruchase.vendor_id.id)], limit=1)
slatime = 15
@@ -132,42 +136,45 @@ class Product(controller.Controller):
if qty_available < 1 :
qty_available = 0
- qty = 0
+ # qty = 0
+ qty = qty_available
sla_date = f'{slatime} Hari'
+ if qty_available > 0:
+ sla_date = '1 Hari'
# 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 = '1 Hari'
- elif qty_altama > 0 or qty_vendor > 0:
- qty = total_adem if qty_altama > 0 else total_excell
- sla_date = f'{slatime} Hari'
- else:
- sla_date = f'{slatime} Hari'
- except:
- print('error')
- else:
- if qty_available > 0:
- qty = qty_available
- sla_date = f'1 Hari'
- elif qty_vendor > 0:
- qty = total_excell
- sla_date = f'{slatime} Hari'
+ # 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 = '1 Hari'
+ # elif qty_altama > 0 or qty_vendor > 0:
+ # qty = total_adem if qty_altama > 0 else total_excell
+ # sla_date = f'{slatime} Hari'
+ # else:
+ # sla_date = f'{slatime} Hari'
+ # except:
+ # print('error')
+ # else:
+ # if qty_available > 0:
+ # qty = qty_available
+ # sla_date = f'1 Hari'
+ # elif qty_vendor > 0:
+ # qty = total_excell
+ # sla_date = f'{slatime} Hari'
data = {
'qty': qty,
@@ -245,6 +252,8 @@ class Product(controller.Controller):
[('id', '=', id)], limit=1)
qty_available = product.qty_free_bandengan
+ if qty_available < 1:
+ qty_available = 0
data = {
'qty': qty_available,
diff --git a/indoteknik_api/controllers/api_v1/stock_picking.py b/indoteknik_api/controllers/api_v1/stock_picking.py
index ddbb89ad..94d0035f 100644
--- a/indoteknik_api/controllers/api_v1/stock_picking.py
+++ b/indoteknik_api/controllers/api_v1/stock_picking.py
@@ -1,5 +1,5 @@
from .. import controller
-from odoo import http
+from odoo import http, fields
from odoo.http import request, Response
from pytz import timezone
from datetime import datetime
@@ -8,7 +8,6 @@ import logging
_logger = logging.getLogger(__name__)
-_logger = logging.getLogger(__name__)
class StockPicking(controller.Controller):
prefix = '/api/v1/'
@@ -125,33 +124,87 @@ class StockPicking(controller.Controller):
@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, scanid, **kw):
- sj_document = kw.get('sj_document') if 'sj_document' in kw else None
paket_document = kw.get('paket_document') if 'paket_document' in kw else None
dispatch_document = kw.get('dispatch_document') if 'dispatch_document' in kw else None
+ self_pu = kw.get('self_pu') if 'self_pu' in kw else None
# ===== Cari picking by id / picking_code =====
- picking_data = False
+ picking = False
if scanid.isdigit() and int(scanid) < 2147483646:
- picking_data = request.env['stock.picking'].search([('id', '=', int(scanid))], limit=0)
+ picking = request.env['stock.picking'].search([('id', '=', int(scanid))], limit=0)
+ if not picking:
+ picking = request.env['stock.picking'].search([('picking_code', '=', scanid)], limit=0)
+ if not picking:
+ return self.response(code=403, description='picking not found')
- if not picking_data:
- picking_data = request.env['stock.picking'].search([('picking_code', '=', scanid)], limit=0)
+ # ===== Ambil MULTIPLE SJ dari form: sj_documentations=...&sj_documentations=... =====
+ form = request.httprequest.form or {}
+ sj_list = form.getlist('sj_documentations') # list of base64 strings
- if not picking_data:
- return self.response(code=403, description='picking not found')
+ # fallback: kalau FE kirim single dengan nama yang sama (bukan list)
+ if not sj_list and 'sj_documentations' in kw and kw.get('sj_documentations'):
+ sj_list = [kw.get('sj_documentations')]
- params = {
- 'driver_arrival_date': datetime.utcnow(),
- }
- if sj_document:
- params['sj_documentation'] = sj_document
+ params = {}
if paket_document:
params['paket_documentation'] = paket_document
+ params['driver_arrival_date'] = datetime.utcnow()
if dispatch_document:
params['dispatch_documentation'] = dispatch_document
+ if sj_list and self_pu:
+ params['driver_arrival_date'] = datetime.utcnow()
+
+ if params:
+ picking.write(params)
+
+ if sj_list:
+ Child = request.env['stock.picking.sj.document'].sudo()
+ seq = (picking.sj_documentations[:1].sequence or 10) if picking.sj_documentations else 10
+ for b64 in sj_list:
+ if not b64:
+ continue
+ Child.create({
+ 'picking_id': picking.id,
+ 'sequence': seq,
+ 'image': b64,
+ })
+ seq += 10
+
+ return self.response({'name': picking.name})
+
+ # @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, scanid, **kw):
+ # sj_document = kw.get('sj_document') if 'sj_document' in kw else None
+ # paket_document = kw.get('paket_document') if 'paket_document' in kw else None
+ # dispatch_document = kw.get('dispatch_document') if 'dispatch_document' in kw else None
+ # self_pu= kw.get('self_pu') if 'self_pu' in kw else None
+ #
+ # # ===== Cari picking by id / picking_code =====
+ # picking_data = False
+ # if scanid.isdigit() and int(scanid) < 2147483646:
+ # picking_data = request.env['stock.picking'].search([('id', '=', int(scanid))], limit=0)
+ #
+ # if not picking_data:
+ # picking_data = request.env['stock.picking'].search([('picking_code', '=', scanid)], limit=0)
+ #
+ # if not picking_data:
+ # return self.response(code=403, description='picking not found')
+ #
+ # params = {}
+ # if sj_document:
+ # params['sj_documentation'] = sj_document
+ # if self_pu:
+ # params['driver_arrival_date'] = datetime.utcnow()
+ # if paket_document:
+ # params['paket_documentation'] = paket_document
+ # params['driver_arrival_date'] = datetime.utcnow()
+ # if dispatch_document:
+ # params['dispatch_documentation'] = dispatch_document
+ #
+ # picking_data.write(params)
+ # return self.response({'name': picking_data.name})
- picking_data.write(params)
- return self.response({'name': picking_data.name})
@http.route(prefix + 'webhook/biteship', type='json', auth='public', methods=['POST'], csrf=False)
def update_status_from_biteship(self, **kw):