You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
3.6 KiB
74 lines
3.6 KiB
# -*- coding: utf-8 -*-
|
|
#############################################################################
|
|
#
|
|
# Cybrosys Technologies Pvt. Ltd.
|
|
#
|
|
# Copyright (C) 2022-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
|
|
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
|
|
#
|
|
# You can modify it under the terms of the GNU LESSER
|
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
|
|
#
|
|
# 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
|
|
#
|
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
|
|
# (LGPL v3) along with this program.
|
|
# If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
#############################################################################
|
|
|
|
from datetime import date, timedelta
|
|
|
|
from odoo import fields, models,_
|
|
from odoo.exceptions import UserError, ValidationError, AccessError, RedirectWarning
|
|
|
|
|
|
class ResCompany(models.Model):
|
|
_inherit = "res.company"
|
|
|
|
def _validate_fiscalyear_lock(self, values):
|
|
if values.get('fiscalyear_lock_date'):
|
|
|
|
draft_entries = self.env['account.move'].search([
|
|
('company_id', 'in', self.ids),
|
|
('state', '=', 'draft'),
|
|
('date', '<=', values['fiscalyear_lock_date'])])
|
|
if draft_entries:
|
|
error_msg = _('There are still unposted entries in the period you want to lock. You should either post or delete them.')
|
|
action_error = {
|
|
'view_mode': 'tree',
|
|
'name': 'Unposted Entries',
|
|
'res_model': 'account.move',
|
|
'type': 'ir.actions.act_window',
|
|
'domain': [('id', 'in', draft_entries.ids)],
|
|
'search_view_id': [self.env.ref('account.view_account_move_filter').id, 'search'],
|
|
'views': [[self.env.ref('account.view_move_tree').id, 'list'], [self.env.ref('account.view_move_form').id, 'form']],
|
|
}
|
|
raise RedirectWarning(error_msg, action_error, _('Show unposted entries'))
|
|
|
|
unreconciled_statement_lines = self.env['account.bank.statement.line'].search([
|
|
('company_id', 'in', self.ids),
|
|
('is_reconciled', '=', False),
|
|
('date', '<=', values['fiscalyear_lock_date']),
|
|
('move_id.state', 'in', ('draft', 'posted')),
|
|
])
|
|
if unreconciled_statement_lines:
|
|
error_msg = _("There are still unreconciled bank statement lines in the period you want to lock."
|
|
"You should either reconcile or delete them.")
|
|
action_error = {
|
|
'view_mode': 'tree',
|
|
'name': 'Unreconciled Transactions',
|
|
'res_model': 'account.bank.statement.line',
|
|
'type': 'ir.actions.act_window',
|
|
'domain': [('id', 'in', unreconciled_statement_lines.ids)],
|
|
# 'search_view_id': [self.env.ref('account.view_account_move_filter').id, 'search'],
|
|
'views': [[self.env.ref('base_accounting_kit.view_bank_statement_line_tree').id, 'list']]
|
|
# [self.env.ref('account.view_move_form').id, 'form']],
|
|
}
|
|
# action_error = self._get_fiscalyear_lock_statement_lines_redirect_action(unreconciled_statement_lines)
|
|
raise RedirectWarning(error_msg, action_error, _('Show Unreconciled Bank Statement Line'))
|
|
|
|
|
|
|