From 2a6a6f946f7d8d255cd4a384a951c5f09bfbe2a1 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 5 Jul 2023 14:49:18 +0700 Subject: change condition product non altama --- indoteknik_custom/models/product_sla.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/indoteknik_custom/models/product_sla.py b/indoteknik_custom/models/product_sla.py index 5cd3bbe2..1ef1e0fb 100644 --- a/indoteknik_custom/models/product_sla.py +++ b/indoteknik_custom/models/product_sla.py @@ -25,39 +25,34 @@ class ProductSla(models.Model): # Filter produk non-Altama products = self.env['product.product'].search([ ('x_manufacture', 'not in', [10, 122, 89]), - ('location_id', '=', 57) + ('location_id', '=', 57), + ('stock_move_ids', '!=', False), ], order='sla_version asc', limit=limit) i = 1 - indexMatch = 1 for product in products: - qty_available = 0 - for stock in product.stock_quant_ids: - if stock.location_id.id == 57: - qty_available += stock.quantity - qty_available -= 10 - _logger.info(f'Product SLA: {i}/{len(products)}') i += 1 product.sla_version += 1 - if len(product.stock_move_ids) == 0 and qty_available <= 0: - continue - - _logger.info(f'Match Product SLA: {indexMatch}') - indexMatch += 1 product_sla = self.search([('product_variant_id', '=', product.id)], limit=1) if not product_sla: product_sla = self.env['product.sla'].create({ 'product_variant_id': product.id, }) - product_sla.generate_product_sla(qty_available) + product_sla.generate_product_sla() - def generate_product_sla(self, qty_available): + def generate_product_sla(self): self.avg_leadtime = '-' self.sla = '-' + qty_available = 0 + for stock in self.product_variant_id.stock_quant_ids: + if stock.location_id.id == 57: + qty_available += stock.quantity + qty_available -= 10 + total_stock_moves = len(self.product_variant_id.stock_move_ids) if total_stock_moves > 0: -- cgit v1.2.3