No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ms_pendaftaran.py 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from odoo import api, fields, models
  2. from odoo.exceptions import Warning
  3. import unicodedata
  4. class ms_pendaftaran(models.Model):
  5. _name = "ms.pendaftaran"
  6. _description = "Pendaftaran"
  7. _order = "name desc"
  8. name = fields.Char(string='Pendaftaran', default='/')
  9. state = fields.Selection([
  10. ('draft','Draft'),
  11. ('confirm','Confirmed'),
  12. ('cancel','Cancelled')
  13. ], string='State', default='draft')
  14. pasien_id = fields.Many2one('res.partner', domain=[('pasien','=',True)], string='Pasien')
  15. poli_id = fields.Many2one('ms.poli', string='Poli yang Dituju')
  16. tanggal = fields.Datetime(string='Tanggal', default=fields.Datetime.now())
  17. note = fields.Html(string='Note')
  18. @api.model
  19. def create(self, vals):
  20. vals['name'] = self.env['ir.sequence'].get_sequence('Pendaftaran','ms.pendaftaran','DFT/%(y)s/',5)
  21. return super(ms_pendaftaran, self).create(vals)
  22. @api.multi
  23. def name_get(self):
  24. result = []
  25. for me_id in self :
  26. result.append((me_id.id, "%s - %s" % (me_id.name, me_id.pasien_id.name)))
  27. return result
  28. @api.model
  29. def name_search(self, name, args=None, operator='ilike', limit=100):
  30. args = args or []
  31. if name :
  32. recs = self.search([
  33. '|',
  34. ('pasien_id.name', operator, name),
  35. ('name', operator, name),
  36. ] + args, limit=limit)
  37. else :
  38. recs = self.search([] + args, limit=limit)
  39. return recs.name_get()
  40. @api.multi
  41. def action_confirm(self):
  42. for me_id in self :
  43. if me_id.state == 'draft':
  44. self.env['ms.pemeriksaan'].create({'pendaftaran_id':me_id.id})
  45. me_id.write({'state':'confirm'})
  46. @api.multi
  47. def action_cancel(self):
  48. for me_id in self :
  49. pemeriksaan_ids = self.env['ms.pemeriksaan'].search([
  50. ('pendaftaran_id','=',me_id.id),
  51. ('state','!=','cancel')
  52. ])
  53. if pemeriksaan_ids :
  54. pemeriksaan_names = [unicodedata.normalize('NFKD', pemeriksaan.name).encode('ascii','ignore') for pemeriksaan in pemeriksaan_ids]
  55. raise Warning("Silahkan cancel pemeriksaan %s terlebih dahulu !"%pemeriksaan_names)
  56. me_id.write({'state':'cancel'})
  57. @api.multi
  58. def unlink(self):
  59. for me_id in self :
  60. if me_id.state != 'draft' :
  61. raise Warning("Tidak bisa menghapus data pendaftaran yang bukan draft !")
  62. return super(ms_pendaftaran, self).unlink()