diff options
| author | FIN-IT_AndriFP <it@fixcomart.co.id> | 2025-10-24 17:00:07 +0700 |
|---|---|---|
| committer | FIN-IT_AndriFP <it@fixcomart.co.id> | 2025-10-24 17:00:07 +0700 |
| commit | b7658e977fb0697345fe34f88e6d0c312dc9bf4b (patch) | |
| tree | e21a577bcea5638c731d20cfc1efcef59dbd2058 | |
| parent | a45c6abe62390a45164ba27608f348954066c935 (diff) | |
(andri) fix
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 85 |
1 files changed, 46 insertions, 39 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index e97a7ff8..0eba92b4 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, |
