hostel.py 1.0 KB

123456789101112131415161718192021222324252627282930
  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. # _table = 'hostel_hostel'
  9. name = fields.Char(string='Hostel name', required=True)
  10. hostel_code = fields.Char(string='代码', required=True)
  11. street = fields.Char('Street')
  12. street2 = fields.Char('Street2')
  13. city = fields.Char('City')
  14. zip = fields.Char('ZIP')
  15. state_id = fields.Many2one('res.country.state', string='State')
  16. country_id = fields.Many2one('res.country', string='Country')
  17. phone = fields.Char('Phone')
  18. mobile = fields.Char('Mobile')
  19. email = fields.Char('Email')
  20. @api.depends('hostel_code')
  21. def _compute_display_name(self):
  22. for record in self:
  23. name = record.name
  24. if record.hostel_code:
  25. name = f"{name} ({record.hostel_code})"
  26. record.display_name = name