diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-07-01 11:30:17 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-07-01 11:30:17 +0700 |
| commit | fde265040065d233a0b7eee277defb3c472575a2 (patch) | |
| tree | 1ff4c348f2bbfc9de0ede5376215227222bf296c /indoteknik_api/controllers/api_v1 | |
| parent | 577fe5a01f3b782a2a441ad55f3cc721ba2e212c (diff) | |
api sla website
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 54b039c7..8dea4c28 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -4,6 +4,7 @@ from odoo.http import request from datetime import datetime, timedelta import ast import logging +import math _logger = logging.getLogger(__name__) @@ -11,6 +12,51 @@ _logger = logging.getLogger(__name__) class Product(controller.Controller): prefix = '/api/v1/' + @http.route(prefix + 'product/template/stock/<id>', auth='public', methods=['GET', 'OPTIONS']) + def get_product_template_stock_by_id(self, **kw): + id = kw.get('id') + stock_location_id = 57 # Ubah dengan location_id yang diinginkan + template = request.env['product.product'].search([('id', '=', id)], limit=1) + stock = template.qty_available + item_code = template.default_code + qty_altama = request.env['product.template'].get_stock_altama(item_code) + qty_altama -= int(qty_altama * 0.1) + rounded_qty_altama = math.ceil(float(qty_altama)) + qty_b2b_altama = rounded_qty_altama + + qty = 0 + sla_date = '-' + qty_available = 0 + + for stock in template.stock_quant_ids: + if stock.location_id.id == 57: + qty_available += stock.quantity + + if qty_available == 0: + if qty_b2b_altama > 0: + qty = qty_b2b_altama + sla_date = '2-4 Hari' + else: + qty = 0 + sla_date = 'Indent' + elif qty_available > 10: + if template.x_manufacture.id == 10 or template.x_manufacture.id == 122 or template.x_manufacture.id == 89: + qty = qty_available + qty_b2b_altama + else: + qty = qty_available + sla_date = '1 Hari' + elif qty_available < 10: + qty = 0 + sla_date = '-' + + data = { + 'qty': qty, + 'sla_date': sla_date, + } + + return self.response(data, headers=[('Cache-Control', 'max-age=180, private')]) + + @http.route(prefix + 'product/template/price/<id>', auth='public', methods=['GET', 'OPTIONS']) def get_product_template_price_by_id(self, **kw): if not self.authenticate(): @@ -54,7 +100,7 @@ class Product(controller.Controller): if not self.authenticate(): return self.response(code=401, description='Unauthorized') id = kw.get('id') - partner_id = int(kw.get('partner_id', 0)) + partner_id = int(kw.get('partner_id', 0)) product_product = request.env['product.product'].search([('id', '=', id)], limit=1) data = { @@ -90,7 +136,7 @@ class Product(controller.Controller): # ('create_date', '>=', delta_time), ] new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=limit_new_products) - brands = [] + brands = [] for product in new_products: brands.append(product.x_manufacture) brands = list(dict.fromkeys(brands)) |
