説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

res_partner.py 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from odoo import api, fields, models
  2. class res_partner(models.Model):
  3. _inherit = "res.partner"
  4. dokter = fields.Boolean(string='Dokter')
  5. pasien = fields.Boolean(string='Pasien')
  6. kode = fields.Char(string='Kode', default='/')
  7. name = fields.Char(string='Nama')
  8. pekerjaan = fields.Selection([
  9. ('pelajar_mhs','Pelajar/Mahasiswa'),
  10. ('pegawai_negeri','Pegawai Negeri'),
  11. ('abri','ABRI'),
  12. ('swasta','Swasta'),
  13. ('lain','Lain-Lain'),
  14. ], string='Pekerjaan')
  15. nama_pekerjaan = fields.Char('Nama Pekerjaan')
  16. jenis_kelamin = fields.Selection([('laki','Laki-Laki'),('perempuan','Perempuan')], string='Jenis Kelamin')
  17. tgl_lahir = fields.Date('Tanggal Lahir')
  18. gol_darah = fields.Selection([
  19. ('a','A'),
  20. ('b','B'),
  21. ('ab','AB'),
  22. ('o','O'),
  23. ], string='Golongan Darah')
  24. status = fields.Selection([
  25. ('lajang','Lajang'),
  26. ('menikah','Menikah'),
  27. ('duda','Duda'),
  28. ('janda','Janda'),
  29. ], string='Status')
  30. history_pasien = fields.One2many('ms.pemeriksaan', 'pasien_id', 'History Pasien')
  31. history_dokter = fields.One2many('ms.pemeriksaan', 'dokter_id', 'History Dokter')
  32. _sql_constraints = [
  33. ('unique_kode', 'unique(kode,name)', 'Kombinasi kode dan nama sudah ada, mohon cek kembali !'),
  34. ]
  35. @api.model
  36. def create(self, vals):
  37. if vals.get('pasien', False):
  38. vals['kode'] = self.env['ir.sequence'].get_sequence('Kode Pasien','res.partner','PSN')
  39. elif vals.get('dokter', False) and ('kode' not in vals or vals.get('kode', False) == '/'):
  40. vals['kode'] = self.env['ir.sequence'].get_sequence('Kode Dokter','res.partner','DKT')
  41. return super(res_partner, self).create(vals)
  42. @api.multi
  43. def name_get(self):
  44. result = []
  45. for me_id in self :
  46. if me_id.kode and me_id.kode != '/' :
  47. result.append((me_id.id, "%s - %s" % (me_id.kode, me_id.name)))
  48. else :
  49. result.append((me_id.id, me_id.name))
  50. return result
  51. @api.model
  52. def name_search(self, name, args=None, operator='ilike', limit=100):
  53. args = args or []
  54. if name :
  55. recs = self.search([
  56. '|',
  57. ('kode', operator, name),
  58. ('name', operator, name),
  59. ] + args, limit=limit)
  60. else :
  61. recs = self.search([] + args, limit=limit)
  62. return recs.name_get()