123456789101112131415161718192021222324252627282930 |
- from odoo import models, fields, api
- class Hostel(models.Model):
- _name = 'hostel.hostel'
- _description = 'Information about hostel'
- _order = "id desc, name"
- _rec_name = 'hostel_code'
- _rec_names_search = ["name", "hostel_code"]
- # _table = 'hostel_hostel'
-
- name = fields.Char(string='Hostel name', required=True)
- hostel_code = fields.Char(string='代码', required=True)
- street = fields.Char('Street')
- street2 = fields.Char('Street2')
- city = fields.Char('City')
- zip = fields.Char('ZIP')
- state_id = fields.Many2one('res.country.state', string='State')
- country_id = fields.Many2one('res.country', string='Country')
- phone = fields.Char('Phone')
- mobile = fields.Char('Mobile')
- email = fields.Char('Email')
- @api.depends('hostel_code')
- def _compute_display_name(self):
- for record in self:
- name = record.name
- if record.hostel_code:
- name = f"{name} ({record.hostel_code})"
- record.display_name = name
|