diff options
| author | Srushti Patel <shp@odoo.com> | 2015-09-09 17:38:50 +0530 |
|---|---|---|
| committer | David Monjoie <dmo@odoo.com> | 2016-04-08 13:54:07 +0200 |
| commit | 1e9b6b4cb4914159d9b18ec00a861da3542bd3e5 (patch) | |
| tree | 9c480f530174efd2db090ca40123cf4659a11ac1 /addons/website_forum_doc/models/forum_documentation_toc.py | |
| parent | b88060e5bae0d239a2b7879b9661d015ec9df3b9 (diff) | |
[MIG] website_forum_doc: migrated to new api
Diffstat (limited to 'addons/website_forum_doc/models/forum_documentation_toc.py')
| -rw-r--r-- | addons/website_forum_doc/models/forum_documentation_toc.py | 69 |
1 files changed, 29 insertions, 40 deletions
diff --git a/addons/website_forum_doc/models/forum_documentation_toc.py b/addons/website_forum_doc/models/forum_documentation_toc.py index 9f36c178c48..fc167f1ed80 100644 --- a/addons/website_forum_doc/models/forum_documentation_toc.py +++ b/addons/website_forum_doc/models/forum_documentation_toc.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -from openerp.osv import osv, fields +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError -class Documentation(osv.Model): +class Documentation(models.Model): _name = 'forum.documentation.toc' _description = 'Documentation ToC' _inherit = ['website.seo.metadata'] @@ -11,48 +12,36 @@ class Documentation(osv.Model): _parent_order = "sequence, name" _parent_store = True - def name_get(self, cr, uid, ids, context=None): - if isinstance(ids, (list, tuple)) and not len(ids): - return [] - if isinstance(ids, (long, int)): - ids = [ids] - reads = self.read(cr, uid, ids, ['name', 'parent_id'], context=context) + sequence = fields.Integer('Sequence') + name = fields.Char('Name', required=True, translate=True) + introduction = fields.Html('Introduction', translate=True) + parent_id = fields.Many2one('forum.documentation.toc', string='Parent Table Of Content', ondelete='cascade') + child_ids = fields.One2many('forum.documentation.toc', 'parent_id', string='Children Table Of Content') + parent_left = fields.Integer(string='Left Parent', index=True) + parent_right = fields.Integer(string='Right Parent', index=True) + post_ids = fields.One2many('forum.post', 'documentation_toc_id', string='Posts') + forum_id = fields.Many2one('forum.forum', string='Forum', required=True) + + @api.multi + def name_get(self): res = [] - for record in reads: - name = record['name'] - if record['parent_id']: - name = record['parent_id'][1]+' / '+name - res.append((record['id'], name)) + for record in self: + name = record.name + if record.parent_id: + name = record.parent_id.name + ' / ' + name + res.append((record.id, name)) return res - # TODO master remove me - def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None): - res = self.name_get(cr, uid, ids, context=context) - return dict(res) - - _columns = { - 'sequence': fields.integer('Sequence'), - 'name': fields.char('Name', required=True, translate=True), - 'introduction': fields.html('Introduction', translate=True), - 'parent_id': fields.many2one('forum.documentation.toc', 'Parent Table Of Content', ondelete='cascade'), - 'child_ids': fields.one2many('forum.documentation.toc', 'parent_id', 'Children Table Of Content'), - 'parent_left': fields.integer('Left Parent', select=True), - 'parent_right': fields.integer('Right Parent', select=True), - 'post_ids': fields.one2many('forum.post', 'documentation_toc_id', 'Posts'), - 'forum_id': fields.many2one('forum.forum', 'Forum', required=True), - } - - _constraints = [ - (osv.osv._check_recursion, 'Error ! You cannot create recursive categories.', ['parent_id']) - ] - - -class DocumentationStage(osv.Model): + @api.constrains('parent_id') + def _check_parent_id(self): + if not self._check_recursion(): + raise ValidationError(_('Error ! You cannot create recursive categories.')) + + +class DocumentationStage(models.Model): _name = 'forum.documentation.stage' _description = 'Post Stage' _order = 'sequence' - _columns = { - 'sequence': fields.integer('Sequence'), - 'name': fields.char('Stage Name', required=True, translate=True), - } + sequence = fields.Integer('Sequence') + name = fields.Char(string='Stage Name', required=True, translate=True) |
