<commit_before>﻿# -*- coding: utf-8 -*-
from openerp import models, fields, api


class TreeNode(models.AbstractModel):
    _name = 'suvit.tree.node.mixin'
    _description = u'Узел дерева'
    _order = 'parent_id,sequence,id'
    _use_full_ids = False

    parent_id = fields.Many2one(string=u'Принадлежность',
                                comodel_name=_name)

    child_ids = fields.One2many(string=u'Состав',
                                comodel_name=_name,
                                inverse_name='parent_id')

    sequence = fields.Integer(string=u'Порядок',
                              default=99)

    object_id = fields.Reference(string=u'Связь',
                                 selection=[],
                                 )

    # Link
    shortcut_id = fields.Many2one(string="Ярлык",
                                  comodel_name=_name)

    name = fields.Char(string=u'Наименование',
                       compute='compute_name',
                       store=True,
                       readonly=False)

    @api.multi
    @api.onchange('shortcut_id', 'object_id')
    @api.depends('shortcut_id', 'object_id')
    def compute_name(self):
        for rec in self:
            if rec.shortcut_id:
                rec.name = u'[Я] %s' % rec.shortcut_id.name
            elif rec.object_id:
                rec.name = getattr(rec.object_id, rec.object_id._rec_name or 'title', '-')

    @api.multi
    def action_remove(self):
        self.write({'parent_id': False})

    @api.model
    def change_parent(self):
        pass

    # API for full ids
    @api.multi
    def evaluate_ids(self):
        if not any(isinstance(id, basestring) for id in self.ids):
            return<commit_msg>fixed save name on create without object_id<commit_after>﻿# -*- coding: utf-8 -*-
from openerp import models, fields, api


class TreeNode(models.AbstractModel):
    _name = 'suvit.tree.node.mixin'
    _description = u'<NAME>'
    _order = 'parent_id,sequence,id'
    _use_full_ids = False

    parent_id = fields.Many2one(string=u'Принадлежность',
                                comodel_name=_name)

    child_ids = fields.One2many(string=u'Состав',
                                comodel_name=_name,
                                inverse_name='parent_id')

    sequence = fields.Integer(string=u'Порядок',
                              default=99)

    object_id = fields.Reference(string=u'Связь',
                                 selection=[],
                                 )

    # Link
    shortcut_id = fields.Many2one(string="Ярлык",
                                  comodel_name=_name)

    name = fields.Char(string=u'Наименование',
                       compute='compute_name',
                       store=True,
                       readonly=False)

    @api.model
    def create(self, vals):
        #print 'TreeNode.create', vals
        new_obj = super(TreeNode, self).create(vals)

        # XXX ugly hack to fixed depends override 
        if not new_obj.name and 'name' in vals:
            new_obj.name = vals['name']

        return new_obj

    @api.multi
    @api.onchange('shortcut_id', 'object_id')
    @api.depends('shortcut_id', 'object_id')
    def compute_name(self):
        for rec in self:
            if rec.shortcut_id:
                rec.name = u'[Я] %s' % rec.shortcut_id.name
            elif rec.object_id:
                rec.name = getattr(rec.object_id, rec.object_id._rec_name or 'title', '-')

    @api.multi
    def action_remove(self):
        self.write({'parent_id': False})

    @api.model
    def change_parent(self):
        pass

    # API for full ids
    @api.multi
    def evaluate_ids(self):
        if not any(isinstance(id, basestring) for id in self.ids):
            return
{'fraction_non_alphanumeric': 0.1066205796330763, 'fraction_numerical': 0.0031906407870247273, 'mean_word_length': 1.7260869565217392, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1442154', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1146, 'n_words': 214}