from odoo import fields, models from odoo.exceptions import UserError class LibraryBook(models.Model): _name = "library.book" _description = "Library Book" name = fields.Char(string="Tên sách", required=True) author = fields.Char(string="Tác giả") published_date = fields.Date(string="Ngày xuất bản") isbn = fields.Char(string="Số ISBN") price = fields.Float(string="Giá sách") borrowed_by = fields.Many2one("library.member", string="Được mượn bởi") def action_mark_as_borrowed(self): if self.borrowed_by: raise UserError("Sách này đã được mượn rồi!") return { 'name': 'Select Member', 'type': 'ir.actions.act_window', 'res_model': 'library.member', 'view_mode': 'form', 'target': 'new' }