summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2024-05-22 02:15:56 +0000
committerIT Fixcomart <it@fixcomart.co.id>2024-05-22 02:15:56 +0000
commitad1325d80785f236a32bff2f2645fe8c85c50efb (patch)
tree85d8772e1af6ef37a0bfe3bc19064258b7bea39d /indoteknik_custom/models
parentf6c324302fb2a6490c9c95836887e2c58d684e86 (diff)
parent4f5594be8d73f88fbb42671525d0d2c6ed977abe (diff)
Merged in production (pull request #143)
Production
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py2
-rw-r--r--indoteknik_custom/models/dunning_run.py1
-rw-r--r--indoteknik_custom/models/external_api.py21
-rw-r--r--indoteknik_custom/models/ged.py291
-rwxr-xr-xindoteknik_custom/models/product_template.py12
-rwxr-xr-xindoteknik_custom/models/sale_order.py9
-rw-r--r--indoteknik_custom/models/stock_picking.py5
7 files changed, 337 insertions, 4 deletions
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/dunning_run.py b/indoteknik_custom/models/dunning_run.py
index abfd68be..4e04c03c 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__)
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..a2e8bc3c
--- /dev/null
+++ b/indoteknik_custom/models/ged.py
@@ -0,0 +1,291 @@
+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'
+# 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'
+
+
+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')
+ 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')
+ 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')
+ 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)
+ dunning_id = fields.Many2one('dunning.run', string='Dunning Run')
+
+
+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')
+ dunning_id = fields.Many2one('dunning.run', string='Dunning Run')
+
+
+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'
+
+ def _get_token(self):
+ 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, 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',
+ 'X-Ged-Key': x_ged_key,
+ 'X-Ged-Password': x_ged_password,
+ 'Authorization': 'Bearer '+token
+ }
+ json_data = {
+ 'data': {
+ 'awb': dunning_run.resi_tukar_faktur
+ }
+ }
+ 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']
+ 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']
+ 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']
+ last_description = last_status['description']
+ last_status_detail = last_status['status_detail']
+ header_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,
+ '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,
+ 'last_description': last_description,
+ 'last_status_detail': last_status_detail,
+ 'last_status': header_last_status,
+ 'dunning_id': dunning_run.id
+ }
+
+ 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,
+ 'dunning_id': dunning_run.id
+ }
+ self.env['ged.tracking.line'].create(param_line)
+
+ return ged_tracking
+
+
+class DunningRunGed(models.Model):
+ _inherit = 'dunning.run'
+
+ last_status_awb = fields.Char(string='Last Status AWB')
+ ged_tracking = fields.One2many('ged.tracking', 'dunning_id', string='GED Tracking', auto_join=True)
+ ged_tracking_line = fields.One2many('ged.tracking.line', 'dunning_id', string='GED Tracking Line', auto_join=True)
+
+ def _get_tracking_history(self, test_awb_number):
+ if test_awb_number > 0:
+ query = [
+ ('last_status_awb', '!=', 'POD Return'),
+ ('resi_tukar_faktur', '=', test_awb_number),
+ ('shipper_faktur_id', '=', 123)
+ ]
+ else:
+ query = [
+ ('last_status_awb', '!=', 'POD Return'),
+ ('resi_tukar_faktur', '!=', False),
+ ('shipper_faktur_id', '=', 123),
+ ('date_terima_tukar_faktur', '=', False)
+ ]
+ dunnings = self.env['dunning.run'].search(query, limit=50)
+
+ 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']
+ 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.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/models/product_template.py b/indoteknik_custom/models/product_template.py
index 8494e18a..97ad07a7 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -350,6 +350,18 @@ class ProductProduct(models.Model):
is_edited = fields.Boolean(string='Is Edited')
qty_sold = fields.Float(string='Sold Quantity', compute='_get_qty_sold')
+ def update_internal_reference_variants(self, limit=100):
+ variants = self.env['product.product'].search([
+ ('default_code', '=', False),
+ ('type', '=', 'product'),
+ ('active', '=', True)
+ ], limit=limit, order='write_date desc')
+ for variant in variants:
+ if not variant.default_code:
+ variant.default_code = 'ITV.'+str(variant.id)
+
+ _logger.info('Updated variant %s' % variant.name)
+
def _get_po_suggest(self, qty_purchase):
if self.qty_available_bandengan < qty_purchase:
return 'harus beli'
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index aa34b0f4..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')
@@ -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):
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 22aceaf4..62d86911 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -88,8 +88,9 @@ class StockPicking(models.Model):
@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')
+ 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()