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_custom/models/product_template.py | |
| parent | 577fe5a01f3b782a2a441ad55f3cc721ba2e212c (diff) | |
api sla website
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 5fbac2e3..8247cd7e 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -196,7 +196,7 @@ class ProductTemplate(models.Model): qty = self._get_stock_altama() print(qty) - def _get_stock_altama(self): + def get_stock_altama(self, item_code): current_time = datetime.now() current_time = current_time.strftime('%Y-%m-%d %H:%M:%S') query = [('source', '=', 'altama'), ('expired_date', '>', current_time)] @@ -215,13 +215,16 @@ class ProductTemplate(models.Model): } json_data = { 'type_search': 'Item_code', - 'search_key':['RSG100-3'], + 'search_key':[item_code], } response = requests.post(url, headers=headers, json=json_data) datas = json.loads(response.text)['data'] + qty = 0 for data in datas: - qty = data['availability'] - return qty or 0 + availability = int(data['availability']) # Mengonversi ke tipe data int + qty += availability # Mengakumulasi qty dari setiap data + + return qty def _get_new_token_altama(self): url = "https://kc.altama.co.id/realms/altama/protocol/openid-connect/token" |
