From ad804db879d8cf288543e6bb045ff597fe025b34 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 17 May 2024 13:43:11 +0700 Subject: deactivate function onchance on stock picking --- indoteknik_custom/models/stock_picking.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 22aceaf4..de234067 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -86,10 +86,10 @@ class StockPicking(models.Model): date_availability = fields.Datetime(string="Date Availability", copy=False, tracking=True) sale_order = fields.Char(string='Matches SO', copy=False) - @api.onchange('carrier_id') - def constrains_carrier_id(self): - if not self.env.user.is_logistic_approver: - raise UserError('Hanya Logistic yang bisa mengubah shipping method') + # @api.onchange('carrier_id') + # def constrains_carrier_id(self): + # if not self.env.user.is_logistic_approver: + # raise UserError('Hanya Logistic yang bisa mengubah shipping method') def do_unreserve(self): res = super(StockPicking, self).do_unreserve() -- cgit v1.2.3 From ea8cad6bf8158bee8d074cb5c493155a87c9b9fe Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 17 May 2024 13:53:50 +0700 Subject: fix function onchange on stock picking --- indoteknik_custom/models/stock_picking.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index de234067..62d86911 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -86,10 +86,11 @@ class StockPicking(models.Model): date_availability = fields.Datetime(string="Date Availability", copy=False, tracking=True) sale_order = fields.Char(string='Matches SO', copy=False) - # @api.onchange('carrier_id') - # def constrains_carrier_id(self): - # if not self.env.user.is_logistic_approver: - # raise UserError('Hanya Logistic yang bisa mengubah shipping method') + @api.onchange('carrier_id') + def constrains_carrier_id(self): + if self.carrier_id: + if not self.env.user.is_logistic_approver: + raise UserError('Hanya Logistic yang bisa mengubah shipping method') def do_unreserve(self): res = super(StockPicking, self).do_unreserve() -- cgit v1.2.3 From 9c7e20e61ccc8509ff3d6a658505d5d97f6219d5 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 17 May 2024 15:29:03 +0700 Subject: comment code api get sale order --- indoteknik_api/controllers/api_v1/sale_order.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index 948ecd03..8d3d0218 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -52,7 +52,6 @@ class SaleOrder(controller.Controller): params = self.get_request_params(kw, { 'partner_id': ['number'], 'name': [], - 'site': [], 'limit': ['default:0', 'number'], 'offset': ['default:0', 'number'], 'context': [] @@ -81,11 +80,11 @@ class SaleOrder(controller.Controller): ('partner_purchase_order_name', 'ilike', '%' + name + '%') ] - if params['value']['site']: - site = params['value']['site'].replace(' ', '%') - domain += [ - ('partner_id.site_id.name', 'ilike', '%' + site + '%') - ] + # if params['value']['site']: + # site = params['value']['site'].replace(' ', '%') + # domain += [ + # ('partner_id.site_id.name', 'ilike', '%' + site + '%') + # ] sale_orders = request.env['sale.order'].search( domain, offset=offset, limit=limit) -- cgit v1.2.3 From 49566a406160fca5cef44f864c228ae2e8e3f1fb Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 20 May 2024 15:08:43 +0700 Subject: new branch api ged --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 2 + indoteknik_custom/models/external_api.py | 21 +++ indoteknik_custom/models/ged.py | 194 +++++++++++++++++++++++++ indoteknik_custom/security/ir.model.access.csv | 6 +- indoteknik_custom/views/apps_stored.xml | 45 ++++++ 6 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/external_api.py create mode 100644 indoteknik_custom/models/ged.py create mode 100644 indoteknik_custom/views/apps_stored.xml 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 @@ + + + + apps.stored.tree + apps.stored + + + + + + + + + apps.stored.form + apps.stored + +
+ +
+ + + + + + + + + + + + + Apps Stored + ir.actions.act_window + apps.stored + tree,form + + + + + \ No newline at end of file -- cgit v1.2.3 From 8cb1d5045542d120a65a610b6f9bb4b99c43adf4 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 20 May 2024 15:43:01 +0700 Subject: add column ged api --- indoteknik_custom/models/ged.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py index 832fb023..53bbe184 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -37,6 +37,13 @@ class GedTracking(models.Model): kg = fields.Char(string='KG') origin = fields.Char(string='Origin') destination = fields.Char(string='Destination') + receiver_name = fields.Char(string='Receiver Name') + receiver_relationship = fields.Char(string='Receiver Relationship') + delivered_date = fields.Char(string='Delivered Date') + 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') 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') @@ -136,6 +143,13 @@ class GedApi(models.Model): kg = info_awb['kg'] origin = info_awb['origin'] destination = info_awb['destination'] + receiver_name = info_awb['receiver_name'] + receiver_relationship = info_awb['receiver_relationship'] + delivered_date = info_awb['delivered_date'] + photo_pod = info_awb['photo_pod'] + photo_signature = info_awb['photo_signature'] + photo_location = info_awb['photo_location'] + photo_receiver = info_awb['photo_receiver'] last_user_input = last_status['user_input'] last_created_at = last_status['created_at'] last_location = last_status['location'] @@ -162,6 +176,13 @@ class GedApi(models.Model): 'kg': kg, 'origin': origin, 'destination': destination, + 'receiver_name': receiver_name, + 'receiver_relationship': receiver_relationship, + 'delivered_date': delivered_date, + 'photo_pod': photo_pod, + 'photo_signature': photo_signature, + 'photo_location': photo_location, + 'photo_receiver': photo_receiver, 'last_user_input': last_user_input, 'last_created_at': last_created_at, 'last_location': last_location, -- cgit v1.2.3 From 92f33f2851a76bf391c0cfdee8fc0d4047e22a1d Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 20 May 2024 16:30:43 +0700 Subject: sync dunning to ged --- indoteknik_custom/models/dunning_run.py | 29 +++++++++++++++++++++++++++++ indoteknik_custom/models/ged.py | 28 ++++++++++++++++++++++------ 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 + -- cgit v1.2.3 From b88662f880bfcc03d8de4c4e272054a35acf1e4a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 20 May 2024 16:35:38 +0700 Subject: refactor code dunning run to ged class --- indoteknik_custom/models/dunning_run.py | 27 --------------------------- indoteknik_custom/models/ged.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index b5b8acb5..8f17fea6 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -107,33 +107,6 @@ 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 4502ce0b..b63caf86 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -229,3 +229,32 @@ class GedApi(models.Model): return header_last_status + +class DunningRunGed(models.Model): + _inherit = 'dunning.run' + + 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 -- cgit v1.2.3 From 777380f7346afc91189502c7f7943ce4b7b2e7f1 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 20 May 2024 16:36:23 +0700 Subject: revert column in dunning run related with ged --- indoteknik_custom/models/dunning_run.py | 1 - indoteknik_custom/models/ged.py | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index 8f17fea6..4e04c03c 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -26,7 +26,6 @@ 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: diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py index b63caf86..10409130 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -233,6 +233,8 @@ class GedApi(models.Model): class DunningRunGed(models.Model): _inherit = 'dunning.run' + last_status_awb = fields.Char(string='Last Status AWB') + def _get_tracking_history(self, test_awb_number): if test_awb_number: query = [ -- cgit v1.2.3 From b75112a16554ea97fce7e8c1f23ffe6793ec7c94 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 20 May 2024 16:41:40 +0700 Subject: chnage return of ged api --- indoteknik_custom/models/ged.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py index 10409130..83b07568 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -227,7 +227,7 @@ class GedApi(models.Model): } self.env['ged.tracking.line'].create(param_line) - return header_last_status + return ged_tracking class DunningRunGed(models.Model): @@ -256,7 +256,7 @@ class DunningRunGed(models.Model): 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 + ged_tracking = ged_api.get_tracking_awb(dunning.id) + if ged_tracking: + dunning.last_status_awb = ged_tracking.last_status return -- cgit v1.2.3 From 92413dbeda6eebc85731536dd698bb155b09d7df Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 20 May 2024 17:05:11 +0700 Subject: bug fix --- indoteknik_custom/models/ged.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py index 83b07568..9e6facc6 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -238,13 +238,13 @@ class DunningRunGed(models.Model): def _get_tracking_history(self, test_awb_number): if test_awb_number: query = [ - ('last_status', '!=', 'POD Return'), + ('last_status_awb', '!=', 'POD Return'), ('resi_tukar_faktur', '=', test_awb_number), ('shipper_faktur_id', '=', 123) ] else: query = [ - ('last_status', '!=', 'POD Return'), + ('last_status_awb', '!=', 'POD Return'), ('resi_tukar_faktur', '!=', False), ('shipper_faktur_id', '=', 123) ] @@ -254,9 +254,9 @@ class DunningRunGed(models.Model): 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'] - ged_tracking = ged_api.get_tracking_awb(dunning.id) - if ged_tracking: - dunning.last_status_awb = ged_tracking.last_status + # else: + ged_api = self.env['ged.api'] + ged_tracking = ged_api.get_tracking_awb(dunning.id) + if ged_tracking: + dunning.last_status_awb = ged_tracking.last_status return -- cgit v1.2.3 From 8da2a7fe0de6f0abe4e35831e5e5560c20b5b627 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 21 May 2024 09:21:33 +0700 Subject: bug fix total margin so, forgot deduction of delivery amount --- indoteknik_custom/models/ged.py | 26 +++++++++++++------------- indoteknik_custom/models/sale_order.py | 7 ++++++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py index 9e6facc6..9ca426af 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -6,20 +6,20 @@ 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' -# username = 'mandiri@gmail.co.id' -# password = 'nPcWh8Up75ai5CW' -# x_ged_key = 'Mandiriind' -# x_ged_password = 'M4ndir1ind0n3si4ap1' +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' -username = 'stephan@indoteknik.co.id' -password = 'faCE2HFFKdzhvPW' -x_ged_key = 'Indoteknikdotcom' -x_ged_password = 'Ind0t3kn1kdotc0m4p1' +# 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' @@ -245,7 +245,7 @@ class DunningRunGed(models.Model): else: query = [ ('last_status_awb', '!=', 'POD Return'), - ('resi_tukar_faktur', '!=', False), + ('resi_tukar_faktur', '=', False), ('shipper_faktur_id', '=', 123) ] dunnings = self.env['dunning.run'].search(query) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index aa34b0f4..fbb5e7a2 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -582,7 +582,12 @@ class SaleOrder(models.Model): if order.amount_untaxed == 0: order.total_percent_margin = 0 continue - order.total_percent_margin = round((order.total_margin / order.amount_untaxed) * 100, 2) + if order.shipping_cost_covered == 'indoteknik': + delivery_amt = order.delivery_amt + else: + delivery_amt = 0 + order.total_percent_margin = round((order.total_margin / (order.amount_untaxed-delivery_amt)) * 100, 2) + # order.total_percent_margin = round((order.total_margin / (order.amount_untaxed)) * 100, 2) @api.onchange('sales_tax_id') def onchange_sales_tax_id(self): -- cgit v1.2.3 From d6fea32f48e1214768cb56a7f27f3f3bf309e29c Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 21 May 2024 10:18:32 +0700 Subject: dont allow copy field delivery amount --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index fbb5e7a2..d246f37f 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -20,7 +20,7 @@ class SaleOrder(models.Model): ], string='Approval Status', readonly=True, copy=False, index=True, tracking=3) carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method', tracking=3) have_visit_service = fields.Boolean(string='Have Visit Service', compute='_have_visit_service', help='To compute is customer get visit service') - delivery_amt = fields.Float('Delivery Amt') + delivery_amt = fields.Float(string='Delivery Amt', copy=False) shipping_cost_covered = fields.Selection([ ('indoteknik', 'Indoteknik'), ('customer', 'Customer') -- cgit v1.2.3 From 337a3347c50637b059655e2feaff5029ecaba3cb Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 21 May 2024 10:47:42 +0700 Subject: fix error parsing parameter in API GED --- indoteknik_custom/models/ged.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py index 9ca426af..9a8a6dcc 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -6,20 +6,20 @@ 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' -username = 'mandiri@gmail.co.id' -password = 'nPcWh8Up75ai5CW' -x_ged_key = 'Mandiriind' -x_ged_password = 'M4ndir1ind0n3si4ap1' +# 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' -# username = 'stephan@indoteknik.co.id' -# password = 'faCE2HFFKdzhvPW' -# x_ged_key = 'Indoteknikdotcom' -# x_ged_password = 'Ind0t3kn1kdotc0m4p1' +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' @@ -132,7 +132,7 @@ class GedApi(models.Model): } json_data = { 'data': { - 'awb': dunning_run.resi_tukar_faktur or 19138131 + 'awb': dunning_run.resi_tukar_faktur } } response = requests.post(url_tracking, headers=headers, json=json_data) @@ -169,7 +169,7 @@ class GedApi(models.Model): last_location = last_status['location'] last_description = last_status['description'] last_status_detail = last_status['status_detail'] - header_last_status = last_status = last_status['status'] + # header_last_status = last_status = last_status['status'] param_header = { 'status': status, @@ -256,7 +256,9 @@ class DunningRunGed(models.Model): current_tracking.unlink() # else: ged_api = self.env['ged.api'] - ged_tracking = ged_api.get_tracking_awb(dunning.id) + ged_tracking = ged_api.get_tracking_awb(dunning) if ged_tracking: dunning.last_status_awb = ged_tracking.last_status + if ged_tracking.last_status == 'POD Return': + dunning.copy_date_faktur() return -- cgit v1.2.3 From d9978ad05ab9a709467070fc6770af077cb38848 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 21 May 2024 10:51:24 +0700 Subject: copy date terima faktur --- indoteknik_custom/models/ged.py | 1 + 1 file changed, 1 insertion(+) diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py index 9a8a6dcc..c380088b 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -260,5 +260,6 @@ class DunningRunGed(models.Model): if ged_tracking: dunning.last_status_awb = ged_tracking.last_status if ged_tracking.last_status == 'POD Return': + dunning.date_terima_tukar_faktur = ged_tracking.delivered_date dunning.copy_date_faktur() return -- cgit v1.2.3 From f43c3abd858b5bac2ec920e553bc6566845d2a08 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 21 May 2024 10:53:34 +0700 Subject: add validation while query dunning run --- indoteknik_custom/models/ged.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py index c380088b..9b949687 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -246,7 +246,8 @@ class DunningRunGed(models.Model): query = [ ('last_status_awb', '!=', 'POD Return'), ('resi_tukar_faktur', '=', False), - ('shipper_faktur_id', '=', 123) + ('shipper_faktur_id', '=', 123), + ('date_terima_tukar_faktur', '=', False) ] dunnings = self.env['dunning.run'].search(query) -- cgit v1.2.3 From 3c43dad74ebb3feef42ddb871a794ea1763e7008 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 21 May 2024 11:00:22 +0700 Subject: fix wrong status in dunning run --- indoteknik_custom/models/ged.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py index 9b949687..5de47a6e 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -169,7 +169,7 @@ class GedApi(models.Model): last_location = last_status['location'] last_description = last_status['description'] last_status_detail = last_status['status_detail'] - # header_last_status = last_status = last_status['status'] + header_last_status = last_status['status'] param_header = { 'status': status, @@ -202,7 +202,7 @@ class GedApi(models.Model): 'last_location': last_location, 'last_description': last_description, 'last_status_detail': last_status_detail, - 'last_status': last_status + 'last_status': header_last_status } ged_tracking = self.env['ged.tracking'].create(param_header) -- cgit v1.2.3 From b4448913dc446840c21d2403a58cd7edcc13be4a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 21 May 2024 11:47:03 +0700 Subject: add view of ged tracking --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/ged.py | 18 +++- indoteknik_custom/security/ir.model.access.csv | 1 + indoteknik_custom/views/ged_tracking.xml | 117 +++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/views/ged_tracking.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index c3c77d4e..68695b0e 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -123,6 +123,7 @@ 'views/purchasing_job_state.xml', 'views/res_partner_site.xml', 'views/apps_stored.xml', + 'views/ged_tracking.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py index 5de47a6e..2de88a8d 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -21,8 +21,11 @@ password = 'faCE2HFFKdzhvPW' x_ged_key = 'Indoteknikdotcom' x_ged_password = 'Ind0t3kn1kdotc0m4p1' + class GedTracking(models.Model): _name = 'ged.tracking' + _order = 'awb_no desc' + _rec_name = 'awb_no' status = fields.Char(string='Status') messages = fields.Char(string='Messages') @@ -55,6 +58,7 @@ class GedTracking(models.Model): last_description = fields.Char(string='Last Description') last_status_detail = fields.Char(string='Last Status Detail') last_status = fields.Char(string='Last Status') + tracking_line = fields.One2many('ged.tracking.line', 'ged_tracking_id', string='Tracking Lines', auto_join=True) class GedTrackingLine(models.Model): @@ -77,6 +81,13 @@ class GedTrackingLine(models.Model): gps = fields.Char(string='GPS') +class GedTrackingLog(models.Model): + _name = 'ged.tracking.log' + + responses = fields.Char(string='Responses') + body = fields.Char(string='Body') + + class GedApi(models.Model): _name = 'ged.api' @@ -136,9 +147,14 @@ class GedApi(models.Model): } } response = requests.post(url_tracking, headers=headers, json=json_data) + log = { + 'body': str(json_data), + 'responses': str(response.json()) + } + self.env['ged.tracking.log'].create(log) + info_awb = response.json()['infoawb'] last_status = response.json()['laststatus'] - status = response.json()['status'] messages = response.json()['messages'] awb_no = info_awb['awb_no'] diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index ae91a3da..a5605f3b 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -115,3 +115,4 @@ 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 +access_ged_tracking_log,access.ged.tracking.log,model_ged_tracking_log,,1,1,1,1 diff --git a/indoteknik_custom/views/ged_tracking.xml b/indoteknik_custom/views/ged_tracking.xml new file mode 100644 index 00000000..850788c3 --- /dev/null +++ b/indoteknik_custom/views/ged_tracking.xml @@ -0,0 +1,117 @@ + + + + ged.tracking.tree + ged.tracking + + + + + + + + + + + + + + + + + + + ged.tracking.line.tree + ged.tracking.line + + + + + + + + + + + + + + + + ged.tracking.form + ged.tracking + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ged.tracking.list.select + ged.tracking + + + + + + + + + + + + GED Tracking + ir.actions.act_window + ged.tracking + + tree,form + + + + \ No newline at end of file -- cgit v1.2.3 From b6a0434a4ff9fe580469cf79c30816697e36e48e Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 21 May 2024 12:06:46 +0700 Subject: add standalone button for get tracking awb in dunning run --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/ged.py | 3 +++ indoteknik_custom/views/dunning_run_ged.xml | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 indoteknik_custom/views/dunning_run_ged.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 68695b0e..fa0188e6 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -124,6 +124,7 @@ 'views/res_partner_site.xml', 'views/apps_stored.xml', 'views/ged_tracking.xml', + 'views/dunning_run_ged.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/ged.py b/indoteknik_custom/models/ged.py index 2de88a8d..e1881c45 100644 --- a/indoteknik_custom/models/ged.py +++ b/indoteknik_custom/models/ged.py @@ -280,3 +280,6 @@ class DunningRunGed(models.Model): dunning.date_terima_tukar_faktur = ged_tracking.delivered_date dunning.copy_date_faktur() return + + def get_tracking_history_by_awb(self): + self._get_tracking_history(self.resi_tukar_faktur) \ No newline at end of file diff --git a/indoteknik_custom/views/dunning_run_ged.xml b/indoteknik_custom/views/dunning_run_ged.xml new file mode 100644 index 00000000..5b8c6a3c --- /dev/null +++ b/indoteknik_custom/views/dunning_run_ged.xml @@ -0,0 +1,19 @@ + + + + + Dunning Run GED + dunning.run + + + +