diff options
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 80 | ||||
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/product_sla.py | 49 | ||||
| -rw-r--r-- | indoteknik_custom/models/vendor_sla.py | 26 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 2 | ||||
| -rw-r--r-- | indoteknik_custom/views/product_sla.xml | 2 | ||||
| -rw-r--r-- | indoteknik_custom/views/vendor_sla.xml | 42 | ||||
| -rwxr-xr-x | indoteknik_custom/views/x_banner_category.xml | 2 |
9 files changed, 179 insertions, 26 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 32362582..7570015f 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -1,6 +1,6 @@ from .. import controller from odoo import http -from odoo.http import request +from odoo.http import request, Response from datetime import datetime, timedelta import ast import logging @@ -33,9 +33,60 @@ class Product(controller.Controller): categories.reverse() return self.response(categories, headers=[('Cache-Control', 'max-age=3600, public')]) - - @http.route(prefix + 'product_variant/<id>/stock', auth='public', methods=['GET', 'OPTIONS']) + + @http.route(prefix + 'product/variants/sla', auth='none', type='json', csrf=False, cors='*', methods=['GET', 'OPTIONS']) @controller.Controller.must_authorized() + def get_product_template_sla_by_id(self, **kw): + json_raw = json.loads(request.httprequest.data) + + ids = json_raw.get('ids') + ids = list(map(int, ids)) + + if not ids or not isinstance(ids, list): + return ({'status' : 'Failed','message': 'Parameter "ids" harus berupa list dan tidak boleh kosong.'}) + + sla_days = 0 + products = request.env['product.product'].search([('id', 'in', ids)]) + if len(products) < 1: + return ({ + 'status' : 'Failed', + 'message' : 'Produk Tidak Di Temukan.' + }) + + product_slas = request.env['product.sla'].search([('product_variant_id', 'in', ids)]) + if len(product_slas) < 1: + return ({ + 'status' : 'Failed', + 'message' : 'Produk Tidak Di Temukan.' + }) + + # Mapping SLA untuk mempermudah lookup + sla_map = {sla.product_variant_id.id: sla for sla in product_slas} + + for product in products: + product_sla = sla_map.get(product.id) + if product_sla: + sla_days = max(sla_days, product_sla.sla_vendor_id.duration) + if product.qty_free_bandengan < 1 : + if product_sla.sla_vendor_id.unit != 'jam': + return ({ + 'status' : 'Success', + 'data' : [{ + 'include_instant': False, + 'sla_days': sla_days + }], + }) + # Jika semua loop selesai tanpa include_instant menjadi False + return ({ + 'status' : 'Success', + 'data' : [{ + 'include_instant': True, + 'sla_days': sla_days + }], + }) + + @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 = int(kw.get('id')) date_7_days_ago = datetime.now() - timedelta(days=7) @@ -47,12 +98,19 @@ class Product(controller.Controller): ('product_variant_id', '=', id), ('write_date', '>=', date_7_days_ago.strftime("%Y-%m-%d %H:%M:%S")) ], limit=1) + + include_instant = False qty_available = product.qty_free_bandengan - - if qty_available < 0: - qty_available = 0 - + + + if qty_available > 0 : + include_instant = True + else : + qty_available = 0 + if product_sla.sla_vendor_id.unit == 'jam': + include_instant = True + qty = 0 sla_date = '-' @@ -74,17 +132,18 @@ class Product(controller.Controller): if qty_available > 0: qty = qty_available + total_adem + total_excell + sla_date = product_sla.sla or 1 elif qty_altama > 0 or qty_vendor > 0: qty = total_adem if qty_altama > 0 else total_excell - sla_date = '2-4 Hari' + sla_date = product_sla.sla else: - sla_date = '3-7 Hari' + sla_date = product_sla.sla except: print('error') else: if qty_available > 0: qty = qty_available - sla_date = product_sla.sla or '-' + sla_date = product_sla.sla or 'Indent' elif qty_vendor > 0: qty = total_excell sla_date = '2-4 Hari' @@ -92,6 +151,7 @@ class Product(controller.Controller): data = { 'qty': qty, 'sla_date': sla_date, + 'can_instant': include_instant } return self.response(data, headers=[('Cache-Control', 'max-age=600, private')]) diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index d44f85db..c1593c9e 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -157,6 +157,7 @@ 'report/report_invoice.xml', 'report/report_picking.xml', 'report/report_sale_order.xml', + 'views/vendor_sla.xml', 'views/coretax_faktur.xml', ], 'demo': [], diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 3990e81c..43fbf146 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -137,5 +137,6 @@ from . import user_pengajuan_tempo from . import approval_retur_picking from . import va_multi_approve from . import va_multi_reject +from . import vendor_sla from . import stock_immediate_transfer from . import coretax_fatur diff --git a/indoteknik_custom/models/product_sla.py b/indoteknik_custom/models/product_sla.py index 2e663d30..dfdf7662 100644 --- a/indoteknik_custom/models/product_sla.py +++ b/indoteknik_custom/models/product_sla.py @@ -12,6 +12,8 @@ class ProductSla(models.Model): _rec_name = 'product_variant_id' product_variant_id = fields.Many2one('product.product',string='Product') + sla_vendor_id = fields.Many2one('vendor.sla',string='Vendor', readonly=True) + sla_vendor_duration = fields.Char(string='AVG Leadtime', related='sla_vendor_id.duration_unit') avg_leadtime = fields.Char(string='AVG Leadtime', readonly=True) leadtime = fields.Char(string='Leadtime', readonly=True) sla = fields.Char(string='SLA', readonly=True) @@ -23,6 +25,7 @@ class ProductSla(models.Model): def generate_product_variant_id_sla(self, limit=5000): # Filter produk non-Altama + products = self.env['product.product'].search([ ('x_manufacture', 'not in', [10, 122, 89]), ('location_id', '=', 57), @@ -36,6 +39,7 @@ class ProductSla(models.Model): product.sla_version += 1 product_sla = self.search([('product_variant_id', '=', product.id)], limit=1) + print(product_sla.id, product.id) if not product_sla: product_sla = self.env['product.sla'].create({ 'product_variant_id': product.id, @@ -49,12 +53,31 @@ class ProductSla(models.Model): product = self.product_variant_id - qty_available = 0 - qty_available = product.qty_onhand_bandengan + # qty_available = 0 + # qty_available = product.qty_onhand_bandengan + + + # if qty_available > 0: + # self.sla = 1 + + q_vendor = [ + ('product_id', '=', product.id), + ('is_winner', '=', True) + ] + vendor = self.env['purchase.pricelist'].search(q_vendor) - if qty_available > 0: - self.sla = '1 Hari' + vendor_duration = 0 + if vendor: + vendor_sla = self.env['vendor.sla'].search([('id_vendor', '=', vendor.vendor_id.id)], limit=1) + sla_vendor = int(vendor_sla.duration) if vendor_sla else 0 + if sla_vendor > 0: + if vendor_sla.unit == 'hari': + vendor_duration = vendor_sla.duration * 24 * 60 + else : + vendor_duration = vendor_sla.duration * 60 + + self.sla_vendor_id = vendor_sla.id if vendor_sla else False query = [ ('product_id', '=', product.id), @@ -63,22 +86,20 @@ class ProductSla(models.Model): ('picking_id.state', 'not in', ['cancel']) ] picking = self.env['stock.move.line'].search(query) + leadtimes=[] for stock in picking: date_delivered = stock.picking_id.driver_departure_date - date_so_confirmed = stock.picking_id.sale_id.date_order - if date_delivered and date_so_confirmed: - leadtime = date_delivered - date_so_confirmed + date_do_ready = stock.picking_id.date_reserved + if date_delivered and date_do_ready: + leadtime = date_delivered - date_do_ready leadtime_in_days = leadtime.days leadtimes.append(leadtime_in_days) if len(leadtimes) > 0: avg_leadtime = sum(leadtimes) / len(leadtimes) rounded_leadtime = math.ceil(avg_leadtime) - self.avg_leadtime = rounded_leadtime - if rounded_leadtime >= 1 and rounded_leadtime <= 5: - self.sla = '3-7 Hari' - elif rounded_leadtime >= 6 and rounded_leadtime <= 10: - self.sla = '4-12 Hari' - elif rounded_leadtime >= 11: - self.sla = 'Indent'
\ No newline at end of file + estimation_sla = (rounded_leadtime * 24 * 60) + vendor_duration + estimation_sla_days = estimation_sla / (24 * 60) + self.sla = math.ceil(estimation_sla_days) + self.avg_leadtime = int(rounded_leadtime)
\ No newline at end of file diff --git a/indoteknik_custom/models/vendor_sla.py b/indoteknik_custom/models/vendor_sla.py new file mode 100644 index 00000000..9af86a14 --- /dev/null +++ b/indoteknik_custom/models/vendor_sla.py @@ -0,0 +1,26 @@ +from odoo import models, fields, api + +class VendorSLA(models.Model): + _name = 'vendor.sla' + _description = 'Vendor SLA' + _rec_name = 'id_vendor' + + id_vendor = fields.Many2one('res.partner', string='Name', domain="[('industry_id', '=', 46)]") + duration = fields.Integer(string='Duration', description='SLA Duration') + unit = fields.Selection( + [('jam', 'Jam'),('hari', 'Hari')], + string="SLA Time" + ) + duration_unit = fields.Char(string="Duration (Unit)", compute="_compute_duration_unit") + + + @api.depends('duration', 'unit') + def _compute_duration_unit(self): + for record in self: + if record.duration and record.unit: + record.duration_unit = f"{record.duration} {record.unit}" + else: + record.duration_unit = "" + + +
\ No newline at end of file diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index f53a360f..67756cc7 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -149,9 +149,9 @@ access_sales_order_fulfillment_v2,access.sales.order.fulfillment.v2,model_sales_ access_v_move_outstanding,access.v.move.outstanding,model_v_move_outstanding,,1,1,1,1 access_va_multi_approve,access.va.multi.approve,model_va_multi_approve,,1,1,1,1 access_va_multi_reject,access.va.multi.reject,model_va_multi_reject,,1,1,1,1 +access_vendor_sla,access.vendor_sla,model_vendor_sla,,1,1,1,1 access_stock_immediate_transfer,access.stock.immediate.transfer,model_stock_immediate_transfer,,1,1,1,1 access_coretax_faktur,access.coretax.faktur,model_coretax_faktur,,1,1,1,1 - access_User_pengajuan_tempo_line,access.user.pengajuan.tempo.line,model_user_pengajuan_tempo_line,,1,1,1,1 access_user_pengajuan_tempo,access.user.pengajuan.tempo,model_user_pengajuan_tempo,,1,1,1,1 access_reject_reason_wizard,reject.reason.wizard,model_reject_reason_wizard,,1,1,1,0 diff --git a/indoteknik_custom/views/product_sla.xml b/indoteknik_custom/views/product_sla.xml index 8b0e874b..3722ef3d 100644 --- a/indoteknik_custom/views/product_sla.xml +++ b/indoteknik_custom/views/product_sla.xml @@ -6,6 +6,8 @@ <field name="arch" type="xml"> <tree create="false"> <field name="product_variant_id"/> + <field name="sla_vendor_id" string="Name Vendor"/> + <field name="sla_vendor_duration" string="SLA Vendor"/> <field name="avg_leadtime"/> <field name="sla"/> </tree> diff --git a/indoteknik_custom/views/vendor_sla.xml b/indoteknik_custom/views/vendor_sla.xml new file mode 100644 index 00000000..cf4425eb --- /dev/null +++ b/indoteknik_custom/views/vendor_sla.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8" ?> +<odoo> + <record id="vendor_action" model="ir.actions.act_window"> + <field name="name">Vendor SLA</field> + <field name="res_model">vendor.sla</field> + <field name="view_mode">tree,form</field> + </record> + + <record id="vendor_tree" model="ir.ui.view"> + <field name="name">Vendor SLA</field> + <field name="model">vendor.sla</field> + <field name="arch" type="xml"> + <tree> + <field name="id_vendor" string="Vendor Name" /> + <field name="duration_unit" string="Duration" /> + </tree> + </field> + </record> + + <record id="vendor_sla_view" model="ir.ui.view"> + <field name="name">Vendor SLA</field> + <field name="model">vendor.sla</field> + <field name="arch" type="xml"> + <form> + <sheet> + <group> + <field name="id_vendor" string="Vendor Name" /> + <field name="duration" string="SLA Duration" /> + <field name="unit" string="SLA Time" /> + </group> + </sheet> + </form> + </field> + </record> + + <menuitem id="menu_vendor_sla" + name="Vendor SLA" + parent="menu_monitoring_in_purchase" + sequence="1" + action="vendor_action" + /> +</odoo>
\ No newline at end of file diff --git a/indoteknik_custom/views/x_banner_category.xml b/indoteknik_custom/views/x_banner_category.xml index 11feb207..a83c4129 100755 --- a/indoteknik_custom/views/x_banner_category.xml +++ b/indoteknik_custom/views/x_banner_category.xml @@ -23,7 +23,7 @@ <group> <field name="x_name"/> <field name="x_banner_subtitle"/> - <field name="x_studio_field_KKVl4"/> + <field name="x_studio_field_KKVl4"/> <field name="last_update_solr" readonly="1"/> </group> <group></group> |
