summaryrefslogtreecommitdiff
path: root/indoteknik_custom
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2024-05-20 16:30:43 +0700
committerstephanchrst <stephanchrst@gmail.com>2024-05-20 16:30:43 +0700
commit92f33f2851a76bf391c0cfdee8fc0d4047e22a1d (patch)
treedb1dd312b0c8e770f3eb05762bdbfae5010468d0 /indoteknik_custom
parent8cb1d5045542d120a65a610b6f9bb4b99c43adf4 (diff)
sync dunning to ged
Diffstat (limited to 'indoteknik_custom')
-rw-r--r--indoteknik_custom/models/dunning_run.py29
-rw-r--r--indoteknik_custom/models/ged.py28
2 files changed, 51 insertions, 6 deletions
diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py
index abfd68be..b5b8acb5 100644
--- a/indoteknik_custom/models/dunning_run.py
+++ b/indoteknik_custom/models/dunning_run.py
@@ -3,6 +3,7 @@ from odoo.exceptions import AccessError, UserError, ValidationError
from datetime import timedelta
import logging
+
_logger = logging.getLogger(__name__)
@@ -25,6 +26,7 @@ class DunningRun(models.Model):
shipper_faktur_id = fields.Many2one('delivery.carrier', string='Shipper Faktur')
is_validated = fields.Boolean(string='Validated')
notification = fields.Char(string='Notification')
+ last_status_awb = fields.Char(string='Last Status AWB')
def copy_date_faktur(self):
if not self.is_validated:
@@ -105,6 +107,33 @@ class DunningRun(models.Model):
result = super(DunningRun, self).create(vals)
return result
+ def _get_tracking_history(self, test_awb_number):
+ if test_awb_number:
+ query = [
+ ('last_status', '!=', 'POD Return'),
+ ('resi_tukar_faktur', '=', test_awb_number),
+ ('shipper_faktur_id', '=', 123)
+ ]
+ else:
+ query = [
+ ('last_status', '!=', 'POD Return'),
+ ('resi_tukar_faktur', '!=', False),
+ ('shipper_faktur_id', '=', 123)
+ ]
+ dunnings = self.env['dunning.run'].search(query)
+
+ for dunning in dunnings:
+ current_tracking = self.env['ged.tracking'].search([('awb_no', '=', dunning.resi_tukar_faktur)], limit=1)
+ if current_tracking:
+ current_tracking.unlink()
+ else:
+ ged_api = self.env['ged.api']
+ last_status = ged_api.get_tracking_awb(dunning.id)
+ if not last_status:
+ dunning.last_status_awb = last_status
+ return
+
+
class DunningRunLine(models.Model):
_name = 'dunning.run.line'
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
+