Compare commits

..

2 Commits

14 changed files with 233 additions and 3 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,4 @@
.env .env
config/odoo.conf config/odoo.conf
addons/
*.log *.log
.DS_Store .DS_Store

View File

@@ -73,7 +73,22 @@ Addon kustom dalam folder `./addons/kosbar_erp_ext/` menyediakan:
--- ---
## 4. Struktur Database Utama (PostgreSQL) ## 4. Product Category Code & Item Code
### Field Baru (Auto-generated):
* **Category Code** (`product.category.code`)
- 2 digit berdasarkan ID kategori
- Contoh: ID=1 → `01`, ID=7 → `07`, ID=10 → `10`
* **Item Code** (`product.template.item_code`)
- Kombinasi: `parent_kode` (2 digit) + `kategori_kode` (2 digit) + `id_produk` (4 digit) + `nama_slug` (lowercase, tanpa spasi)
- Contoh: Kategori `05` (anak dari `01`), Produk ID=1, nama="Laptop ASUS"
- → `item_code = 01050001laptopasus`
- *Item Code otomatis diisi saat produk dibuat/diupdate.*
---
## 5. Struktur Database Utama (PostgreSQL)
Tabel inti Odoo 19 yang digunakan dalam alur di atas: Tabel inti Odoo 19 yang digunakan dalam alur di atas:
@@ -99,7 +114,7 @@ Tabel inti Odoo 19 yang digunakan dalam alur di atas:
--- ---
## 5. Perintah Manajemen Docker ## 6. Perintah Manajemen Docker
* **Menjalankan stack:** * **Menjalankan stack:**
```bash ```bash

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,15 @@
{
'name': 'Kos Barokah ERP Extension',
'version': '1.0',
'category': 'Sales',
'summary': 'Grup akses, Custom Sales/DO Sequence',
'depends': ['sale_management', 'sales_team', 'stock', 'purchase', 'crm'],
'data': [
'security/res_groups.xml',
'security/ir.model.access.csv',
'data/ir_sequence.xml',
'data/stock_picking_type.xml',
],
'installable': True,
'application': False,
}

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- Quotation Sequence: SQ/2026/00001 -->
<record id="seq_quotation" model="ir.sequence">
<field name="name">Quotation Kos Barokah</field>
<field name="code">sale.quotation.custom</field>
<field name="padding">5</field>
<field name="prefix">SQ/%(year)s/</field>
<field name="company_id" eval="False"/>
</record>
<!-- Sales Order Sequence: SO/2026/00001 -->
<record id="seq_sales_order" model="ir.sequence">
<field name="name">Sales Order Kos Barokah</field>
<field name="code">sale.order.custom</field>
<field name="padding">5</field>
<field name="prefix">SO/%(year)s/</field>
<field name="company_id" eval="False"/>
</record>
<!-- Delivery Order Sequence: DO/2026/00001 -->
<record id="seq_delivery_order" model="ir.sequence">
<field name="name">Delivery Order Kos Barokah</field>
<field name="code">stock.picking.do</field>
<field name="padding">5</field>
<field name="prefix">DO/%(year)s/</field>
<field name="company_id" eval="False"/>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- Delivery Orders memakai sequence DO/2026/00001 -->
<record id="stock.picking_type_out" model="stock.picking.type">
<field name="sequence_id" ref="kosbar_erp_ext.seq_delivery_order"/>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,4 @@
from . import sale_order
from . import stock_picking
from . import product_category
from . import product_template

View File

@@ -0,0 +1,19 @@
from odoo import models, fields, api
class ProductCategory(models.Model):
_inherit = 'product.category'
code = fields.Char(
string='Category Code',
size=10,
help='Kode 2-digit otomatis dari ID kategori (contoh ID 1 -> "01")',
)
@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
for r in records:
if not r.code:
r.code = f'{r.id:02d}'
return records

View File

