summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2025-01-07 17:02:06 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2025-01-07 17:02:06 +0700
commit7ac434ec0fcf75cb6eefe1892118b7c18b3db53a (patch)
tree2aaf7a6b409248acec3bcf58dbcb31999d4fef5f
parent60f54931f8eac477ab737abab1710789e0a2aaf4 (diff)
sla
-rw-r--r--indoteknik_api/controllers/api_v1/product.py23
-rw-r--r--indoteknik_custom/models/product_sla.py44
-rw-r--r--indoteknik_custom/views/product_sla.xml4
3 files changed, 36 insertions, 35 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 32362582..2573d7a8 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -35,7 +35,7 @@ class Product(controller.Controller):
return self.response(categories, headers=[('Cache-Control', 'max-age=3600, public')])
@http.route(prefix + 'product_variant/<id>/stock', auth='public', methods=['GET', 'OPTIONS'])
- @controller.Controller.must_authorized()
+ @controller.Controller.must_authorized()
def get_product_template_stock_by_id(self, **kw):
id = int(kw.get('id'))
date_7_days_ago = datetime.now() - timedelta(days=7)
@@ -47,12 +47,19 @@ class Product(controller.Controller):
('product_variant_id', '=', id),
('write_date', '>=', date_7_days_ago.strftime("%Y-%m-%d %H:%M:%S"))
], limit=1)
+
+ include_instant = False
qty_available = product.qty_free_bandengan
-
- if qty_available < 0:
- qty_available = 0
-
+
+
+ if qty_available > 0 :
+ include_instant = True
+ else :
+ qty_available = 0
+ if product_sla.sla_vendor_id.unit == 'jam':
+ include_instant = True
+
qty = 0
sla_date = '-'
@@ -74,9 +81,10 @@ class Product(controller.Controller):
if qty_available > 0:
qty = qty_available + total_adem + total_excell
+ sla_date = product_sla.sla or 1
elif qty_altama > 0 or qty_vendor > 0:
qty = total_adem if qty_altama > 0 else total_excell
- sla_date = '2-4 Hari'
+ sla_date = product.sla
else:
sla_date = '3-7 Hari'
except:
@@ -84,7 +92,7 @@ class Product(controller.Controller):
else:
if qty_available > 0:
qty = qty_available
- sla_date = product_sla.sla or '-'
+ sla_date = product_sla.sla or 'Indent'
elif qty_vendor > 0:
qty = total_excell
sla_date = '2-4 Hari'
@@ -92,6 +100,7 @@ class Product(controller.Controller):
data = {
'qty': qty,
'sla_date': sla_date,
+ 'can_instant': include_instant
}
return self.response(data, headers=[('Cache-Control', 'max-age=600, private')])
diff --git a/indoteknik_custom/models/product_sla.py b/indoteknik_custom/models/product_sla.py
index f597ec44..dfdf7662 100644
--- a/indoteknik_custom/models/product_sla.py
+++ b/indoteknik_custom/models/product_sla.py
@@ -12,8 +12,8 @@ class ProductSla(models.Model):
_rec_name = 'product_variant_id'
product_variant_id = fields.Many2one('product.product',string='Product')
- vendor_id = fields.Many2one('res.partner',string='Vendor', readonly=True)
- sla_vendor = fields.Char(string='SLA Vendor', readonly=True)
+ 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)
@@ -52,7 +52,14 @@ class ProductSla(models.Model):
self.sla = '-'
product = self.product_variant_id
+
+ # 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)
@@ -61,7 +68,6 @@ class ProductSla(models.Model):
vendor = self.env['purchase.pricelist'].search(q_vendor)
vendor_duration = 0
- print(vendor.vendor_id.id)
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
@@ -69,17 +75,9 @@ class ProductSla(models.Model):
if vendor_sla.unit == 'hari':
vendor_duration = vendor_sla.duration * 24 * 60
else :
- vendor_duration = vendor_sla.duration
-
- self.sla_vendor = vendor_sla.duration_unit
- self.vendor_id = vendor.vendor_id.id
-
- qty_available = 0
- qty_available = product.qty_onhand_bandengan
-
-
- if qty_available > 0:
- self.sla = '1 Hari'
+ vendor_duration = vendor_sla.duration * 60
+
+ self.sla_vendor_id = vendor_sla.id if vendor_sla else False
query = [
('product_id', '=', product.id),
@@ -88,12 +86,13 @@ 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)
@@ -102,12 +101,5 @@ class ProductSla(models.Model):
rounded_leadtime = math.ceil(avg_leadtime)
estimation_sla = (rounded_leadtime * 24 * 60) + vendor_duration
estimation_sla_days = estimation_sla / (24 * 60)
- self.sla = estimation_sla_days
- self.avg_leadtime = int(rounded_leadtime)
- # self.sla = (sla_vendor + self.avg_leadtime) / 2
- # 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
+ self.sla = math.ceil(estimation_sla_days)
+ self.avg_leadtime = int(rounded_leadtime) \ No newline at end of file
diff --git a/indoteknik_custom/views/product_sla.xml b/indoteknik_custom/views/product_sla.xml
index 5276bb03..3722ef3d 100644
--- a/indoteknik_custom/views/product_sla.xml
+++ b/indoteknik_custom/views/product_sla.xml
@@ -6,8 +6,8 @@
<field name="arch" type="xml">
<tree create="false">
<field name="product_variant_id"/>
- <field name="vendor_id" string="Vendor"/>
- <field name="sla_vendor" string="Vendor SLA"/>
+ <field name="sla_vendor_id" string="Name Vendor"/>
+ <field name="sla_vendor_duration" string="SLA Vendor"/>
<field name="avg_leadtime"/>
<field name="sla"/>
</tree>