Commit 2e7f07e1 by Owo Sugiana

Tambah RT dan RW

1 parent 9c01dd1c
......@@ -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)
......@@ -9,6 +9,7 @@
'wilayah',
],
'data': [
'views/res_company.xml',
'views/res_partner.xml'
]
}
from . import res_partner
from . import (
res_partner,
res_company,
)
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')
......@@ -3,9 +3,10 @@ from odoo import (
fields,
api,
)
from odoo.exceptions import ValidationError
class ResPartner(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')
<?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>
......@@ -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"/>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!