From 527165ae245fa7301de1a767f5e09865ec8aeade Mon Sep 17 00:00:00 2001 From: Mqdd Date: Wed, 19 Nov 2025 15:32:29 +0700 Subject: import --- indoteknik_custom/__manifest__.py | 2 +- indoteknik_custom/models/sourcing_job_order.py | 65 ++++++++++++++++++++++++++ indoteknik_custom/security/ir.model.access.csv | 1 + indoteknik_custom/views/sourcing.xml | 29 ++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 75c83d68..9ff73ed9 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -191,7 +191,7 @@ 'views/sj_tele.xml', 'views/close_tempo_mail_template.xml', 'views/domain_apo.xml', - 'views/sourcing.xml' + 'views/sourcing.xml', 'views/uom_uom.xml', 'views/commission_internal.xml' ], diff --git a/indoteknik_custom/models/sourcing_job_order.py b/indoteknik_custom/models/sourcing_job_order.py index 75307ee2..c0d15c75 100644 --- a/indoteknik_custom/models/sourcing_job_order.py +++ b/indoteknik_custom/models/sourcing_job_order.py @@ -5,6 +5,9 @@ import requests import logging import pytz from pytz import timezone +import base64 +import csv +import io _logger = logging.getLogger(__name__) @@ -1055,4 +1058,66 @@ class WizardExportSJOtoSO(models.TransientModel): 'view_mode': 'form', 'res_id': so.id, 'target': 'current', + } + +class SourcingJobOrderLineImportWizard(models.TransientModel): + _name = 'sourcing.job.order.line.import.wizard' + _description = 'Import Sourcing Job Order Line Wizard' + + file = fields.Binary(string='File (.CSV)', required=True) + filename = fields.Char("Filename") + order_id = fields.Many2one('sourcing.job.order', string="Sourcing Job Order", required=True) + + + def action_import(self): + if not self.file: + raise UserError("⚠️ Harap upload file terlebih dahulu.") + + data = base64.b64decode(self.file) + file_io = io.StringIO(data.decode('utf-8')) + reader = csv.DictReader(file_io) + + lines_created = 0 + for row in reader: + print("ROW:", row) # 🧪 Tambahkan ini untuk lihat isi row di log + _logger.info("ROW: %s", row) + + if not row.get('Nama Barang'): + continue + + vendor = self.env['res.partner'].search([('name', 'ilike', row.get('Vendor'))], limit=1) + tax = self.env['account.tax'].search([('name', 'ilike', row.get('Tax'))], limit=1) + product_category = self.env['product.category'].search([('name', 'ilike', row.get('Product Category'))], limit=1) + + vals = { + 'order_id': self.order_id.id, + 'product_name': row.get('Nama Barang'), + 'code': row.get('SKU'), + 'budget': row.get('Expected Price'), + 'note': row.get('Note Sourcing'), + 'brand': row.get('Brand'), + 'descriptions': row.get('Deskripsi / Spesifikasi'), + 'sla': row.get('SLA Product'), + 'quantity': float(row.get('Quantity Product') or 1.0), + 'price': float(row.get('Purchase Price') or 0.0), + 'vendor_id': vendor.id if vendor else False, + 'tax_id': tax.id if tax else False, + 'product_category': product_category.id if product_category else False, + 'product_type': row.get('Product Type') or 'product', + # 'product_class': [(6, 0, classes.ids)], + } + + print("Create line with:", vals) # 🧪 Debug log + self.env['sourcing.job.order.line'].create(vals) + lines_created += 1 + + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'title': 'Import Selesai', + 'message': f'{lines_created} baris berhasil diimport.', + 'type': 'success', + 'sticky': False, + } } \ 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 7e1051bc..840fe869 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -216,5 +216,6 @@ access_sj_tele,access.sj.tele,model_sj_tele,base.group_system,1,1,1,1 access_sourcing_job_order,access.sourcing_job_order,model_sourcing_job_order,base.group_system,1,1,1,1 access_sourcing_job_order_line_user,sourcing.job.order.line,model_sourcing_job_order_line,base.group_user,1,1,1,1 access_sourcing_reject_wizard,sourcing.reject.wizard,model_sourcing_reject_wizard,base.group_user,1,1,1,1 +access_sourcing_job_order_line_import_wizard,sourcing.job.order.line.import.wizard,model_sourcing_job_order_line_import_wizard,base.group_user,1,1,1,1 access_wizard_export_sjo_to_so,wizard.export.sjo.to.so,model_wizard_export_sjo_to_so,base.group_user,1,1,1,1 access_stock_picking_sj_document,stock.picking.sj.document,model_stock_picking_sj_document,base.group_user,1,1,1,1 diff --git a/indoteknik_custom/views/sourcing.xml b/indoteknik_custom/views/sourcing.xml index 1e16b513..cc04b498 100644 --- a/indoteknik_custom/views/sourcing.xml +++ b/indoteknik_custom/views/sourcing.xml @@ -49,6 +49,33 @@ + + sourcing.job.order.line.import.wizard.form + sourcing.job.order.line.import.wizard + +
+ + + + +
+ +
+
+
+
+ + + Import SJO Line + sourcing.job.order.line.import.wizard + form + new + + wizard.export.sjo.to.so.form wizard.export.sjo.to.so @@ -75,6 +102,8 @@
+