summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-07-01 11:30:17 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-07-01 11:30:17 +0700
commitfde265040065d233a0b7eee277defb3c472575a2 (patch)
tree1ff4c348f2bbfc9de0ede5376215227222bf296c /indoteknik_custom/models
parent577fe5a01f3b782a2a441ad55f3cc721ba2e212c (diff)
api sla website
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/product_sla.py64
-rwxr-xr-xindoteknik_custom/models/product_template.py11
3 files changed, 72 insertions, 4 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 4cc2433f..8fd33b4a 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -64,3 +64,4 @@ from . import brand_vendor
from . import manufacturing
from . import requisition
from . import token_storage
+from . import product_sla
diff --git a/indoteknik_custom/models/product_sla.py b/indoteknik_custom/models/product_sla.py
new file mode 100644
index 00000000..00df2fa2
--- /dev/null
+++ b/indoteknik_custom/models/product_sla.py
@@ -0,0 +1,64 @@
+from odoo import models, api, fields
+from odoo.exceptions import AccessError, UserError, ValidationError
+from datetime import timedelta, date
+import logging
+import math
+_logger = logging.getLogger(__name__)
+
+
+class ProductSla(models.Model):
+ _name = 'product.sla'
+ _description = 'Product Sla'
+ product_variant_id = fields.Many2one('product.product',string='Product')
+ avg_leadtime = fields.Char(string='AVG Leadtime', readonly=True)
+ leadtime = fields.Char(string='Leadtime', readonly=True)
+ sla = fields.Char(string='SLA', readonly=True)
+
+ def generate_product_variant_id_sla(self):
+ # Filter produk non-Altama
+ products = self.env['stock.move.line'].search([
+ # ('product_id', '=', self.product_variant_id.id),
+ ('product_id.x_manufacture', 'not in', [10,122,89]),
+ ('picking_id.driver_departure_date', '!=', False)
+ ])
+
+ for product in products:
+ sla = self.env['product.sla'].create({
+ 'product_variant_id': product.product_id.id,
+ })
+
+ sla.generate_product_sla()
+
+ def generate_product_sla(self):
+ for sla in self:
+ query = [
+ ('product_id', '=', sla.product_variant_id.id),
+ ('picking_id', '!=', False),
+ ('picking_id.state', '=', 'done'),
+ ]
+ picking = self.env['stock.move.line'].search(query)
+ leadtimes=[]
+ for stock in picking:
+ if not stock.picking_id.driver_departure_date:
+ continue
+ date_delivered = stock.picking_id.driver_departure_date
+ date_so_confirmed = stock.picking_id.sale_id.date_order
+ if date_delivered and date_so_confirmed:
+ leadtime = date_delivered - date_so_confirmed
+ leadtime_in_days = leadtime.days
+ leadtimes.append(leadtime_in_days)
+ if len(leadtimes) > 0:
+ avg_leadtime = sum(leadtimes)/len(leadtimes)
+ rounded_leadtime = math.ceil(float(avg_leadtime))
+ sla.avg_leadtime = rounded_leadtime
+
+ if picking.picking_id.location_id == 57 and picking.picking_id.qty_available > 10:
+ sla.sla = '1 Hari'
+ elif sla.avg_leadtime and float(sla.avg_leadtime) >= 1 and float(sla.avg_leadtime) <= 5:
+ sla.sla = '3-6 Hari'
+ elif sla.avg_leadtime and float(sla.avg_leadtime) >= 6 and float(sla.avg_leadtime) <= 10:
+ sla.sla = '4-12 Hari'
+ elif sla.avg_leadtime and float(sla.avg_leadtime) >= 11:
+ sla.sla = 'Indent'
+ else:
+ sla.sla = '-' \ No newline at end of file
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 5fbac2e3..8247cd7e 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -196,7 +196,7 @@ class ProductTemplate(models.Model):
qty = self._get_stock_altama()
print(qty)
- def _get_stock_altama(self):
+ def get_stock_altama(self, item_code):
current_time = datetime.now()
current_time = current_time.strftime('%Y-%m-%d %H:%M:%S')
query = [('source', '=', 'altama'), ('expired_date', '>', current_time)]
@@ -215,13 +215,16 @@ class ProductTemplate(models.Model):
}
json_data = {
'type_search': 'Item_code',
- 'search_key':['RSG100-3'],
+ 'search_key':[item_code],
}
response = requests.post(url, headers=headers, json=json_data)
datas = json.loads(response.text)['data']
+ qty = 0
for data in datas:
- qty = data['availability']
- return qty or 0
+ availability = int(data['availability']) # Mengonversi ke tipe data int
+ qty += availability # Mengakumulasi qty dari setiap data
+
+ return qty
def _get_new_token_altama(self):
url = "https://kc.altama.co.id/realms/altama/protocol/openid-connect/token"