diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-07-24 08:55:26 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-07-24 08:55:26 +0700 |
| commit | 968f63a411f8cc9e190a261123e47604ce54c2b2 (patch) | |
| tree | 60ad4bb324ccc67ab2e9045def163a413675e968 | |
| parent | 2a1179b22cd1b8ee9e3e31c157821dbbeb66195f (diff) | |
fix bug and refactor api product sla
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 21 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/models/stock_vendor.py | 9 |
3 files changed, 13 insertions, 19 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 587773ee..7ec6459b 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -13,32 +13,35 @@ class Product(controller.Controller): prefix = '/api/v1/' @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) - stock_vendor = request.env['stock.vendor'].search([('product_variant_id', '=', id)], limit=1) - - stock_vendor = stock_vendor.get_stock_updated_last_7_days() + 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_onhand_bandengan qty = 0 sla_date = '-' - - 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 + # 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 if qty_available > 0: qty = qty_available + total_adem + total_excell sla_date = '1 Hari' diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 1a83b702..7abdf1c1 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -221,7 +221,7 @@ class ProductTemplate(models.Model): datas = json.loads(response.text)['data'] qty = 0 for data in datas: - availability = int(data['availability']) # Mengonversi ke tipe data int + availability = float(data['availability']) # Mengonversi ke tipe data int qty += availability # Mengakumulasi qty dari setiap data return qty diff --git a/indoteknik_custom/models/stock_vendor.py b/indoteknik_custom/models/stock_vendor.py index dcbeb399..f214a5e1 100755 --- a/indoteknik_custom/models/stock_vendor.py +++ b/indoteknik_custom/models/stock_vendor.py @@ -17,15 +17,6 @@ class StockVendor(models.Model): ('done', 'Done') ], string="Cache Reset") - def get_stock_updated_last_7_days(self): - date_7_days_ago = datetime.now() - timedelta(days=7) - - stocks = self.search([ - ('write_date', '>=', date_7_days_ago.strftime("%Y-%m-%d %H:%M:%S")) - ], limit=1) - - return stocks - def cache_reset(self): stocks = self.env['stock.vendor'].search([ ('cache_reset_status', '=', 'reset'), |
