Files
odoo-erp/templates/generate_templates.py

61 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Generate template Excel untuk import produk & kategori Odoo."""
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment
HEADER_FILL = PatternFill('solid', fgColor='0B6E4F')
HEADER_FONT = Font(bold=True, color='FFFFFF')
def styled_header(ws, headers):
ws.append(headers)
for cell in ws[1]:
cell.fill = HEADER_FILL
cell.font = HEADER_FONT
cell.alignment = Alignment(horizontal='center')
# ---------- 1. Template Produk ----------
wb = Workbook()
ws = wb.active
ws.title = 'Products'
styled_header(ws, ['Product Name', 'Product Category', 'Sales Price', 'Cost', 'Barcode'])
rows = [
['iPhone 15 128GB', 'Smartphone', 15000000, 12000000, 1234567890123],
['Samsung Galaxy S24', 'Smartphone', 14000000, 11000000, 1234567890124],
['MacBook Air M2', 'Laptop', 25000000, 20000000, 1234567890125],
['Wireless Mouse', 'Mouse', 500000, 350000, 1234567890126],
['Mechanical Keyboard', 'Keyboard', 750000, 500000, 1234567890127],
]
for r in rows:
ws.append(r)
widths = [22, 18, 13, 13, 16]
for i, w in enumerate(widths, 1):
ws.column_dimensions[chr(64 + i)].width = w
wb.save('/home/ardhi/Application/odoo-erp/templates/import-products.xlsx')
print('OK: import-products.xlsx')
# ---------- 2. Template Kategori ----------
wb2 = Workbook()
ws2 = wb2.active
ws2.title = 'Categories'
styled_header(ws2, ['Nama Kategori', 'Parent Category'])
cat_rows = [
['Elektronik', ''],
['Smartphone', 'Elektronik'],
['Laptop', 'Elektronik'],
['Aksesoris', ''],
['Mouse', 'Aksesoris'],
['Keyboard', 'Aksesoris'],
]
for r in cat_rows:
ws2.append(r)
ws2.column_dimensions['A'].width = 22
ws2.column_dimensions['B'].width = 22
wb2.save('/home/ardhi/Application/odoo-erp/templates/import-product-categories.xlsx')
print('OK: import-product-categories.xlsx')