Compare commits
3 Commits
46e2d02908
...
b194ffb67b
| Author | SHA1 | Date | |
|---|---|---|---|
| b194ffb67b | |||
| 0c294b6d39 | |||
| 74fe09d603 |
@@ -50,7 +50,8 @@ class ProductTemplate(models.Model):
|
||||
return f'{parent_code}{own_code}'
|
||||
|
||||
def _name_slug(self, name):
|
||||
return re.sub(r'\s+', '', (name or '').lower())
|
||||
slug = (name or '').lower().replace(',', '.')
|
||||
return re.sub(r'\s+', '', slug)
|
||||
|
||||
def _full_item_code(self, obj):
|
||||
"""Compute full item_code: prefix kategori + id:04d + name_slug."""
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<!-- Product Template form: tampilkan Item Code read_only -->
|
||||
<!-- Product Template form: Item Code read_only -->
|
||||
<record id="view_product_template_item_code" model="ir.ui.view">
|
||||
<field name="name">product.template.form.item.code</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="product.product_template_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="default_code" position="after">
|
||||
<xpath expr="//field[@name='categ_id']" position="after">
|
||||
<field name="item_code" readonly="1"
|
||||
placeholder="Terisi otomatis dari kategori & nama"/>
|
||||
</field>
|
||||
placeholder="Terisi otomatis setelah simpan"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Product Variant form (product.product): Item Code read_only -->
|
||||
<!-- Product Variant/Master form: Item Code read_only -->
|
||||
<record id="view_product_product_item_code" model="ir.ui.view">
|
||||
<field name="name">product.product.form.item.code</field>
|
||||
<field name="model">product.product</field>
|
||||
<field name="inherit_id" ref="product.product_variant_easy_edit_view"/>
|
||||
<field name="inherit_id" ref="product.product_normal_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="default_code" position="after">
|
||||
<xpath expr="//field[@name='categ_id']" position="after">
|
||||
<field name="item_code" readonly="1"/>
|
||||
</field>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
24
templates/README-IMPORT.md
Normal file
24
templates/README-IMPORT.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Template Import Odoo
|
||||
|
||||
Folder ini berisi contoh file template untuk import master data ke Odoo ERP.
|
||||
|
||||
## Isi Folder
|
||||
| File | Kegunaan |
|
||||
|---|---|
|
||||
| `import-products.xlsx` | Template import produk (Product Name, Category, Price, Cost, Barcode) |
|
||||
| `import-product-categories.xlsx` | Template import kategori produk (Name + Parent Category) |
|
||||
| `import-product-categories.csv` | Versi CSV kategori (untuk referensi/format cepat) |
|
||||
|
||||
## Cara Pakai
|
||||
1. **Kategori dulu, baru Produk** (Produk butuh kategori yang sudah ada).
|
||||
2. Buka Odoo → **Inventory/Sales → Configuration → Product Categories** → tombol **Import**.
|
||||
- Petakan: `Nama Kategori` → `Name`, `Parent Category` → `Parent Category`.
|
||||
3. Setelah kategori masuk, `code` 2-digit otomatis terisi oleh addon.
|
||||
4. Buka **Inventory/Sales → Products → Products** → tombol **Import**.
|
||||
- Petakan: `Product Name` → `Name`, `Product Category` → `Product Category`, dll.
|
||||
5. **Jangan isi** kolom `Item Code`/`Internal Reference` — otomatis di-generate addon.
|
||||
- Format: `parent_code + child_code + product_id(4) + nama_lowercase_tanpa_spasi (koma → titik)`.
|
||||
|
||||
## Contoh hasil otomatis
|
||||
- Kategori `Elektronik` (code `01`), kategori `Laptop` (code `04`, parent `Elektronik`), produk `MacBook Air M2` (id `0001`):
|
||||
- `item_code = 01040001macbookairm2`
|
||||
60
templates/generate_templates.py
Normal file
60
templates/generate_templates.py
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/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')
|
||||
7
templates/import-product-categories.csv
Normal file
7
templates/import-product-categories.csv
Normal file
@@ -0,0 +1,7 @@
|
||||
Nama Kategori,Parent Category
|
||||
Elektronik,
|
||||
Smartphone,Electronics
|
||||
Laptop,Electronics
|
||||
Aksesoris,
|
||||
Mouse,Aksesoris
|
||||
Keyboard,Aksesoris
|
||||
|
BIN
templates/import-product-categories.xlsx
Normal file
BIN
templates/import-product-categories.xlsx
Normal file
Binary file not shown.
BIN
templates/import-products.xlsx
Normal file
BIN
templates/import-products.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user