partner.py
3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from odoo import fields, models, api
ADDRESS_FIELDS = (
'street', 'street2', 'zip', 'city', 'state_id', 'country_id',
'village_id', 'sub_district_id', 'district_id'
)
class ResPartner(models.Model):
_inherit = 'res.partner'
# company_id = fields.Many2one('res.company', string="Company",
# default=lambda self: self.env.company.id
# if not self.company_id else False
# )
#
# country_id = fields.Many2one('res.country', string="Country",
# default=lambda self: self.env.company.country_id
# if not self.country_id else False
# )
# state_id = fields.Many2one('res.country.state', string="State",
# default=lambda self: self.env.company.state_id
# if not self.state_id else False
# )
#
district_id = fields.Many2one('res.district', string="Kabupaten/Kota",
ondelete='restrict', domain="[('state_id', '=?', state_id)]"
# default=lambda self: self.env.company.district_id
# if not self.district_id else False
)
sub_district_id = fields.Many2one('res.district.sub', string="Kecamatan",
ondelete='restrict', domain="[('district_id', '=?', district_id)]"
)
village_id = fields.Many2one('res.district.village', string="Desa/Kelurahan",
ondelete='restrict', domain="[('sub_district_id', '=?', sub_district_id)]"
)
@api.model
def _address_fields(self):
"""Returns the list of address fields that are synced from the parent."""
return list(ADDRESS_FIELDS)
@api.onchange('village_id')
def _onchange_village_id(self):
if self.village_id and self.village_id.sub_district_id != self.sub_district_id:
self.sub_district_id = self.village_id.sub_district_id
if self.village_id and self.village_id.zip and self.village_id.zip != self.zip:
self.zip = self.village_id.zip
@api.onchange('sub_district_id')
def _onchange_sub_district_id(self):
if self.sub_district_id and self.sub_district_id.district_id != self.district_id:
self.district_id = self.sub_district_id.district_id
if not self.sub_district_id or self.sub_district_id != self.village_id.sub_district_id:
self.village_id = False
@api.onchange('district_id')
def _onchange_district_id(self):
if self.district_id and self.district_id.state_id != self.state_id:
self.state_id = self.district_id.state_id
if not self.district_id or self.district_id != self.sub_district_id.district_id:
self.sub_district_id = False
@api.onchange('state_id')
def _onchange_state_id(self):
if not self.state_id or self.state_id != self.district_id.state_id:
self.district_id = False
# from . import company