module library

This commit is contained in:
XuanHuyen
2025-03-08 01:26:56 +07:00
parent 6baa855977
commit f340de4a96
12 changed files with 254 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from . import library_book
from . import library_member
+25
View File
@@ -0,0 +1,25 @@
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'
}
+10
View File
@@ -0,0 +1,10 @@
from odoo import fields, models
class LibraryMember(models.Model):
_name = "library.member"
_description = "Library Member"
name = fields.Char(string="Tên thành viên")
email = fields.Char(string="Email", required=True, unique=True)
phone = fields.Char(string="Số điện thoại")
borrowed_books_ids = fields.One2many("library.book", "borrowed_by", string="Danh sách sách đã mượn")