Sfoglia il codice sorgente

[ADD]添加hostel_amenities.py模型,以及添加宿舍与学生的O2M和学生与宿舍的M2O字段,更新之前没写完的XML视图文件

longyuan 1 mese fa
parent
commit
f27054fdd2
4 ha cambiato i file con 33 aggiunte e 2 eliminazioni
  1. 1 0
      models/__init__.py
  2. 3 2
      models/hostel.py
  3. 10 0
      models/hostel_amenities.py
  4. 19 0
      models/hostel_room.py

+ 1 - 0
models/__init__.py

@@ -1,2 +1,3 @@
 from . import hostel
 from . import hostel_room
+from . import hostel_amenities

+ 3 - 2
models/hostel.py

@@ -3,7 +3,7 @@ from odoo import models, fields, api
 
 class Hostel(models.Model):
     _name = 'hostel.hostel'
-    _description = 'Information about hostel'
+    _description = '宿舍信息'
     _order = "id desc, name"
     _rec_name = 'hostel_code'
     _rec_names_search = ["name", "hostel_code"]
@@ -48,12 +48,13 @@ class Hostel(models.Model):
 
     @api.constrains('hostel_floors')
     def _check_hostel_floors(self):
+        self.ensure_one()
         for record in self:
             if record.hostel_floors <= 0:
                 raise models.ValidationError("楼层数不能小于0")
             elif record.hostel_floors > 50:
                 # record.hostel_floors = 50
-                raise models.ValidationError("楼层数不能超过50层")
+                raise models.ValidationError("楼层数不能超过10层")
                 # record.message_post(body="楼层数不能超过50层")
 
     # 此函数用于在当前字段分组时扩展read_group结果

+ 10 - 0
models/hostel_amenities.py

@@ -0,0 +1,10 @@
+from odoo import models, fields, api
+
+
+class HostelAmennities(models.Model):
+    _name = "hostel.amenities"
+    _description = "宿舍设施信息"
+
+    # 视图
+    name = fields.Char("设施名字", help="Provided Hostel Amennity")
+    active = fields.Boolean("可用", default=True, help="激活/停用 宿舍设施")

+ 19 - 0
models/hostel_room.py

@@ -1,11 +1,30 @@
 from odoo import models, fields, api
 
+
+class HostelStudent(models.Model):
+    _name = "hostel.student"
+    _description = "宿舍学生信息"
+
+    # 学生信息
+    name = fields.Char("姓名", required=True)
+    gender = fields.Selection([("male", "男"), ("female", "女")], string="性别", required=True)
+    age = fields.Integer("年龄", required=True)
+    active = fields.Boolean("可用", default=True, help="激活/停用 宿舍记录")
+    room_id = fields.Many2one("hostel.room", "房间", help="选择房间号")
+    
+
 class HostelRoom(models.Model):
     _name = "hostel.room"
     _description = "宿舍房间信息"
+
     floor_number = fields.Integer("楼层", required=True)
     room_name = fields.Char("房间名称", required=True)
     room_id = fields.Integer("房间编号", required=True)
     rent_amount = fields.Monetary("租金", help="输入每月租金", currency_field="currency_id")
     currency_id = fields.Many2one('res.currency', string="货币种类")
+    hostel_id = fields.Many2one("hostel.hostel", "hostel", help='输入宿舍名称')
+    student_ids = fields.One2many("hostel.student", "room_id", "学生")
+    
+    hostel_amenities_ids = fields.Many2many("hostel.amenities", "hostel_room_amenities_rel", "room_id", "amenitily_id",
+    string="设施", domain="[('active', '=', True)]", help="选择宿舍设施")