<commit_before># Copyright 2017 ACSONE SA/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_fm_id = fields.Many2one(
        comodel_name='date.range', string="Fiscal month",
        compute='_compute_date_range_fm', search='_search_date_range_fm',
    )

    @api.multi
    @api.depends('date', 'company_id')
    def _compute_date_range_fm(self):
        for rec in self:
            date = rec.date
            company = rec.company_id
            rec.date_range_fm_id = company.find_daterange_fm(date)

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

        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),
            ]])
        return domain
<commit_msg>[12.0][FIX] account_move_fiscal_month: error when creating account.move<commit_after># 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_fm_id = fields.Many2one(
        comodel_name='date.range', string="Fiscal month",
        compute='_compute_date_range_fm', search='_search_date_range_fm',
    )

    @api.multi
    @api.depends('date', 'company_id')
    def _compute_date_range_fm(self):
        for rec in self:
            date = rec.date
            company = rec.company_id
            rec.date_range_fm_id =\
                company and company.find_daterange_fm(date) or False

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

        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),
            ]])
        return domain

{'fraction_non_alphanumeric': 0.13720851639067252, 'fraction_numerical': 0.005745184183845894, 'mean_word_length': 2.210412147505423, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '6639461', 'n_tokens_mistral': 951, 'n_tokens_neox': 912, 'n_words': 178}