<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Addons modules by CLEARCORP S.A.
#    Copyright (C) 2009-TODAY CLEARCORP S.A. (<http://clearcorp.co.cr>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from report import report_sxw
from tools.translate import _
import pooler
from osv import fields,osv

from openerp.addons.account_financial_report_webkit.report.trial_balance import TrialBalanceWebkit
from openerp.addons.account_financial_report_webkit.report.webkit_parser_header_fix import HeaderFooterTextWebKitParser

def sign(number):
    return cmp(number, 0)

class IncomeStatementReport(TrialBalanceWebkit):
    def __init__(self, cr, uid, name, context):
        super(IncomeStatementReport, self).__init__(cr, uid, name, context=context)
        self.pool = pooler.get_pool(self.cr.dbname)
        self.cursor = self.cr
        #This line is to delete, the header of trial balance
        self.localcontext['additional_args'][4] = ('--header-left', '')
        self.localcontext.update({
            'cr': self.cr,
            'uid': self.uid,
            'get_fiscalyear': self.get_fiscalyear,
            'get_last_period': self.get_last_period,
            'get_data': self.get_data,
        })
        
    def set_context(self, objects, data, ids, report_type=None):
        start_period = self._get_form_param('period_from', data)
        
        self.localcontext.update({
            'start_period': start_period,
            })
        return super(IncomeStatementReport, self).set_context(objects, data, ids, report_type=report_type)
    
    def get_last_period_fiscalyear(self, cr, uid, fiscalyear):
        account_period_obj = self.pool.get('account.period')
        period_ids = account_period_obj.search(cr, uid, [('fiscalyear_id', '=', fiscalyear.id), ('special', '=', False)])
        periods = account_period_obj.browse(cr, uid, period_ids)
        period_select = periods[0]
        for current_period in periods:
            if current_period.date_start > period_select.date_start:
                period_select = current_period
        return period_select
    
    def get_last_period(self, cr, uid, start_period):
        account_period_obj = self.pool.get('account.period')
        #REMOVE: debug
        print start_period, start_period.fiscalyear_id
        period_ids = account_period_obj.search(cr, uid, [('fiscalyear_id', '=', start_period.fiscalyear_id.id), ('special', '=', False)])
        periods = account_period_obj.browse(cr, uid, period_ids)
        period_select = start_period
        for period in periods:
            if (period.date_start < start_period.date_start and period.date_start > period_select.date_start) or (period.date_start < start_period.date_start and start_period == period_select):
                period_select = period
        if period_select == start_period:
            fiscalyear = self.get_fiscalyear(cr, uid, start_period)
            fiscalyear_select = fiscalyear
            account_fiscalyear_obj = self.pool.get('account.fiscalyear')
            all_fiscalyears_ids = account_fiscalyear_obj.search(cr, uid, [])
            all_fiscalyears = account_fiscalyear_obj.browse(cr, uid, all_fiscalyears_ids)
            for current_fiscalyear in all_fiscalyears:
                if (current_fiscalyear.date_start < fiscalyear.date_start and current_fiscalyear.date_start > fiscalyear_select.date_start) or (current_fiscalyear.date_start < fiscalyear.date_start and fiscalyear == fiscalyear_select):
                    fiscalyear_select = current_fiscalyear
            if fiscalyear_select == fiscalyear:
                raise osv.except_osv(_('Error fiscal year'),_('There is no previous period to compare'))
            period_select = self.get_last_period_fiscalyear(cr, uid, fiscalyear_select)
        return period_select
        
    def get_fiscalyear(self, cr, uid, start_period):
        fiscalyear = start_period.fiscalyear_id
        return fiscalyear
     
    def get_data(self, cr, uid, data, context={}):
        account_account_obj = self.pool.get('account.account')
        library_obj = self.pool.get('account.webkit.report.library')
        
        #TODO: remove dependency of c2c
        account_chart_id = self._get_form_param('chart_account_id', data)
        
        account_chart = account_account_obj.browse(cr, uid, account_chart_id)[0]
        company_id = account_chart['company_id'].id
        category_account_ids = library_obj.get_category_accounts(cr, uid, company_id)
        period = self._get_form_param('period_from', data)
        last_period = self.get_last_period(cr, uid, period.id)
        fiscal_year = self.get_fiscalyear(cr, uid, period.id)
        
        #build accounts list
        income_accounts = [category_account_ids['income']]
        income_accounts.append(library_obj.get_account_child_ids(cr, uid, category_account_ids['income']))
        expense_accounts = [category_account_ids['expense']]
        expense_accounts.append(library_obj.get_account_child_ids(cr, uid, category_account_ids['expense']))
        
        #build account_ids list
        income_account_ids = []
        expense_account_ids = []<commit_msg>[FIX] testing report<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Addons modules by CLEARCORP S.A.
