<commit_before># -*- coding: utf-8 -*-
# Copyright 2015 Odoo SA
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from odoo.exceptions import ValidationError


class AccountAnalyticLine(models.Model):
    _inherit = "account.analytic.line"

    journal_id = fields.Many2one(
        'account.analytic.journal', 'Analytic Journal', required=True,
        ondelete='restrict', index=True)


class AccountAnalyticJournal(models.Model):
    _name = 'account.analytic.journal'
    _description = 'Analytic Journal'

    name = fields.Char(string='Journal Name', required=True)
    code = fields.Char(string='Short Code', size=5, required=True)
    type = fields.Selection([
            ('sale', 'Sale'),
            ('purchase', 'Purchase'),
            ('cash', 'Cash'),
            ('bank', 'Bank'),
            ('general', 'Miscellaneous'),
        ], required=True,
        help="Select 'Sale' for customer invoices journals.\n"\
        "Select 'Purchase' for vendor bills journals.\n"\
        "Select 'Cash' or 'Bank' for journals that are used in customer or vendor payments.\n"\
        "Select 'General' for miscellaneous operations journals.")

    line_ids = fields.One2many('account.analytic.line', 'journal_id',
                                'Lines', copy=False)
    company_id = fields.Many2one(
        comodel_name='res.company',
        default=lambda self: self._get_default_company()
    )

    def _get_default_company(self):
        return self.env.user.company_id.id


class AccountJournal(models.Model):
    _inherit = "account.journal"

    analytic_journal_id = fields.Many2one(
        'account.analytic.journal',
        'Analytic Journal',
        help="Journal for analytic entries")


class AccountMoveLine(models.Model):
    _inherit = 'account.move.line'

    @api.one
    def _prepare_analytic_line(self):
        res = super(AccountMoveLine, self)._prepare_analytic_line()
        if not self.journal_id.analytic_journal_id:
            raise ValidationError("Please define an analytic journal for "
                                  "journal %s" % self.journal_id.name)
        res[0]['journal_id'] = self.journal_id.analytic_journal_id.id
        return res[0]


class AccountInvoice(models.Model):
    _inherit = 'account.invoice'

    @api.model
    def invoice_line_move_line_get(self):
        res = super(AccountInvoice, self).invoice_line_move_line_get()
        for data in res:
            if data.get('analytic_line_ids', False) and data.get('invoice_id'):
                aj = self.browse(
                    data['invoice_id']).journal_id.analytic_journal_id.id
                for line in data['analytic_line_ids']:
                    line[2]['journal_id'] = aj
        return res
<commit_msg>[FIX] pylint<commit_after># -*- coding: utf-8 -*-
# Copyright 2015 Odoo SA
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from odoo.exceptions import ValidationError


class AccountAnalyticLine(models.Model):
    _inherit = "account.analytic.line"

    journal_id = fields.Many2one(
        'account.analytic.journal', 'Analytic Journal', required=True,
        ondelete='restrict', index=True)


class AccountAnalyticJournal(models.Model):
    _name = 'account.analytic.journal'
    _description = 'Analytic Journal'

    name = fields.Char(string='Journal Name', required=True)
    code = fields.Char(string='Short Code', size=5, required=True)
    type = fields.Selection([
            ('sale', 'Sale'),
            ('purchase', 'Purchase'),
            ('cash', 'Cash'),
            ('bank', 'Bank'),
            ('general', 'Miscellaneous'),
        ], required=True,
        help="Select 'Sale' for customer invoices journals.\n"\
        "Select 'Purchase' for vendor bills journals.\n"\
        "Select 'Cash' or 'Bank' for journals that are used in customer or vendor payments.\n"\
        "Select 'General' for miscellaneous operations journals.")

    line_ids = fields.One2many('account.analytic.line', 'journal_id',
                                'Lines', copy=False)
    company_id = fields.Many2one(
        comodel_name='res.company',
        default=lambda self: self._get_default_company()
    )

    def _get_default_company(self):
        return self.env.user.company_id.id


class AccountJournal(models.Model):
    _inherit = "account.journal"

    analytic_journal_id = fields.Many2one(
        'account.analytic.journal',
        'Analytic Journal',
        help="Journal for analytic entries")


class AccountMoveLine(models.Model):
    _inherit = 'account.move.line'

    @api.multi
    def _prepare_analytic_line(self):
        self.ensure_one()
        res = super(AccountMoveLine, self)._prepare_analytic_line()
        if not self.journal_id.analytic_journal_id:
            raise ValidationError("Please define an analytic journal for "
                                  "journal %s" % self.journal_id.name)
        res[0]['journal_id'] = self.journal_id.analytic_journal_id.id
        return res[0]


class AccountInvoice(models.Model):
    _inherit = 'account.invoice'

    @api.model
    def invoice_line_move_line_get(self):
        res = super(AccountInvoice, self).invoice_line_move_line_get()
        for data in res:
            if data.get('analytic_line_ids', False) and data.get('invoice_id'):
                aj = self.browse(
                    data['invoice_id']).journal_id.analytic_journal_id.id
                for line in data['analytic_line_ids']:
                    line[2]['journal_id'] = aj
        return res

{'fraction_non_alphanumeric': 0.11655376063922182, 'fraction_numerical': 0.006600660066006601, 'mean_word_length': 2.7148387096774194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '609456', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1643, 'n_words': 380}