<commit_before># -*- coding: utf-8 -*-
# Copyright 2017 <NAME>/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.osv import expression


class AccountMove(models.Model):

    _inherit = 'account.move'

    date_range_fy_id = fields.Many2one(
        comodel_name='date.range', string="Fiscal year",
        domain=lambda self: self._get_date_range_fy_domain(),
        compute='_compute_date_range_fy', search='_search_date_range_fy')

    @api.model
    def _get_date_range_fy_domain(self):
        fiscal_year_type = self.env.ref('account_fiscal_year.fiscalyear')
        return "[('type_id', '=', %d)]" % fiscal_year_type.id

    @api.multi
    @api.depends('date', 'company_id')
    def _compute_date_range_fy(self):
        for rec in self:
            date = fields.Date.from_string(rec.date)
            company = rec.company_id
            rec.date_range_fy_id = company.find_daterange_fy(date)

    @api.model
    def _search_date_range_fy(self, operator, value):
        if operator in ('=', '!=', 'in', 'not in'):
            date_range_domain = [('id', operator, value)]
        else:
            date_range_domain = [('name', operator, value)]

        fiscal_year_type = self.env.ref('account_fiscal_year.fiscalyear')
        date_range_domain.append(('type_id', '=', fiscal_year_type.id))
        date_ranges = self.env['date.range'].search(date_range_domain)

        domain = []
        for date_range in date_ranges:
            domain = expression.OR([domain, [
                '&',
                '&',
                ('date', '>=', date_range.date_start),
                ('date', '<=', date_range.date_end),
                '|',
                ('company_id', '=', False),
                ('company_id', '=', date_range.company_id.id),<commit_msg>[FIX] account_move_fiscal_year: check if the company is defined.<commit_after># -*- coding: utf-8 -*-
# Copyright 2017 <NAME>/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.osv import expression


class AccountMove(models.Model):

    _inherit = 'account.move'

    date_range_fy_id = fields.Many2one(
        comodel_name='date.range', string="Fiscal year",
        domain=lambda self: self._get_date_range_fy_domain(),
        compute='_compute_date_range_fy', search='_search_date_range_fy')

    @api.model
    def _get_date_range_fy_domain(self):
        fiscal_year_type = self.env.ref('account_fiscal_year.fiscalyear')
        return "[('type_id', '=', %d)]" % fiscal_year_type.id

    @api.multi
    @api.depends('date', 'company_id')
    def _compute_date_range_fy(self):
        for rec in self:
            date = fields.Date.from_string(rec.date)
            company = rec.company_id
            rec.date_range_fy_id =\
                company and company.find_daterange_fy(date) or False

    @api.model
    def _search_date_range_fy(self, operator, value):
        if operator in ('=', '!=', 'in', 'not in'):
            date_range_domain = [('id', operator, value)]
        else:
            date_range_domain = [('name', operator, value)]

        fiscal_year_type = self.env.ref('account_fiscal_year.fiscalyear')
        date_range_domain.append(('type_id', '=', fiscal_year_type.id))
        date_ranges = self.env['date.range'].search(date_range_domain)

        domain = []
        for date_range in date_ranges:
            domain = expression.OR([domain, [
                '&',
                '&',
                ('date', '>=', date_range.date_start),
                ('date', '<=', date_range.date_end),
                '|',
                ('company_id', '=', False),
                ('company_id', '=', date_range.company_id.id),
{'fraction_non_alphanumeric': 0.14232508645916467, 'fraction_numerical': 0.004256451183825486, 'mean_word_length': 2.574144486692015, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '970338', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1217, 'n_words': 210}