summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sourcing_job_order.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/sourcing_job_order.py')
-rw-r--r--indoteknik_custom/models/sourcing_job_order.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/indoteknik_custom/models/sourcing_job_order.py b/indoteknik_custom/models/sourcing_job_order.py
index b65d45bf..d50256b4 100644
--- a/indoteknik_custom/models/sourcing_job_order.py
+++ b/indoteknik_custom/models/sourcing_job_order.py
@@ -118,6 +118,16 @@ class SourcingJobOrder(models.Model):
now_jakarta = datetime.now(jakarta_tz)
return now_jakarta.date()
+ def action_open_download_template(self):
+ wizard = self.env['sourcing.job.order.line.template.wizard'].create({})
+ return {
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'sourcing.job.order.line.template.wizard',
+ 'view_mode': 'form',
+ 'res_id': wizard.id, # ✅ ini WAJIB supaya file bisa didownload
+ 'target': 'new',
+ }
+
@api.depends('eta_sales', 'eta_complete', 'create_date', 'state')
def _compute_progress_status(self):
for rec in self:
@@ -1111,7 +1121,7 @@ class SourcingJobOrderLineImportWizard(models.TransientModel):
# Relations
tax = Tax.search([('name', 'ilike', val('Tax'))], limit=1)
- vendor = Vendor.search([('name', '=', val('Vendor'))], limit=1)
+ vendor = Vendor.search([('name', 'ilike', val('Vendor'))], limit=1)
category = Category.search([('name', 'ilike', val('Product Category'))], limit=1)
# Many2many: Categories
@@ -1223,3 +1233,29 @@ class SourcingJobOrderLineExportWizard(models.TransientModel):
'target': 'new',
}
+
+class SourcingJobOrderLineTemplateWizard(models.TransientModel):
+ _name = 'sourcing.job.order.line.template.wizard'
+ _description = 'Download Template SJO Line'
+
+ file = fields.Binary("File", readonly=True)
+ filename = fields.Char("Filename", readonly=True)
+
+ def action_generate_template(self):
+ res = super().default_get(fields)
+ output = io.BytesIO()
+ wb = xlwt.Workbook()
+ ws = wb.add_sheet('Template')
+
+ headers = ['Nama Barang', 'SKU', 'Expected Price']
+ for idx, header in enumerate(headers):
+ ws.write(0, idx, header)
+
+ wb.save(output)
+ output.seek(0)
+
+ res.update({
+ 'file': base64.b64encode(output.read()),
+ 'filename': 'sjo_template.xls',
+ })
+ return res \ No newline at end of file