diff options
| author | Mqdd <ahmadmiqdad27@gmail.com> | 2025-11-19 15:32:29 +0700 |
|---|---|---|
| committer | Mqdd <ahmadmiqdad27@gmail.com> | 2025-11-19 15:32:29 +0700 |
| commit | 527165ae245fa7301de1a767f5e09865ec8aeade (patch) | |
| tree | 4dcea9bc903f42a4a894fa8bf69a4f0b42116d20 | |
| parent | 6ec6f33cc2579be1b926371f11fffe0c9f5ddad0 (diff) | |
<Miqdad> import
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/sourcing_job_order.py | 65 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 1 | ||||
| -rw-r--r-- | indoteknik_custom/views/sourcing.xml | 29 |
4 files changed, 96 insertions, 1 deletions
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 @@ </field> </record> + <record id="view_sjo_line_import_wizard_form" model="ir.ui.view"> + <field name="name">sourcing.job.order.line.import.wizard.form</field> + <field name="model">sourcing.job.order.line.import.wizard</field> + <field name="arch" type="xml"> + <form string="Import SJO Line"> + <group> + <field name="order_id"/> + <field name="file" filename="filename"/> + </group> + <footer> + <!-- TOMBOL YANG PENTING: Ini yang akan memanggil def action_import --> + <button name="action_import" type="object" string="Import" class="btn-primary"/> + + <!-- Tombol cancel seperti biasa --> + <button string="Cancel" special="cancel" class="btn-secondary"/> + </footer> + </form> + </field> + </record> + + <record id="action_sjo_line_import_wizard" model="ir.actions.act_window"> + <field name="name">Import SJO Line</field> + <field name="res_model">sourcing.job.order.line.import.wizard</field> + <field name="view_mode">form</field> + <field name="target">new</field> + </record> + <record id="view_wizard_export_sjo_to_so_form" model="ir.ui.view"> <field name="name">wizard.export.sjo.to.so.form</field> <field name="model">wizard.export.sjo.to.so</field> @@ -75,6 +102,8 @@ <field name="arch" type="xml"> <form string="Sourcing Job Order"> <header> + <button name="%(indoteknik_custom.action_sjo_line_import_wizard)d" string="Import Line" type="action" context="{'default_order_id': active_id}" class="btn-secondary"/> + <button name="action_take" string="Take" type="object" |
