<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2018 Compassion CH (http://www.compassion.ch)
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################

from odoo import models, fields, api
from datetime import timedelta


class ResCompany(models.Model):
    _inherit = 'res.company'

    move_bills_date = fields.Boolean(string="Move unclosed bills to next "
                                            "fiscal year", default=False)

    @api.multi
    def _validate_fiscalyear_lock(self, values):
        super(ResCompany, self)._validate_fiscalyear_lock(values)
        # Move open customer invoice open moves to next fiscal year
        lock_date = values.get('fiscalyear_lock_date')
        if lock_date:
            config = self.env['account.config.settings'].search([
                ('company_id', 'in', self.ids)
            ], order="create_date desc", limit=1)
            if config.move_bills_date:

                open_invoices = self.env['account.invoice'].search([
                    ('state', '=', 'open'),
                    ('type', '=', 'out_invoice'),
                    ('date_invoice', '<=', lock_date)
                ])
                first_day_in_next_fy = fields.Date.from_string(
                    lock_date) + timedelta(days=1)
                moves = open_invoices.mapped('move_id').sudo()
                moves.write({
                    'date': fields.Date.to_string(first_day_in_next_fy)
                })
                analytic_lines = self.env['account.analytic.line'].sudo()\
                    .search([
                        ('move_id', 'in', moves.ids),
                        ('date', '<=', lock_date)
                    ])
                analytic_lines.write({'date': first_day_in_next_fy})<commit_msg>CO-2049: Fix bug date analytic_lines<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2018 Compassion CH (http://www.compassion.ch)
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################

from odoo import models, fields, api
from datetime import timedelta


class ResCompany(models.Model):
    _inherit = 'res.company'

    move_bills_date = fields.Boolean(string="Move unclosed bills to next "
                                            "fiscal year", default=False)

    @api.multi
    def _validate_fiscalyear_lock(self, values):
        super(ResCompany, self)._validate_fiscalyear_lock(values)
        # Move open customer invoice open moves to next fiscal year
        lock_date = values.get('fiscalyear_lock_date')
        if lock_date:
            config = self.env['account.config.settings'].search([
                ('company_id', 'in', self.ids)
            ], order="create_date desc", limit=1)
            if config.move_bills_date:

                open_invoices = self.env['account.invoice'].search([
                    ('state', '=', 'open'),
                    ('type', '=', 'out_invoice'),
                    ('date_invoice', '<=', lock_date)
                ])
                first_day_in_next_fy = fields.Date.from_string(
                    lock_date) + timedelta(days=1)
                moves = open_invoices.mapped('move_id').sudo()
                moves.write({
                    'date': fields.Date.to_string(first_day_in_next_fy)

                })
                analytic_lines = moves.mapped('line_ids.analytic_line_ids')
                analytic_lines.write({'date': first_day_in_next_fy})
{'fraction_non_alphanumeric': 0.19587083112758072, 'fraction_numerical': 0.004764425622022234, 'mean_word_length': 2.17563025210084, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1779907', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1004, 'n_words': 195}