Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Owo Sugiana
/
warga
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2e7f07e1
authored
May 24, 2023
by
Owo Sugiana
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Tambah RT dan RW
1 parent
9c01dd1c
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
160 additions
and
4 deletions
README.rst
warga/__manifest__.py
warga/models/__init__.py
warga/models/res_company.py
warga/models/res_partner.py
warga/views/res_company.xml
warga/views/res_partner.xml
README.rst
View file @
2e7f07e
...
...
@@ -2,3 +2,8 @@ Catat Warga
===========
Modul Odoo untuk pencatatan warga. Aplikasi untuk Ketua RT.
Berikut rencananya:
1. Company adalah RT
2. Setiap user bisa menangani beberapa company (bawaan Odoo)
warga/__manifest__.py
View file @
2e7f07e
...
...
@@ -9,6 +9,7 @@
'wilayah'
,
],
'data'
:
[
'views/res_company.xml'
,
'views/res_partner.xml'
]
}
warga/models/__init__.py
View file @
2e7f07e
from
.
import
res_partner
from
.
import
(
res_partner
,
res_company
,
)
warga/models/res_company.py
0 → 100644
View file @
2e7f07e
from
odoo
import
(
models
,
fields
,
api
,
)
from
odoo.exceptions
import
ValidationError
class
Company
(
models
.
Model
):
_inherit
=
'res.company'
kabupaten_id
=
fields
.
Many2one
(
'kabupaten'
,
string
=
'Kabupaten'
,
ondelete
=
'restrict'
,
domain
=
"[('state_id', '=?', state_id)]"
)
kecamatan_id
=
fields
.
Many2one
(
'kecamatan'
,
string
=
'Kecamatan'
,
ondelete
=
'restrict'
,
domain
=
"[('kabupaten_id', '=?', kabupaten_id)]"
)
kelurahan_id
=
fields
.
Many2one
(
'kelurahan'
,
string
=
'Kelurahan'
,
ondelete
=
'restrict'
,
domain
=
"[('kecamatan_id', '=?', kecamatan_id)]"
)
rw
=
fields
.
Char
()
rt
=
fields
.
Char
()
@api.onchange
(
'country_id'
)
def
_onchange_country_id
(
self
):
if
self
.
country_id
:
self
.
currency_id
=
self
.
country_id
.
currency_id
if
self
.
country_id
!=
self
.
state_id
.
country_id
:
self
.
state_id
=
False
else
:
self
.
state_id
=
False
@api.onchange
(
'state_id'
)
def
_onchange_state
(
self
):
if
self
.
state_id
:
self
.
country_id
=
self
.
state_id
.
country_id
if
self
.
state_id
!=
self
.
kabupaten_id
.
state_id
:
self
.
kabupaten_id
=
False
else
:
self
.
kabupaten_id
=
False
@api.onchange
(
'kabupaten_id'
)
def
_onchange_kabupaten_id
(
self
):
if
self
.
kabupaten_id
:
self
.
state_id
=
self
.
kabupaten_id
.
state_id
self
.
city
=
self
.
kabupaten_id
.
name
if
self
.
kabupaten_id
!=
self
.
kecamatan_id
.
kabupaten_id
:
self
.
kecamatan_id
=
False
else
:
self
.
kecamatan_id
=
False
self
.
city
=
False
@api.onchange
(
'kecamatan_id'
)
def
_onchange_kecamatan_id
(
self
):
if
self
.
kecamatan_id
:
self
.
kabupaten_id
=
self
.
kecamatan_id
.
kabupaten_id
if
self
.
kecamatan_id
!=
self
.
kelurahan_id
.
kecamatan_id
:
self
.
kelurahan_id
=
False
else
:
self
.
kelurahan_id
=
False
@api.onchange
(
'kelurahan_id'
)
def
_onchange_kelurahan_id
(
self
):
if
self
.
kelurahan_id
:
self
.
kecamatan_id
=
self
.
kelurahan_id
.
kecamatan_id
@api.onchange
(
'rw'
)
def
_onchange_rw
(
self
):
if
self
.
rw
:
try
:
n
=
int
(
self
.
rw
)
if
1
<=
n
<=
999
:
self
.
rw
=
str
(
n
)
return
except
ValueError
:
pass
raise
ValidationError
(
'RW harus angka 1 - 999'
)
@api.onchange
(
'rt'
)
def
_onchange_rt
(
self
):
if
self
.
rt
:
try
:
n
=
int
(
self
.
rt
)
if
1
<=
n
<=
999
:
self
.
rt
=
str
(
n
)
return
except
ValueError
:
pass
raise
ValidationError
(
'RT harus angka 1 - 999'
)
warga/models/res_partner.py
View file @
2e7f07e
...
...
@@ -3,9 +3,10 @@ from odoo import (
fields
,
api
,
)
from
odoo.exceptions
import
ValidationError
class
Res
Partner
(
models
.
Model
):
class
Partner
(
models
.
Model
):
_inherit
=
'res.partner'
kabupaten_id
=
fields
.
Many2one
(
...
...
@@ -17,10 +18,15 @@ class ResPartner(models.Model):
kelurahan_id
=
fields
.
Many2one
(
'kelurahan'
,
string
=
'Kelurahan'
,
ondelete
=
'restrict'
,
domain
=
"[('kecamatan_id', '=?', kecamatan_id)]"
)
rw
=
fields
.
Char
()
rt
=
fields
.
Char
()
@api.onchange
(
'country_id'
)
def
_onchange_country_id
(
self
):
if
self
.
country_id
and
self
.
country_id
!=
self
.
state_id
.
country_id
:
if
self
.
country_id
:
if
self
.
country_id
!=
self
.
state_id
.
country_id
:
self
.
state_id
=
False
else
:
self
.
state_id
=
False
@api.onchange
(
'state_id'
)
...
...
@@ -56,3 +62,27 @@ class ResPartner(models.Model):
def
_onchange_kelurahan_id
(
self
):
if
self
.
kelurahan_id
:
self
.
kecamatan_id
=
self
.
kelurahan_id
.
kecamatan_id
@api.onchange
(
'rw'
)
def
_onchange_rw
(
self
):
if
self
.
rw
:
try
:
n
=
int
(
self
.
rw
)
if
1
<=
n
<=
999
:
self
.
rw
=
str
(
n
)
return
except
ValueError
:
pass
raise
ValidationError
(
'RW harus angka 1 - 999'
)
@api.onchange
(
'rt'
)
def
_onchange_rt
(
self
):
if
self
.
rt
:
try
:
n
=
int
(
self
.
rt
)
if
1
<=
n
<=
999
:
self
.
rt
=
str
(
n
)
return
except
ValueError
:
pass
raise
ValidationError
(
'RT harus angka 1 - 999'
)
warga/views/res_company.xml
0 → 100644
View file @
2e7f07e
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record
model=
"ir.ui.view"
id=
"view_rt_form"
>
<field
name=
"name"
>
res.rt.form
</field>
<field
name=
"model"
>
res.company
</field>
<field
name=
"inherit_id"
ref=
"base.view_company_form"
/>
<field
name=
"type"
>
form
</field>
<field
name=
"arch"
type=
"xml"
>
<xpath
expr=
"//field[@name='city']"
position=
"attributes"
>
<attribute
name=
"invisible"
>
1
</attribute>
</xpath>
<field
name=
"state_id"
position=
"before"
>
<label
for=
"rt"
string=
"RT"
attrs=
"{'invisible': [('rt', '=', False)]}"
/>
<field
name=
"rt"
placeholder=
"RT"
class=
"o_address_zip"
/>
<label
for=
"rw"
string=
"RW"
attrs=
"{'invisible': [('rw', '=', False)]}"
/>
<field
name=
"rw"
placeholder=
"RW"
class=
"o_address_zip"
/>
<field
name=
"kelurahan_id"
placeholder=
"Kelurahan"
/>
<field
name=
"kecamatan_id"
placeholder=
"Kecamatan"
/>
<field
name=
"kabupaten_id"
placeholder=
"Kota / Kabupaten"
/>
</field>
</field>
</record>
</data>
</odoo>
warga/views/res_partner.xml
View file @
2e7f07e
...
...
@@ -10,8 +10,11 @@
<xpath
expr=
"//field[@name='city']"
position=
"attributes"
>
<attribute
name=
"invisible"
>
1
</attribute>
</xpath>
<field
name=
"street2"
invisible=
"1"
/>
<field
name=
"state_id"
position=
"before"
>
<label
for=
"rt"
string=
"RT"
attrs=
"{'invisible': [('rt', '=', False)]}"
/>
<field
name=
"rt"
placeholder=
"RT"
class=
"o_address_zip"
/>
<label
for=
"rw"
string=
"RW"
attrs=
"{'invisible': [('rw', '=', False)]}"
/>
<field
name=
"rw"
placeholder=
"RW"
class=
"o_address_zip"
/>
<field
name=
"kelurahan_id"
placeholder=
"Kelurahan"
/>
<field
name=
"kecamatan_id"
placeholder=
"Kecamatan"
/>
<field
name=
"kabupaten_id"
placeholder=
"Kota / Kabupaten"
/>
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment