Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ms_pemeriksaan.py 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. from odoo import api, fields, models
  2. from datetime import datetime
  3. class ms_pemeriksaan(models.Model):
  4. _name = "ms.pemeriksaan"
  5. _description = "Pemeriksaan"
  6. _order = "name desc"
  7. @api.one
  8. @api.depends('pasien_id')
  9. def _get_usia(self):
  10. usia = False
  11. if self.pasien_id :
  12. usia = datetime.now().year - datetime.strptime(self.pasien_id.tgl_lahir , '%Y-%m-%d').year
  13. self.usia = usia
  14. name = fields.Char(string='Pemeriksaan', default='/')
  15. state = fields.Selection([
  16. ('draft','Draft'),
  17. ('confirm','Confirmed'),
  18. ('cancel','Cancelled')
  19. ], string='State', default='draft')
  20. pendaftaran_id = fields.Many2one('ms.pendaftaran', 'Pendaftaran')
  21. tanggal = fields.Datetime(string='Tanggal', default=fields.Datetime.now())
  22. pasien_id = fields.Many2one(related='pendaftaran_id.pasien_id', string='Pasien')
  23. jenis_kelamin = fields.Selection(related='pendaftaran_id.pasien_id.jenis_kelamin', string='Jenis Kelamin')
  24. usia = fields.Integer(compute='_get_usia', string='Usia')
  25. poli_id = fields.Many2one(related='pendaftaran_id.poli_id', string='Poli')
  26. dokter_id = fields.Many2one('res.partner', string='Dokter')
  27. keluhan = fields.Text(string='Keluhan')
  28. hasil = fields.Text(string='Hasil Pemeriksaan')
  29. tindakan = fields.Text(string='Tindakan Pengobatan')
  30. resep_line = fields.One2many('ms.resep.obat', 'pemeriksaan_id', 'Resep Obat')
  31. @api.model
  32. def create(self, vals):
  33. vals['name'] = self.env['ir.sequence'].get_sequence('Pemeriksaan','ms.pemeriksaan','PMR/%(y)s/',5)
  34. return super(ms_pemeriksaan, self).create(vals)
  35. @api.multi
  36. def action_confirm(self):
  37. for me_id in self :
  38. if me_id.state == 'draft':
  39. inv_line_vals = []
  40. for line in me_id.resep_line :
  41. inv_line_vals.append((0,0,{
  42. 'product_id': line.product_id.id,
  43. 'name': line.product_id.name_get()[0][1],
  44. 'quantity': line.qty,
  45. 'price_unit': line.product_id.lst_price,
  46. 'account_id': me_id.pasien_id.property_account_payable_id.id,
  47. }))
  48. self.env['account.invoice'].create({
  49. 'partner_id': me_id.pasien_id.id,
  50. 'invoice_line_ids': inv_line_vals,
  51. })
  52. me_id.write({'state':'confirm'})
  53. @api.multi
  54. def action_cancel(self):
  55. view_id = self.env.ref('ms_puskesmas.view_ms_reason_cancel_wizard')
  56. return {
  57. 'name': 'Reason Cancel',
  58. 'type': 'ir.actions.act_window',
  59. 'view_type': 'form',
  60. 'view_mode': 'form',
  61. 'res_model': 'ms.reason.cancel.wizard',
  62. 'views': [(view_id.id, 'form')],
  63. 'view_id': view_id.id,
  64. 'target': 'new',
  65. }
  66. @api.multi
  67. def unlink(self):
  68. for me_id in self :
  69. if me_id.state != 'draft' :
  70. raise Warning("Tidak bisa menghapus data pendaftaran yang bukan draft !")
  71. return super(ms_pemeriksaan, self).unlink()
  72. class ms_resep_obat(models.Model):
  73. _name = "ms.resep.obat"
  74. _description = "Resep Obat"
  75. _rec_name = "product_id"
  76. pemeriksaan_id = fields.Many2one('ms.pemeriksaan', 'Pemeriksaan')
  77. product_id = fields.Many2one('product.product', 'Obat', required="1")
  78. aturan_minum = fields.Char('Aturan Minum')
  79. waktu_minum = fields.Selection([
  80. ('sebelum','Sebelum'),
  81. ('sesudah','Sesudah'),
  82. ], 'Sebelum/Sesudah Makan', default='sesudah')
  83. qty = fields.Float('Quantity')
  84. satuan_id = fields.Many2one('product.uom', 'Satuan')
  85. @api.onchange('product_id')
  86. def change_product(self):
  87. if self.product_id :
  88. self.satuan_id = self.product_id.uom_id.id