summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/product_sla.py49
-rw-r--r--indoteknik_custom/models/vendor_sla.py26
3 files changed, 62 insertions, 14 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 3990e81c..43fbf146 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -137,5 +137,6 @@ from . import user_pengajuan_tempo
from . import approval_retur_picking
from . import va_multi_approve
from . import va_multi_reject
+from . import vendor_sla
from . import stock_immediate_transfer
from . import coretax_fatur
diff --git a/indoteknik_custom/models/product_sla.py b/indoteknik_custom/models/product_sla.py
index 2e663d30..dfdf7662 100644
--- a/indoteknik_custom/models/product_sla.py
+++ b/indoteknik_custom/models/product_sla.py
@@ -12,6 +12,8 @@ class ProductSla(models.Model):
_rec_name = 'product_variant_id'
product_variant_id = fields.Many2one('product.product',string='Product')
+ sla_vendor_id = fields.Many2one('vendor.sla',string='Vendor', readonly=True)
+ sla_vendor_duration = fields.Char(string='AVG Leadtime', related='sla_vendor_id.duration_unit')
avg_leadtime = fields.Char(string='AVG Leadtime', readonly=True)
leadtime = fields.Char(string='Leadtime', readonly=True)
sla = fields.Char(string='SLA', readonly=True)
@@ -23,6 +25,7 @@ class ProductSla(models.Model):
def generate_product_variant_id_sla(self, limit=5000):
# Filter produk non-Altama
+
products = self.env['product.product'].search([
('x_manufacture', 'not in', [10, 122, 89]),
('location_id', '=', 57),
@@ -36,6 +39,7 @@ class ProductSla(models.Model):
product.sla_version += 1
product_sla = self.search([('product_variant_id', '=', product.id)], limit=1)
+ print(product_sla.id, product.id)
if not product_sla:
product_sla = self.env['product.sla'].create({
'product_variant_id': product.id,
@@ -49,12 +53,31 @@ class ProductSla(models.Model):
product = self.product_variant_id
- qty_available = 0
- qty_available = product.qty_onhand_bandengan
+ # qty_available = 0
+ # qty_available = product.qty_onhand_bandengan
+
+
+ # if qty_available > 0:
+ # self.sla = 1
+
+ q_vendor = [
+ ('product_id', '=', product.id),
+ ('is_winner', '=', True)
+ ]
+ vendor = self.env['purchase.pricelist'].search(q_vendor)
- if qty_available > 0:
- self.sla = '1 Hari'
+ vendor_duration = 0
+ if vendor:
+ vendor_sla = self.env['vendor.sla'].search([('id_vendor', '=', vendor.vendor_id.id)], limit=1)
+ sla_vendor = int(vendor_sla.duration) if vendor_sla else 0
+ if sla_vendor > 0:
+ if vendor_sla.unit == 'hari':
+ vendor_duration = vendor_sla.duration * 24 * 60
+ else :
+ vendor_duration = vendor_sla.duration * 60
+
+ self.sla_vendor_id = vendor_sla.id if vendor_sla else False
query = [
('product_id', '=', product.id),
@@ -63,22 +86,20 @@ class ProductSla(models.Model):
('picking_id.state', 'not in', ['cancel'])
]
picking = self.env['stock.move.line'].search(query)
+
leadtimes=[]
for stock in picking:
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
+ date_do_ready = stock.picking_id.date_reserved
+ if date_delivered and date_do_ready:
+ leadtime = date_delivered - date_do_ready
leadtime_in_days = leadtime.days
leadtimes.append(leadtime_in_days)
if len(leadtimes) > 0:
avg_leadtime = sum(leadtimes) / len(leadtimes)
rounded_leadtime = math.ceil(avg_leadtime)
- self.avg_leadtime = rounded_leadtime
- if rounded_leadtime >= 1 and rounded_leadtime <= 5:
- self.sla = '3-7 Hari'
- elif rounded_leadtime >= 6 and rounded_leadtime <= 10:
- self.sla = '4-12 Hari'
- elif rounded_leadtime >= 11:
- self.sla = 'Indent' \ No newline at end of file
+ estimation_sla = (rounded_leadtime * 24 * 60) + vendor_duration
+ estimation_sla_days = estimation_sla / (24 * 60)
+ self.sla = math.ceil(estimation_sla_days)
+ self.avg_leadtime = int(rounded_leadtime) \ No newline at end of file
diff --git a/indoteknik_custom/models/vendor_sla.py b/indoteknik_custom/models/vendor_sla.py
new file mode 100644
index 00000000..9af86a14
--- /dev/null
+++ b/indoteknik_custom/models/vendor_sla.py
@@ -0,0 +1,26 @@
+from odoo import models, fields, api
+
+class VendorSLA(models.Model):
+ _name = 'vendor.sla'
+ _description = 'Vendor SLA'
+ _rec_name = 'id_vendor'
+
+ id_vendor = fields.Many2one('res.partner', string='Name', domain="[('industry_id', '=', 46)]")
+ duration = fields.Integer(string='Duration', description='SLA Duration')
+ unit = fields.Selection(
+ [('jam', 'Jam'),('hari', 'Hari')],
+ string="SLA Time"
+ )
+ duration_unit = fields.Char(string="Duration (Unit)", compute="_compute_duration_unit")
+
+
+ @api.depends('duration', 'unit')
+ def _compute_duration_unit(self):
+ for record in self:
+ if record.duration and record.unit:
+ record.duration_unit = f"{record.duration} {record.unit}"
+ else:
+ record.duration_unit = ""
+
+
+ \ No newline at end of file