summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2025-11-19 15:32:29 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2025-11-19 15:32:29 +0700
commit527165ae245fa7301de1a767f5e09865ec8aeade (patch)
tree4dcea9bc903f42a4a894fa8bf69a4f0b42116d20 /indoteknik_custom/models
parent6ec6f33cc2579be1b926371f11fffe0c9f5ddad0 (diff)
<Miqdad> import
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/sourcing_job_order.py65
1 files changed, 65 insertions, 0 deletions
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