diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2023-07-24 01:59:15 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2023-07-24 01:59:15 +0000 |
| commit | 6966c00bf2ef2bd9c2261d9363ac6b463a7766dd (patch) | |
| tree | 2149f187f28c0897f4d17118209231a95084b35d | |
| parent | 11aa548be858c2751b2e7b4d15ed0ffcc7b5f237 (diff) | |
| parent | 968f63a411f8cc9e190a261123e47604ce54c2b2 (diff) | |
Merged in real-stock (pull request #63)
Real stock
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 31 | ||||
| -rw-r--r-- | indoteknik_custom/models/product_sla.py | 9 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/models/stock_vendor.py | 1 |
4 files changed, 25 insertions, 18 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 8803bae3..7ec6459b 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -16,31 +16,40 @@ class Product(controller.Controller): @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), + ('write_date', '>=', date_7_days_ago.strftime("%Y-%m-%d %H:%M:%S")) + ], limit=1) + qty_available = product.qty_onhand_bandengan - qty_available -= 10 - if qty_available < 10: - qty_available = 0 qty = 0 sla_date = '-' - + 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)) - qty = qty_altama - if qty_available > 10: - qty += qty_available + 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' - 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: - sla_date = 'Indent' + else: + sla_date = '3-7 Hari' except: print('error') else: diff --git a/indoteknik_custom/models/product_sla.py b/indoteknik_custom/models/product_sla.py index f969502f..2e663d30 100644 --- a/indoteknik_custom/models/product_sla.py +++ b/indoteknik_custom/models/product_sla.py @@ -51,12 +51,9 @@ class ProductSla(models.Model): qty_available = 0 qty_available = product.qty_onhand_bandengan - qty_available -= 10 - if qty_available < 10: - qty_available = 0 - - if qty_available > 10: + + if qty_available > 0: self.sla = '1 Hari' query = [ @@ -80,7 +77,7 @@ class ProductSla(models.Model): rounded_leadtime = math.ceil(avg_leadtime) self.avg_leadtime = rounded_leadtime if rounded_leadtime >= 1 and rounded_leadtime <= 5: - self.sla = '3-6 Hari' + self.sla = '3-7 Hari' elif rounded_leadtime >= 6 and rounded_leadtime <= 10: self.sla = '4-12 Hari' elif rounded_leadtime >= 11: diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 1a83b702..7abdf1c1 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -221,7 +221,7 @@ class ProductTemplate(models.Model): datas = json.loads(response.text)['data'] qty = 0 for data in datas: - availability = int(data['availability']) # Mengonversi ke tipe data int + availability = float(data['availability']) # Mengonversi ke tipe data int qty += availability # Mengakumulasi qty dari setiap data return qty diff --git a/indoteknik_custom/models/stock_vendor.py b/indoteknik_custom/models/stock_vendor.py index 1e5bce16..f214a5e1 100755 --- a/indoteknik_custom/models/stock_vendor.py +++ b/indoteknik_custom/models/stock_vendor.py @@ -1,5 +1,6 @@ from odoo import fields, models, api import logging +from datetime import datetime, timedelta _logger = logging.getLogger(__name__) |
