diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-13 11:26:47 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-13 11:26:47 +0700 |
| commit | 5aa6e8f5ed1bd628a5f4559a3f752b6e83ee2c49 (patch) | |
| tree | b1fc439658912bab3beb82392eecbad932e39d6f | |
| parent | 32bf7b115ec71e72d9cde58bfa3c0304c4b1ffcb (diff) | |
Add product sla cron xml and fix product sla api
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 32 | ||||
| -rw-r--r-- | indoteknik_custom/views/product_sla.xml | 13 |
2 files changed, 30 insertions, 15 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 3908ecc2..8803bae3 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -12,9 +12,10 @@ _logger = logging.getLogger(__name__) class Product(controller.Controller): prefix = '/api/v1/' - @http.route(prefix + '/api/v1/product_variant/<id>/stock', auth='public', methods=['GET', 'OPTIONS']) + @http.route(prefix + 'product_variant/<id>/stock', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() def get_product_template_stock_by_id(self, **kw): - id = kw.get('id') + 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) @@ -24,26 +25,27 @@ class Product(controller.Controller): qty_available = 0 qty = 0 - sla_date = '-' + sla_date = '-' is_altama_product = product.x_manufacture.id in [10,122,89] - 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)) if is_altama_product: - if qty_available > 10: - qty = qty_altama + qty_available - sla_date = '1 Hari' - else: - if qty_altama > 0: - qty = qty_altama + 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 + if qty_available > 10: + qty += qty_available + sla_date = '1 Hari' + elif qty_altama > 0: sla_date = '2-4 Hari' else: sla_date = 'Indent' + except: + print('error') else: - if qty_available > 0: - qty = qty_available - sla_date = product_sla.sla or '-' + qty = qty_available + sla_date = product_sla.sla or '-' data = { 'qty': qty, diff --git a/indoteknik_custom/views/product_sla.xml b/indoteknik_custom/views/product_sla.xml index f91cf97c..59d58568 100644 --- a/indoteknik_custom/views/product_sla.xml +++ b/indoteknik_custom/views/product_sla.xml @@ -38,6 +38,19 @@ <field name="view_mode">tree,form</field> </record> + <record id="product_sla_generate_cron" model="ir.cron"> + <field name="name">Product SLA: Generate</field> + <field name="interval_number">8</field> + <field name="interval_type">minutes</field> + <field name="numbercall">-1</field> + <field name="doall" eval="False"/> + <field name="model_id" ref="model_product_sla"/> + <field name="code">model.generate_product_variant_id_sla(limit=150)</field> + <field name="state">code</field> + <field name="priority">100</field> + <field name="active">True</field> + </record> + <menuitem id="menu_product_sla" name="Product Sla" action="product_sla_action" |
