From 917bc54da1bdcbbac36e20aa483e8fd0bac39e4f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 3 Jul 2023 13:50:12 +0700 Subject: product sla non altama --- indoteknik_custom/models/product_sla.py | 34 ++++++++++++++++++++------------- indoteknik_custom/views/product_sla.xml | 1 - 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/indoteknik_custom/models/product_sla.py b/indoteknik_custom/models/product_sla.py index 8d314dd9..4f74b28f 100644 --- a/indoteknik_custom/models/product_sla.py +++ b/indoteknik_custom/models/product_sla.py @@ -18,9 +18,13 @@ class ProductSla(models.Model): # Filter produk non-Altama products = self.env['product.product'].search([ ('x_manufacture', 'not in', [10,122,89]), - ]) + ('location_id', '=', 57), + ], offset=74465) + i = 1 for product in products: + print(f"PRODUCT KE: {i}/{len(products)}") + i += 1 sla = self.env['product.sla'].create({ 'product_variant_id': product.id, }) @@ -34,6 +38,7 @@ class ProductSla(models.Model): ('product_id', '=', sla.product_variant_id.id), ('picking_id', '!=', False), ('picking_id.state', '=', 'done'), + ('picking_id.location_id', '=', 57) ] picking = self.env['stock.move.line'].search(query) leadtimes=[] @@ -50,16 +55,19 @@ class ProductSla(models.Model): 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: + if sla.product_variant_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 = '-' + + for stock in sla.product_variant_id.stock_quant_ids: + if not sla.avg_leadtime and stock.location_id.id == 57 and stock.quantity > 0: 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 = '-' - elif not sla.product_variant_id.stock_move_ids.picking_id and sla.product_variant_id.stock_quant_ids.location_id.id == 57 and sla.product_variant_id.stock_quant_ids.quantity > 0: - sla.sla = '1 Hari' - sla.avg_leadtime = '-' + sla.avg_leadtime = '-' + diff --git a/indoteknik_custom/views/product_sla.xml b/indoteknik_custom/views/product_sla.xml index 378a977b..2cc29d7c 100644 --- a/indoteknik_custom/views/product_sla.xml +++ b/indoteknik_custom/views/product_sla.xml @@ -27,7 +27,6 @@ - -- cgit v1.2.3