From 0aaf2d3af0e5096514f8b72850f6a3d2901cfc3e Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 18 Jul 2023 11:56:33 +0700 Subject: refactor product real stock --- indoteknik_api/controllers/api_v1/product.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 8803bae3..8411ee25 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -18,11 +18,9 @@ class Product(controller.Controller): id = int(kw.get('id')) product = request.env['product.product'].search([('id', '=', id)], limit=1) product_sla = request.env['product.sla'].search([('product_variant_id', '=', id)], limit=1) + stock_vendor = request.env['stock.vendor'].search([('product_variant_id', '=', id)], limit=1) qty_available = product.qty_onhand_bandengan - qty_available -= 10 - if qty_available < 10: - qty_available = 0 qty = 0 sla_date = '-' @@ -33,8 +31,8 @@ class Product(controller.Controller): qty_altama = request.env['product.template'].get_stock_altama(product.default_code) qty_altama -= int(qty_altama * 0.1) qty_altama = math.ceil(float(qty_altama)) - qty = qty_altama - if qty_available > 10: + qty = qty_altama + if qty_available > 0: qty += qty_available sla_date = '1 Hari' elif qty_altama > 0: -- cgit v1.2.3 From 145b370e5b57206edd1b44400c9ed8a7a3d26c36 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 20 Jul 2023 17:56:34 +0700 Subject: update api product sla --- indoteknik_api/controllers/api_v1/product.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 8411ee25..96b0742a 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -13,31 +13,37 @@ class Product(controller.Controller): prefix = '/api/v1/' @http.route(prefix + 'product_variant//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')) product = request.env['product.product'].search([('id', '=', id)], limit=1) product_sla = request.env['product.sla'].search([('product_variant_id', '=', id)], limit=1) stock_vendor = request.env['stock.vendor'].search([('product_variant_id', '=', id)], limit=1) - + qty_available = product.qty_onhand_bandengan qty = 0 sla_date = '-' + qty_vendor = stock_vendor.quantity + qty_vendor -= int(qty_vendor * 0.1) + qty_vendor = math.ceil(float(qty_vendor)) + total_excell = qty_vendor + is_altama_product = product.x_manufacture.id in [10,122,89] if is_altama_product: try: qty_altama = request.env['product.template'].get_stock_altama(product.default_code) qty_altama -= int(qty_altama * 0.1) qty_altama = math.ceil(float(qty_altama)) - qty = qty_altama + total_adem = qty_altama if qty_available > 0: - qty += qty_available + qty = qty_available + total_adem sla_date = '1 Hari' - elif qty_altama > 0: + elif qty_altama > 0 or qty_vendor > 0: + qty = total_adem if qty_altama > 0 else total_excell sla_date = '2-4 Hari' - else: + else: sla_date = 'Indent' except: print('error') -- cgit v1.2.3 From 22298c2cfdb7d3de1c7a2e85e21444847b65d4ff Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 20 Jul 2023 17:57:28 +0700 Subject: add must_authorized in api product sla --- indoteknik_api/controllers/api_v1/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 96b0742a..4795f1fb 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -13,7 +13,7 @@ class Product(controller.Controller): prefix = '/api/v1/' @http.route(prefix + 'product_variant//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')) product = request.env['product.product'].search([('id', '=', id)], limit=1) -- cgit v1.2.3 From 81175e09c6fa406ee3269265a91ca859659ef7fe Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 20 Jul 2023 18:01:30 +0700 Subject: add total_excell to condition --- indoteknik_api/controllers/api_v1/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 4795f1fb..87747988 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -38,7 +38,7 @@ class Product(controller.Controller): qty_altama = math.ceil(float(qty_altama)) total_adem = qty_altama if qty_available > 0: - qty = qty_available + total_adem + qty = qty_available + total_adem + total_excell sla_date = '1 Hari' elif qty_altama > 0 or qty_vendor > 0: qty = total_adem if qty_altama > 0 else total_excell -- cgit v1.2.3 From 70c667cb341efa30f29626183bb5dc25654714de Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 21 Jul 2023 08:20:16 +0700 Subject: update stock vendor --- indoteknik_api/controllers/api_v1/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 87747988..53ba7671 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -18,7 +18,7 @@ class Product(controller.Controller): id = int(kw.get('id')) product = request.env['product.product'].search([('id', '=', id)], limit=1) product_sla = request.env['product.sla'].search([('product_variant_id', '=', id)], limit=1) - stock_vendor = request.env['stock.vendor'].search([('product_variant_id', '=', id)], limit=1) + stock_vendor = self.env['stock.vendor'].get_stock_updated_last_7_days(id) qty_available = product.qty_onhand_bandengan -- cgit v1.2.3 From f4c02f0ca17c0c72314334c03417c2f54382dfa1 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 21 Jul 2023 15:20:08 +0700 Subject: fix condition --- indoteknik_api/controllers/api_v1/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 53ba7671..3667a787 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -44,7 +44,7 @@ class Product(controller.Controller): qty = total_adem if qty_altama > 0 else total_excell sla_date = '2-4 Hari' else: - sla_date = 'Indent' + sla_date = '3-7 Hari' except: print('error') else: -- cgit v1.2.3 From 2a1179b22cd1b8ee9e3e31c157821dbbeb66195f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Sat, 22 Jul 2023 11:12:14 +0700 Subject: fix bug api product sla stock vendor --- indoteknik_api/controllers/api_v1/product.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 3667a787..587773ee 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -13,12 +13,14 @@ class Product(controller.Controller): prefix = '/api/v1/' @http.route(prefix + 'product_variant//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')) product = request.env['product.product'].search([('id', '=', id)], limit=1) product_sla = request.env['product.sla'].search([('product_variant_id', '=', id)], limit=1) - stock_vendor = self.env['stock.vendor'].get_stock_updated_last_7_days(id) + stock_vendor = request.env['stock.vendor'].search([('product_variant_id', '=', id)], limit=1) + + stock_vendor = stock_vendor.get_stock_updated_last_7_days() qty_available = product.qty_onhand_bandengan -- cgit v1.2.3 From 968f63a411f8cc9e190a261123e47604ce54c2b2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 24 Jul 2023 08:55:26 +0700 Subject: fix bug and refactor api product sla --- indoteknik_api/controllers/api_v1/product.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 587773ee..7ec6459b 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -13,32 +13,35 @@ class Product(controller.Controller): prefix = '/api/v1/' @http.route(prefix + 'product_variant//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) product = request.env['product.product'].search([('id', '=', id)], limit=1) product_sla = request.env['product.sla'].search([('product_variant_id', '=', id)], limit=1) - stock_vendor = request.env['stock.vendor'].search([('product_variant_id', '=', id)], limit=1) - - stock_vendor = stock_vendor.get_stock_updated_last_7_days() + stock_vendor = request.env['stock.vendor'].search([ + ('product_variant_id', '=', id), + ('write_date', '>=', date_7_days_ago.strftime("%Y-%m-%d %H:%M:%S")) + ], limit=1) qty_available = product.qty_onhand_bandengan qty = 0 sla_date = '-' - - qty_vendor = stock_vendor.quantity - qty_vendor -= int(qty_vendor * 0.1) - qty_vendor = math.ceil(float(qty_vendor)) - total_excell = qty_vendor is_altama_product = product.x_manufacture.id in [10,122,89] if is_altama_product: try: + # Qty Altama qty_altama = request.env['product.template'].get_stock_altama(product.default_code) qty_altama -= int(qty_altama * 0.1) qty_altama = math.ceil(float(qty_altama)) total_adem = qty_altama + # Qty Stock Vendor + qty_vendor = stock_vendor.quantity + qty_vendor -= int(qty_vendor * 0.1) + qty_vendor = math.ceil(float(qty_vendor)) + total_excell = qty_vendor if qty_available > 0: qty = qty_available + total_adem + total_excell sla_date = '1 Hari' -- cgit v1.2.3