summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2025-11-20 13:45:39 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2025-11-20 13:45:39 +0700
commit7d90c2ae207338da07833a30324f1b07ece30e35 (patch)
treed40a00b5ac21097928700d2ee1e43adef5d078d8
parent53fc67b6d785c6bfe44422ce52647c5b9e72579b (diff)
<MIqdad> export line to excel
-rw-r--r--indoteknik_custom/models/sourcing_job_order.py69
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv1
2 files changed, 69 insertions, 1 deletions
diff --git a/indoteknik_custom/models/sourcing_job_order.py b/indoteknik_custom/models/sourcing_job_order.py
index 347429bb..b65d45bf 100644
--- a/indoteknik_custom/models/sourcing_job_order.py
+++ b/indoteknik_custom/models/sourcing_job_order.py
@@ -6,7 +6,7 @@ import logging
import pytz
from pytz import timezone
import base64
-import xlrd
+import xlrd, xlwt
import io
_logger = logging.getLogger(__name__)
@@ -1156,3 +1156,70 @@ class SourcingJobOrderLineImportWizard(models.TransientModel):
'sticky': False,
}
}
+
+class SourcingJobOrderLineExportWizard(models.TransientModel):
+ _name = 'sourcing.job.order.line.export.wizard'
+ _description = 'Export SJO Line Wizard'
+
+ order_id = fields.Many2one('sourcing.job.order', string="Sourcing Job Order", required=True)
+ file = fields.Binary("CSV File", readonly=True)
+ filename = fields.Char("Filename", readonly=True)
+
+ def action_export(self):
+ if not self.order_id:
+ raise UserError("Silakan pilih Sourcing Job Order terlebih dahulu.")
+
+ lines = self.env['sourcing.job.order.line'].search([('order_id', '=', self.order_id.id)])
+ wb = xlwt.Workbook()
+ sheet = wb.add_sheet("SJO Lines")
+
+ headers = [
+ 'Nama Barang', 'SKU', 'Expected Price', 'Note Sourcing', 'Brand',
+ 'Deskripsi / Spesifikasi', 'SLA Product', 'Quantity Product',
+ 'Purchase Price', 'Tax', 'Vendor', 'Product Category',
+ 'Categories', 'Product Type'
+ ]
+
+ # Write header
+ for col, header in enumerate(headers):
+ sheet.write(0, col, header)
+
+ for row_idx, line in enumerate(lines, start=1):
+ categories = '; '.join(line.product_class.mapped('name')) or ''
+ values = [
+ line.product_name or '',
+ line.code or '',
+ line.budget or '',
+ line.note or '',
+ line.brand or '',
+ line.descriptions or '',
+ line.sla or '',
+ line.quantity or 0,
+ line.price or 0,
+ line.tax_id.name if line.tax_id else '',
+ line.vendor_id.name if line.vendor_id else '',
+ line.product_category.name if line.product_category else '',
+ categories,
+ line.product_type or '',
+ ]
+ for col_idx, value in enumerate(values):
+ sheet.write(row_idx, col_idx, value)
+
+ # Save to binary
+ fp = io.BytesIO()
+ wb.save(fp)
+ fp.seek(0)
+ data = fp.read()
+ fp.close()
+
+ self.file = base64.b64encode(data)
+ self.filename = f"SJO_{self.order_id.name}_lines.xls" # Note: xlwt hanya mendukung .xls
+
+ return {
+ 'type': 'ir.actions.act_window',
+ 'res_model': self._name,
+ 'view_mode': 'form',
+ 'res_id': self.id,
+ 'target': 'new',
+ }
+
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 840fe869..04e3c2e3 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -217,5 +217,6 @@ access_sourcing_job_order,access.sourcing_job_order,model_sourcing_job_order,bas
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_sourcing_job_order_line_export_wizard,sourcing.job.order.line.export.wizard,model_sourcing_job_order_line_export_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