@@ -0,0 +1,56 @@
import re
from odoo import models, fields, api
from odoo.exceptions import ValidationError
class ProductTemplate(models.Model):
_inherit = 'product.template'
item_code = fields.Char(
string='Item Code',
index=True,
help='Kombinasi: parent_kode + kategori_kode + id_produk(4digit) + nama_produk_tanpa_spasi(lower)',
)
@api.constrains('item_code')
def _check_item_code_unique(self):
for rec in self:
if not rec.item_code:
continue
dup = self.search([('item_code', '=', rec.item_code), ('id', '!=', rec.id)], limit=1)
if dup:
raise ValidationError(
f'Item Code "{rec.item_code}" sudah dipakai oleh produk lain '
f'({dup.name}). Item Code harus unik.'
)
def _generate_item_code(self):
"""Generate item_code: parent_code + cat_code + id:04d + name_slug"""
for p in self:
cat = p.categ_id
parent_code = ''
cat_code = '00'
if cat:
# Pastikan kategori punya code (calculate jika belum ada)
if not cat.code:
cat.code = f'{cat.id:02d}'
parent_code = cat.parent_id.code if cat.parent_id else ''
cat_code = cat.code
# slug: lowercase, remove semua spasi
name_slug = re.sub(r'\s+', '', (p.name or '').lower())
p.item_code = f'{parent_code}{cat_code}{p.id:04d}{name_slug}'
@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
records._generate_item_code()
return records
def write(self, vals):
res = super().write(vals)
if 'name' in vals or 'categ_id' in vals:
self._generate_item_code()
return res

View File

@@ -0,0 +1,29 @@
from odoo import models, fields, api
class SaleOrder(models.Model):
_inherit = 'sale.order'
def _get_quotation_sequence_id(self):
return self.env.ref('kosbar_erp_ext.seq_quotation').sudo()
def _get_sales_order_sequence_id(self):
return self.env.ref('kosbar_erp_ext.seq_sales_order').sudo()
def _get_delivery_sequence_id(self):
return self.env.ref('kosbar_erp_ext.seq_delivery_order').sudo()
def action_confirm(self):
"""Override confirmation to change number from SQ to SO."""
for order in self:
# Quotation (draft) should have SQ prefix; confirm -> SO
seq = self._get_sales_order_sequence_id()
order.name = seq.with_date(order.date_order or fields.Date.context_today(self)).next_by_code()
return super().action_confirm()
@api.model
def create(self, vals):
"""When creating a quotation (draft), use SQ sequence."""
if vals.get('state') == 'draft' and not vals.get('name'):
seq = self._get_quotation_sequence_id()
vals['name'] = seq.with_date(vals.get('date_order') or fields.Date.context_today(self)).next_by_code()
return super().create(vals)

View File

@@ -0,0 +1,10 @@
from odoo import models, api, fields
class StockPicking(models.Model):
_inherit = 'stock.picking'
@api.model
def create(self, vals):
"""Delivery order (outgoing) memakai sequence DO/2026/00001 dari
picking type sequence_id yang sudah diarahkan ke seq_delivery_order."""
return super().create(vals)

View File

@@ -0,0 +1 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- Group Sales Manager -->
<record id="group_sales_manager" model="res.groups">
<field name="name">Sales Manager</field>
<field name="implied_ids" eval="[(4, ref('sales_team.group_sale_salesman_all_leads'))]"/>
</record>
<!-- Group CFO -->
<record id="group_cfo" model="res.groups">
<field name="name">CFO / Finance Director</field>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,25 @@
import re
# Migration: isi code kategori & item_code produk untuk data existing
env.cr.execute(
"CREATE UNIQUE INDEX IF NOT EXISTS product_template_item_code_uniq "
"ON product_template (item_code) WHERE item_code IS NOT NULL"
)
env.cr.commit()
cats = env['product.category'].search([])
for c in cats:
if not c.code:
c.code = f'{c.id:02d}'
env.cr.commit()
print(f'Kategori di-update: {len(cats)}')
prods = env['product.template'].search([])
for p in prods:
p._generate_item_code()
env.cr.commit()
print(f'Produk di-update: {len(prods)}')
# Verifikasi contoh
for p in prods[:5]:
print(f' {p.name!r} -> {p.item_code!r}')