summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2024-05-20 15:08:43 +0700
committerstephanchrst <stephanchrst@gmail.com>2024-05-20 15:08:43 +0700
commit49566a406160fca5cef44f864c228ae2e8e3f1fb (patch)
treeface02a49fc95b4b9c24e5e9ce05c46c4e6dee46
parent9c7e20e61ccc8509ff3d6a658505d5d97f6219d5 (diff)
new branch api ged
-rwxr-xr-xindoteknik_custom/__manifest__.py1
-rwxr-xr-xindoteknik_custom/models/__init__.py2
-rw-r--r--indoteknik_custom/models/external_api.py21
-rw-r--r--indoteknik_custom/models/ged.py194
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv6
-rw-r--r--indoteknik_custom/views/apps_stored.xml45
6 files changed, 268 insertions, 1 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index f1f3f9b6..c3c77d4e 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -122,6 +122,7 @@
'views/stock_quant.xml',
'views/purchasing_job_state.xml',
'views/res_partner_site.xml',
+ 'views/apps_stored.xml',
'report/report.xml',
'report/report_banner_banner.xml',
'report/report_banner_banner2.xml',
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 160d2af3..33aa0784 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -111,3 +111,5 @@ from . import report_stock_forecasted
from . import web_logging
from . import sales_order_fullfillment
from . import res_partner_site
+from . import external_api
+from . import ged
diff --git a/indoteknik_custom/models/external_api.py b/indoteknik_custom/models/external_api.py
new file mode 100644
index 00000000..ff7281c5
--- /dev/null
+++ b/indoteknik_custom/models/external_api.py
@@ -0,0 +1,21 @@
+from odoo import fields, models, api
+import requests
+import urllib.parse
+from odoo.exceptions import UserError
+import json
+
+
+class AppsStored(models.Model):
+ _name = 'apps.stored'
+
+ app_name = fields.Char(string='App Name')
+ description = fields.Char(string='Description')
+
+
+class TokenStorage(models.Model):
+ # _name = 'token.stored'
+ _inherit = 'token.storage'
+
+ app_id = fields.Many2one('apps.stored', string='App')
+ messages = fields.Char(string='Messages')
+ status = fields.Char(string='Status')
diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py
new file mode 100644
index 00000000..832fb023
--- /dev/null
+++ b/indoteknik_custom/models/ged.py
@@ -0,0 +1,194 @@
+from odoo import models, fields
+from datetime import datetime, timedelta
+import requests
+import urllib.parse
+from odoo.exceptions import UserError
+import json
+
+#dev
+# url_token = 'https://stagging-api.ged.co.id/api/GetToken'
+# url_tracking = 'https://stagging-api.ged.co.id/api/TrackingAwb'
+#production
+url_token = 'https://gedapi.ged.co.id/api/GetToken'
+url_tracking = 'https://gedapi.ged.co.id/api/TrackingAwb'
+username = 'stephan@indoteknik.co.id'
+password = 'faCE2HFFKdzhvPW'
+x_ged_key = 'Indoteknikdotcom'
+x_ged_password = 'Ind0t3kn1kdotc0m4p1'
+
+class GedTracking(models.Model):
+ _name = 'ged.tracking'
+
+ status = fields.Char(string='Status')
+ messages = fields.Char(string='Messages')
+ awb_no = fields.Char(string='AWB No')
+ reff_no = fields.Char(string='Reff No')
+ consignee_name = fields.Char(string='Consignee Name')
+ consignee_contact = fields.Char(string='Consignee Contact')
+ consignee_phone = fields.Char(string='Consignee Phone')
+ consignee_address = fields.Char(string='Consignee Address')
+ moda = fields.Char(string='Moda')
+ service = fields.Char(string='Service')
+ package = fields.Char(string='Package')
+ height = fields.Char(string='Height')
+ width = fields.Char(string='Width')
+ length = fields.Char(string='Length')
+ coli = fields.Char(string='Coli')
+ kg = fields.Char(string='KG')
+ origin = fields.Char(string='Origin')
+ destination = fields.Char(string='Destination')
+ last_user_input = fields.Char(string='Last User Input')
+ last_created_at = fields.Char(string='Last Created At')
+ last_location = fields.Char(string='Last Location')
+ last_description = fields.Char(string='Last Description')
+ last_status_detail = fields.Char(string='Last Status Detail')
+ last_status = fields.Char(string='Last Status')
+
+
+class GedTrackingLine(models.Model):
+ _name = 'ged.tracking.line'
+
+ ged_tracking_id = fields.Many2one('ged.tracking', string='Ged Tracking ID', required=True, ondelete='cascade',
+ index=True, copy=False)
+ user_input = fields.Char(string='User Input')
+ created_at = fields.Char(string='Created At')
+ location = fields.Char(string='Location')
+ description = fields.Char(string='Description')
+ status_detail = fields.Char(string='Status Detail')
+ status = fields.Char(string='Status')
+ receiver_name = fields.Char(string='Receiver Name')
+ receiver_relationship = fields.Char(string='Receiver Relationship')
+ photo_pod = fields.Char(string='Photo POD')
+ photo_signature = fields.Char(string='Photo Signature')
+ photo_location = fields.Char(string='Photo Location')
+ photo_receiver = fields.Char(string='Photo Receiver')
+ gps = fields.Char(string='GPS')
+
+
+class GedApi(models.Model):
+ _name = 'ged.api'
+
+ def get_token(self):
+ #TODO check if have old active token or not
+ headers = {
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json',
+ }
+ json_data = {
+ 'data': {
+ 'email': username,
+ 'password': password,
+ },
+ }
+ response = requests.post(url_token, headers=headers, json=json_data)
+
+ status = response.json()['status']
+ messages = response.json()['messages']
+ token = response.json()['token']
+ expired = response.json()['expired']
+ date_expired = datetime.strptime(expired, '%y-%m-%d %H:%M:%S')
+ date_expired = date_expired.strftime('%Y-%m-%d %H:%M:%S')
+
+ param = {
+ "status": status,
+ "messages": messages,
+ "access_token": token,
+ "expired_date": date_expired,
+ "app_id": 1,
+ "source": "GED"
+ }
+ self.env['token.storage'].create([param])
+ return token
+
+ def get_tracking_awb(self):
+ token = self.get_token()
+ headers = {
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json',
+ 'X-Ged-Key': x_ged_key,
+ 'X-Ged-Password': x_ged_password,
+ 'Authorization': 'Bearer '+token
+ }
+ json_data = {
+ 'data': {
+ 'awb': 19138131
+ }
+ }
+ response = requests.post(url_tracking, headers=headers, json=json_data)
+ info_awb = response.json()['infoawb']
+ last_status = response.json()['laststatus']
+
+ status = response.json()['status']
+ messages = response.json()['messages']
+ awb_no = info_awb['awb_no']
+ reff_no = info_awb['reff_no']
+ consignee_name = info_awb['consignee_name']
+ consignee_contact = info_awb['consignee_contact']
+ consignee_phone = info_awb['consignee_phone']
+ consignee_address = info_awb['consignee_address']
+ moda = info_awb['moda']
+ service = info_awb['service']
+ package = info_awb['package']
+ height = info_awb['height']
+ width = info_awb['width']
+ length = info_awb['length']
+ coli = info_awb['coli']
+ kg = info_awb['kg']
+ origin = info_awb['origin']
+ destination = info_awb['destination']
+ last_user_input = last_status['user_input']
+ last_created_at = last_status['created_at']
+ last_location = last_status['location']
+ last_description = last_status['description']
+ last_status_detail = last_status['status_detail']
+ last_status = last_status['status']
+
+ param_header = {
+ 'status': status,
+ 'messages': messages,
+ 'awb_no': awb_no,
+ 'reff_no': reff_no,
+ 'consignee_name': consignee_name,
+ 'consignee_contact': consignee_contact,
+ 'consignee_phone': consignee_phone,
+ 'consignee_address': consignee_address,
+ 'moda': moda,
+ 'service': service,
+ 'package': package,
+ 'height': height,
+ 'width': width,
+ 'length': length,
+ 'coli': coli,
+ 'kg': kg,
+ 'origin': origin,
+ 'destination': destination,
+ 'last_user_input': last_user_input,
+ 'last_created_at': last_created_at,
+ 'last_location': last_location,
+ 'last_description': last_description,
+ 'last_status_detail': last_status_detail,
+ 'last_status': last_status
+ }
+
+ ged_tracking = self.env['ged.tracking'].create(param_header)
+
+ for line in response.json()['data']:
+ ged_tracking_id = ged_tracking.id
+ user_input = line['user_input']
+ created_at = line['created_at']
+ location = line['location']
+ description = line['description']
+ status_detail = line['status_detail']
+ status = line['status']
+
+ param_line = {
+ 'ged_tracking_id': ged_tracking_id,
+ 'user_input': user_input,
+ 'created_at': created_at,
+ 'location': location,
+ 'description': description,
+ 'status_detail': status_detail,
+ 'status': status
+ }
+ self.env['ged.tracking.line'].create(param_line)
+
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index f03e0118..ae91a3da 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -110,4 +110,8 @@ access_cust_commision,access.cust.commision,model_cust_commision,,1,1,1,1
access_report_stock_report_product_product_replenishment,access.report.stock.report_product_product_replenishment,model_report_stock_report_product_product_replenishment,,1,1,1,1
access_sales_order_fullfillment,access.sales.order.fullfillment,model_sales_order_fullfillment,,1,1,1,1
access_purchasing_job_state,access.purchasing.job.state,model_purchasing_job_state,,1,1,1,1
-access_res_partner_site,access.res_partner_site,model_res_partner_site,,1,1,1,1 \ No newline at end of file
+access_res_partner_site,access.res_partner_site,model_res_partner_site,,1,1,1,1
+access_apps_stored,access.apps.stored,model_apps_stored,,1,1,1,1
+access_ged_api,access.ged.api,model_ged_api,,1,1,1,1
+access_ged_tracking,access.ged.tracking,model_ged_tracking,,1,1,1,1
+access_ged_tracking_line,access.ged.tracking.line,model_ged_tracking_line,,1,1,1,1
diff --git a/indoteknik_custom/views/apps_stored.xml b/indoteknik_custom/views/apps_stored.xml
new file mode 100644
index 00000000..5472dc20
--- /dev/null
+++ b/indoteknik_custom/views/apps_stored.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+ <record id="apps_stored_tree" model="ir.ui.view">
+ <field name="name">apps.stored.tree</field>
+ <field name="model">apps.stored</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="app_name"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="apps_stored_form" model="ir.ui.view">
+ <field name="name">apps.stored.form</field>
+ <field name="model">apps.stored</field>
+ <field name="arch" type="xml">
+ <form>
+ <sheet string="Apps Stored">
+ <div class="oe_button_box" name="button_box"/>
+ <group>
+ <group>
+ <field name="app_name"/>
+ <field name="description"/>
+ </group>
+ </group>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="apps_stored_action" model="ir.actions.act_window">
+ <field name="name">Apps Stored</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">apps.stored</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem id="menu_apps_stored"
+ name="Apps Stored"
+ action="apps_stored_action"
+ parent="contacts.res_partner_menu_config"
+ sequence="101"
+ />
+
+</odoo> \ No newline at end of file