summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indoteknik_api/controllers/api_v1/partner.py11
-rw-r--r--indoteknik_api/models/res_users.py1
-rw-r--r--indoteknik_custom/models/res_partner.py46
3 files changed, 45 insertions, 13 deletions
diff --git a/indoteknik_api/controllers/api_v1/partner.py b/indoteknik_api/controllers/api_v1/partner.py
index 69a2f861..4716173e 100644
--- a/indoteknik_api/controllers/api_v1/partner.py
+++ b/indoteknik_api/controllers/api_v1/partner.py
@@ -116,20 +116,25 @@ class Partner(controller.Controller):
def write_partner_by_id(self, **kw):
params = self.get_request_params(kw, {
'id': ['required', 'number'],
- 'name': [],
'company_type_id': ['number'],
'industry_id': ['number'],
'tax_name': ['alias:nama_wajib_pajak'],
'npwp': [],
+ 'alamat_lengkap_text':[],
+ })
+
+ id_user = self.get_request_params(kw, {
+ 'id_user': ['number']
})
if not params['valid']:
return self.response(code=400, description=params)
-
+
partner = request.env[self._name].search([('id', '=', params['value']['id'])], limit=1)
if not partner:
return self.response(code=404, description='User not found')
-
+
+ # Simpan perubahan data
partner.write(params['value'])
return self.response({
diff --git a/indoteknik_api/models/res_users.py b/indoteknik_api/models/res_users.py
index d5dff876..2c0a986b 100644
--- a/indoteknik_api/models/res_users.py
+++ b/indoteknik_api/models/res_users.py
@@ -55,6 +55,7 @@ class ResUsers(models.Model):
'tax_name': user.nama_wajib_pajak or '',
'npwp': user.npwp or '',
'rajaongkir_city_id': user.kecamatan_id.rajaongkir_id or 0,
+ 'alamat_wajib_pajak': user.alamat_lengkap_text or None,
}
if user.kota_id:
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py
index 6a1257f8..9f2c82e2 100644
--- a/indoteknik_custom/models/res_partner.py
+++ b/indoteknik_custom/models/res_partner.py
@@ -98,20 +98,46 @@ class ResPartner(models.Model):
alamat_lengkap = fields.Char(string="Alamat Lengkap", required=False, compute="_alamat_lengkap")
alamat_lengkap_text = fields.Text(string="Alamat Lengkap", required=False)
- def write(self, vals):
- res = super(ResPartner, self).write(vals)
-
- # if 'property_payment_term_id' in vals:
- # if not self.env.user.is_accounting and vals['property_payment_term_id'] != 26:
- # raise UserError('Hanya Finance Accounting yang dapat merubah payment term')
+ # def write(self, vals):
+ # res = super(ResPartner, self).write(vals)
+ #
+ # # if 'property_payment_term_id' in vals:
+ # # if not self.env.user.is_accounting and vals['property_payment_term_id'] != 26:
+ # # raise UserError('Hanya Finance Accounting yang dapat merubah payment term')
+ #
+ # # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id
+ # # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])])
+ # # if self.env.user.id not in users_in_group.mapped('id'):
+ # # raise UserError('You name it')
+ #
+ # return res
- # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id
- # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])])
- # if self.env.user.id not in users_in_group.mapped('id'):
- # raise UserError('You name it')
+ def write(self, vals):
+ if self.company_type == 'person':
+ if self.parent_id:
+ parent = self.parent_id
+ vals['customer_type'] = parent.customer_type
+ vals['nama_wajib_pajak'] = parent.nama_wajib_pajak
+ vals['npwp'] = parent.npwp
+ vals['sppkp'] = parent.sppkp
+ vals['alamat_lengkap_text'] = parent.alamat_lengkap_text
+ vals['industry_id'] = parent.industry_id.id
+ vals['company_type_id'] = parent.company_type_id.id
+ res = super(ResPartner, self).write(vals)
return res
+ @api.onchange('company_type')
+ def _onchange_company_type(self):
+ if self.company_type == 'person' and self.parent_id:
+ self.customer_type = self.parent_id.customer_type
+ self.npwp = self.parent_id.npwp
+ self.sppkp = self.parent_id.sppkp
+ self.nama_wajib_pajak = self.parent_id.nama_wajib_pajak
+ self.alamat_lengkap_text = self.parent_id.alamat_lengkap_text
+ self.industry_id = self.parent_id.industry_id.id
+ self.company_type_id = self.parent_id.company_type_id.id
+
@api.constrains('property_payment_term_id')
def updated_by_payment_term(self):
for rec in self: