hostel.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from odoo import models, fields, api
  2. class Hostel(models.Model):
  3. _name = 'hostel.hostel'
  4. _description = 'Information about hostel'
  5. _order = "id desc, name"
  6. _rec_name = 'hostel_code'
  7. _rec_names_search = ["name", "hostel_code"]
  8. currency_id = fields.Many2one('res.currency', string='Currency')
  9. # _table = 'hostel_hostel'
  10. name = fields.Char(string='宿舍名称', required=True)
  11. hostel_code = fields.Char(string='代码', required=True)
  12. street = fields.Char('街道')
  13. street2 = fields.Char('街道2')
  14. city = fields.Char('城市')
  15. zip = fields.Char('邮编')
  16. state_id = fields.Many2one('res.country.state', string='省份')
  17. country_id = fields.Many2one('res.country', string='国家')
  18. phone = fields.Char('电话')
  19. mobile = fields.Char('手机')
  20. email = fields.Char('邮箱')
  21. hostel_floors = fields.Integer(string="楼层")
  22. image = fields.Binary("宿舍图片")
  23. activate = fields.Boolean(string="激活", default=True, help="激活 / 停用宿舍记录")
  24. type = fields.Selection(
  25. string="类型",
  26. selection=[("男性", "男生宿舍"), ("女性", "女生宿舍"), ("混合", "混合宿舍")],
  27. help="宿舍类型",
  28. required=True,
  29. default="混合"
  30. )
  31. other_info = fields.Text(string="其他信息", help="输入更多信息")
  32. description = fields.Html(string="描述")
  33. hostel_rating = fields.Float('宿舍平均评分',
  34. # digits=(14, 4))
  35. digits = "rating value")
  36. @api.depends('hostel_code')
  37. def _compute_display_name(self):
  38. for record in self:
  39. name = record.name
  40. if record.hostel_code:
  41. name = f"{name} ({record.hostel_code})"
  42. record.display_name = name