<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014 Eficent (<http://www.eficent.com/>)
#              <<EMAIL>>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.tools.translate import _
from openerp.osv import fields, orm


class AnalyticPlanVersion(orm.Model):
    _name = 'account.analytic.plan.version'
    _description = 'Plan Version'
    _columns = {
        'name': fields.char(
            'Plan Version Name', size=64, required=True
        ),
        'code': fields.char(
            'Plan Version Code', size=8
        ),
        'active': fields.boolean(
            'Active',
            help='''
            If the active
            field is set to False,
            it will allow you to hide
            the analytic planning version
            without removing it.
            '''
        ),
        'notes': fields.text(
            'Notes'
        ),
        'company_id': fields.many2one(
            'res.company', 'Company', required=True
        ),
        'default_committed': fields.boolean(
            """Default version
            for committed costs"""
        ),
        'default_plan': fields.boolean(
            'Default plan version'
        ),
    }

    def _check_default_committed(self, cr, uid, vals, context=None):

        if 'default_committed' in vals:
            if vals['default_committed'] is True:
                other_default_committed = self.search(
                    cr, uid, [('default_committed', '=', True)],
                    context=context
                )
                if other_default_committed:
                    raise orm.except_orm(
                        _('Error!'),
                        _(
                            '''
                            Only one default commitments
                            version can exist.
                            '''
                        )
                    )

    def _check_default_plan(self, cr, uid, vals, context=None):

        if 'default_plan' in vals:
            if vals['default_plan'] is True:
                other_default_plan = self.search(
                    cr, uid, [('default_plan', '=', True)], context=context
                )
                if other_default_plan:
                    raise orm.except_orm(
                        _('Error!'),
                        _(
                            '''
                            Only one default plan version
                            can exist.
                            '''
                        )
                    )

    _defaults = {
        'active': True,
        'company_id': lambda self, cr, uid,
        c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
        'default_committed': False,
        'default_plan': False,
    }

    def create(self, cr, uid, vals, *args, **kwargs):

        context = kwargs.get('context', {})
        self._check_default_committed(cr, uid, vals, context)
        self._check_default_plan(cr, uid, vals, context)

        res = super(account_analytic_plan_version, self).create(
            cr, uid, vals, *args, **kwargs)

        return res

    def write(self, cr, uid, ids, vals, context=None):
        if context is None:
            context = {}

        self._check_default_committed(cr, uid, vals, context)
        self._check_default_plan(cr, uid, vals, context)

        return super(account_analytic_plan_version, self).write(
            cr, uid, ids, vals, context=context)
<commit_msg>Update account_analytic_plan_version.py<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014 Eficent (<http://www.eficent.com/>)
#              <<EMAIL>>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.tools.translate import _
from openerp.osv import fields, orm


class AnalyticPlanVersion(orm.Model):
    _name = 'account.analytic.plan.version'
    _description = 'Plan Version'
    _columns = {
        'name': fields.char(
            'Plan Version Name', size=64, required=True
        ),
        'code': fields.char(
            'Plan Version Code', size=8
        ),
        'active': fields.boolean(
            'Active',
            help='''
            If the active
            field is set to False,
            it will allow you to hide
            the analytic planning version
            without removing it.
            '''
        ),
        'notes': fields.text(
            'Notes'
        ),
        'company_id': fields.many2one(
            'res.company', 'Company', required=True
        ),
        'default_committed': fields.boolean(
            """Default version
            for committed costs"""
        ),
        'default_plan': fields.boolean(
            'Default plan version'
        ),
    }

    def _check_default_committed(self, cr, uid, vals, context=None):

        if 'default_committed' in vals:
            if vals['default_committed'] is True:
                other_default_committed = self.search(
                    cr, uid, [('default_committed', '=', True)],
                    context=context
                )
                if other_default_committed:
                    raise orm.except_orm(
                        _('Error!'),
                        _(
                            '''
                            Only one default commitments
                            version can exist.
                            '''
                        )
                    )

    def _check_default_plan(self, cr, uid, vals, context=None):

        if 'default_plan' in vals:
            if vals['default_plan'] is True:
                other_default_plan = self.search(
                    cr, uid, [('default_plan', '=', True)], context=context
                )
                if other_default_plan:
                    raise orm.except_orm(
                        _('Error!'),
                        _(
                            '''
                            Only one default plan version
                            can exist.
                            '''
                        )
                    )

    _defaults = {
        'active': True,
        'company_id': lambda self, cr, uid,
        c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
        'default_committed': False,
        'default_plan': False,
    }

    def create(self, cr, uid, vals, *args, **kwargs):

        context = kwargs.get('context', {})
        self._check_default_committed(cr, uid, vals, context)
        self._check_default_plan(cr, uid, vals, context)

        res = super(account_analytic_plan_version, self).create(
            cr, uid, vals, *args, **kwargs)

        return res

    def write(self, cr, uid, ids, vals, context=None):
        if context is None:
            context = {}

        self._check_default_committed(cr, uid, vals, context)
        self._check_default_plan(cr, uid, vals, context)

        return super(AnalyticPlanVersion, self).write(
            cr, uid, ids, vals, context=context)

{'fraction_non_alphanumeric': 0.130338904363974, 'fraction_numerical': 0.002321262766945218, 'mean_word_length': 1.6489394405164464, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5620196', 'n_tokens_mistral': 2272, 'n_tokens_neox': 2164, 'n_words': 647}