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
71
72
73
74
75
76
77
78
|
from odoo import models
class ResUsers(models.Model):
_inherit = 'res.users'
def api_single_response(self, res_user, with_detail=''):
config = self.env['ir.config_parameter']
product_pricelist_tier1 = int(config.get_param('product.pricelist.tier1'))
product_pricelist_tier2 = int(config.get_param('product.pricelist.tier2'))
product_pricelist_tier3 = int(config.get_param('product.pricelist.tier3'))
user_pricelist = res_user.property_product_pricelist
user_pricelist_id = user_pricelist.id if user_pricelist else False
pricelist_tier = False
if user_pricelist_id == product_pricelist_tier1: pricelist_tier = 'tier1'
if user_pricelist_id == product_pricelist_tier2: pricelist_tier = 'tier2'
if user_pricelist_id == product_pricelist_tier3: pricelist_tier = 'tier3'
data = {
'id': res_user.id,
'parent_id': res_user.parent_id.id or False,
'partner_id': res_user.partner_id.id,
'name': res_user.name,
'email': res_user.login,
'phone': res_user.phone or '',
'mobile': res_user.mobile or '',
'external': res_user.share,
'company': res_user.company_type == 'company',
'pricelist': pricelist_tier
}
if res_user.parent_id:
data.update({ 'company': res_user.parent_id.company_type == 'company' })
return data
def api_address_response(self, user):
data = {
'id': user.id,
'type': user.type or '',
'name': user.name or '',
'mobile': user.mobile or '',
'email': user.email or '',
'street': user.street or '',
'street2': user.street2 or '',
'city': None,
'district': None,
'sub_district': None,
'zip': user.zip or '',
'company_type_id': user.company_type_id.id or None,
'industry_id': user.industry_id.id or None,
'tax_name': user.nama_wajib_pajak or '',
'npwp': user.npwp or '',
'rajaongkir_city_id': user.kecamatan_id.rajaongkir_id or 0,
}
if user.kota_id:
data['city'] = {
'id': user.kota_id.id,
'name': user.kota_id.name
} or None
if user.kecamatan_id:
data['district'] = {
'id': user.kecamatan_id.id,
'name': user.kecamatan_id.name
}
if user.kelurahan_id:
data['sub_district'] = {
'id': user.kelurahan_id.id,
'name': user.kelurahan_id.name
}
return data
|