diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2024-05-20 16:30:43 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2024-05-20 16:30:43 +0700 |
| commit | 92f33f2851a76bf391c0cfdee8fc0d4047e22a1d (patch) | |
| tree | db1dd312b0c8e770f3eb05762bdbfae5010468d0 /indoteknik_custom/models/ged.py | |
| parent | 8cb1d5045542d120a65a610b6f9bb4b99c43adf4 (diff) | |
sync dunning to ged
Diffstat (limited to 'indoteknik_custom/models/ged.py')
| -rw-r--r-- | indoteknik_custom/models/ged.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py index 53bbe184..4502ce0b 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -8,6 +8,11 @@ import json #dev # url_token = 'https://stagging-api.ged.co.id/api/GetToken' # url_tracking = 'https://stagging-api.ged.co.id/api/TrackingAwb' +# username = 'mandiri@gmail.co.id' +# password = 'nPcWh8Up75ai5CW' +# x_ged_key = 'Mandiriind' +# x_ged_password = 'M4ndir1ind0n3si4ap1' + #production url_token = 'https://gedapi.ged.co.id/api/GetToken' url_tracking = 'https://gedapi.ged.co.id/api/TrackingAwb' @@ -75,8 +80,7 @@ class GedTrackingLine(models.Model): class GedApi(models.Model): _name = 'ged.api' - def get_token(self): - #TODO check if have old active token or not + def _get_token(self): headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', @@ -107,8 +111,18 @@ class GedApi(models.Model): self.env['token.storage'].create([param]) return token - def get_tracking_awb(self): - token = self.get_token() + def get_tracking_awb(self, dunning_run): + current_time = datetime.now() + current_time = current_time.strftime('%Y-%m-%d %H:%M:%S') + query = [('app_id', '=', 1), ('expired_date', '>', current_time)] + token_data = self.env['token.storage'].search(query, order='expired_date desc', limit=1) + if not token_data: + token_data = self._get_token() + token = token_data + else: + token = token_data.access_token + + # token = self.get_token() headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', @@ -118,7 +132,7 @@ class GedApi(models.Model): } json_data = { 'data': { - 'awb': 19138131 + 'awb': dunning_run.resi_tukar_faktur or 19138131 } } response = requests.post(url_tracking, headers=headers, json=json_data) @@ -155,7 +169,7 @@ class GedApi(models.Model): last_location = last_status['location'] last_description = last_status['description'] last_status_detail = last_status['status_detail'] - last_status = last_status['status'] + header_last_status = last_status = last_status['status'] param_header = { 'status': status, @@ -213,3 +227,5 @@ class GedApi(models.Model): } self.env['ged.tracking.line'].create(param_line) + return header_last_status + |
