30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
from odoo import models, fields, api
|
|
|
|
class ClinicAppointment(models.Model):
|
|
_name = 'clinic.appointment'
|
|
_description = 'Lịch hẹn'
|
|
_rec_name = 'patient_id'
|
|
|
|
patient_id = fields.Many2one('clinic.patient', string='Bệnh nhân', required=True)
|
|
doctor_id = fields.Many2one('res.partner', string='Bác sĩ', required=True)
|
|
date = fields.Date(string='Ngày kê đơn', default=fields.Date.today)
|
|
state = fields.Selection([
|
|
('scheduled', 'Đã lên lịch'),
|
|
('done', 'Hoàn thành'),
|
|
('cancel', 'Hủy')
|
|
], string='Trạng thái', default='scheduled')
|
|
|
|
services_ids = fields.Many2many('clinic.service', string='Dịch vụ khám')
|
|
total_price = fields.Float(string='Tổng tiền', compute='_compute_total_price')
|
|
|
|
def action_scheduled(self):
|
|
self.state = 'scheduled'
|
|
def action_done(self):
|
|
self.state = 'done'
|
|
def action_cancel(self):
|
|
self.state = 'cancel'
|
|
|
|
@api.depends('services_ids')
|
|
def _compute_total_price(self):
|
|
for rec in self:
|
|
rec.total_price = sum(rec.services_ids.mapped('price')) |