#    Copyright (C) 2009-TODAY CLEARCORP S.A. (<http://clearcorp.co.cr>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from report import report_sxw
from tools.translate import _
import pooler
from osv import fields,osv

from openerp.addons.account_financial_report_webkit.report.trial_balance import TrialBalanceWebkit
from openerp.addons.account_financial_report_webkit.report.webkit_parser_header_fix import HeaderFooterTextWebKitParser

def sign(number):
    return cmp(number, 0)

class IncomeStatementReport(TrialBalanceWebkit):
    def __init__(self, cr, uid, name, context):
        super(IncomeStatementReport, self).__init__(cr, uid, name, context=context)
        self.pool = pooler.get_pool(self.cr.dbname)
        self.cursor = self.cr
        #This line is to delete, the header of trial balance
        self.localcontext['additional_args'][4] = ('--header-left', '')
        self.localcontext.update({
            'cr': self.cr,
            'uid': self.uid,
            'get_fiscalyear': self.get_fiscalyear,
            'get_last_period': self.get_last_period,
            'get_data': self.get_data,
        })
        
    def set_context(self, objects, data, ids, report_type=None):
        start_period = self._get_form_param('period_from', data)
        
        self.localcontext.update({
            'start_period': start_period,
            })
        return super(IncomeStatementReport, self).set_context(objects, data, ids, report_type=report_type)
    
    def get_last_period_fiscalyear(self, cr, uid, fiscalyear):
        account_period_obj = self.pool.get('account.period')
        period_ids = account_period_obj.search(cr, uid, [('fiscalyear_id', '=', fiscalyear.id), ('special', '=', False)])
        periods = account_period_obj.browse(cr, uid, period_ids)
        period_select = periods[0]
        for current_period in periods:
            if current_period.date_start > period_select.date_start:
                period_select = current_period
        return period_select
    
    def get_last_period(self, cr, uid, start_period):
        account_period_obj = self.pool.get('account.period')
        period_ids = account_period_obj.search(cr, uid, [('fiscalyear_id', '=', start_period.fiscalyear_id.id), ('special', '=', False)])
        periods = account_period_obj.browse(cr, uid, period_ids)
        period_select = start_period
        for period in periods:
            if (period.date_start < start_period.date_start and period.date_start > period_select.date_start) or (period.date_start < start_period.date_start and start_period == period_select):
                period_select = period
        if period_select == start_period:
            fiscalyear = self.get_fiscalyear(cr, uid, start_period)
            fiscalyear_select = fiscalyear
            account_fiscalyear_obj = self.pool.get('account.fiscalyear')
            all_fiscalyears_ids = account_fiscalyear_obj.search(cr, uid, [])
            all_fiscalyears = account_fiscalyear_obj.browse(cr, uid, all_fiscalyears_ids)
            for current_fiscalyear in all_fiscalyears:
                if (current_fiscalyear.date_start < fiscalyear.date_start and current_fiscalyear.date_start > fiscalyear_select.date_start) or (current_fiscalyear.date_start < fiscalyear.date_start and fiscalyear == fiscalyear_select):
                    fiscalyear_select = current_fiscalyear
            if fiscalyear_select == fiscalyear:
                raise osv.except_osv(_('Error fiscal year'),_('There is no previous period to compare'))
            period_select = self.get_last_period_fiscalyear(cr, uid, fiscalyear_select)
        return period_select
        
    def get_fiscalyear(self, cr, uid, start_period):
        fiscalyear = start_period.fiscalyear_id
        return fiscalyear
     
    def get_data(self, cr, uid, data, context={}):
        account_account_obj = self.pool.get('account.account')
        library_obj = self.pool.get('account.webkit.report.library')
        
        #TODO: remove dependency of c2c
        account_chart_id = self._get_form_param('chart_account_id', data)
        
        account_chart = account_account_obj.browse(cr, uid, account_chart_id)
        company_id = account_chart['company_id'].id
        category_account_ids = library_obj.get_category_accounts(cr, uid, company_id)
        period = self._get_form_param('period_from', data)
        last_period = self.get_last_period(cr, uid, period.id)
        fiscal_year = self.get_fiscalyear(cr, uid, period.id)
        
        #build accounts list
        income_accounts = [category_account_ids['income']]
        income_accounts.append(library_obj.get_account_child_ids(cr, uid, category_account_ids['income']))
        expense_accounts = [category_account_ids['expense']]
        expense_accounts.append(library_obj.get_account_child_ids(cr, uid, category_account_ids['expense']))
        
        #build account_ids list
        income_account_ids = []
        expense_account_ids = []
{'fraction_non_alphanumeric': 0.11550712489522214, 'fraction_numerical': 0.001760268231349539, 'mean_word_length': 3.3087757313109427, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '6960722', 'n_tokens_mistral': 3553, 'n_tokens_neox': 3497, 'n_words': 797}