From 451b26523d7c1039ee2fd8c6202b9d04ec4dae66 Mon Sep 17 00:00:00 2001 From: AjmalCybro Date: Wed, 30 Aug 2023 11:41:56 +0530 Subject: [PATCH] Aug 30 [FIX] : Bug Fixed 'dynamic_accounts_report' --- dynamic_accounts_report/__manifest__.py | 2 +- .../controllers/__init__.py | 23 +- .../controllers/controllers.py | 33 +- dynamic_accounts_report/doc/RELEASE_NOTES.md | 5 + dynamic_accounts_report/models/__init__.py | 21 + .../models/account_account_custom.py | 102 +- dynamic_accounts_report/models/move_line.py | 90 +- dynamic_accounts_report/report/__init__.py | 21 + dynamic_accounts_report/report/ageing.py | 29 +- .../report/cash_flow_report.py | 25 +- dynamic_accounts_report/report/daybook.py | 30 +- .../report/financial_reports.py | 23 +- .../report/general_ledger.py | 41 +- .../report/partner_ledger.py | 34 +- .../report/partner_ledger.xml | 9 +- .../report/trial_balance.py | 34 +- .../static/description/index.html | 1 - .../static/src/js/ageing.js | 868 ++++++++-------- .../static/src/js/cash_flow.js | 775 +++++++------- .../static/src/js/daybook.js | 878 ++++++++-------- .../static/src/js/financial_reports.js | 753 +++++++------- .../static/src/js/general_ledger.js | 978 +++++++++--------- .../static/src/js/partner_ledger.js | 934 +++++++++-------- .../static/src/js/trial_balance.js | 672 ++++++------ .../static/src/xml/financial_reports_view.xml | 356 ++----- .../static/src/xml/general_ledger_view.xml | 409 +++----- .../static/src/xml/partner_ledger_view.xml | 115 +- dynamic_accounts_report/wizard/__init__.py | 21 + dynamic_accounts_report/wizard/ageing.py | 115 +- .../wizard/balance_sheet.py | 58 +- .../wizard/balance_sheet_config.py | 79 +- dynamic_accounts_report/wizard/cash_flow.py | 72 +- dynamic_accounts_report/wizard/daybook.py | 22 + .../wizard/general_ledger.py | 347 ++++--- .../wizard/partner_leadger.py | 164 +-- .../wizard/trial_balance.py | 21 + 36 files changed, 4107 insertions(+), 4053 deletions(-) diff --git a/dynamic_accounts_report/__manifest__.py b/dynamic_accounts_report/__manifest__.py index bd0923958..16c5ec060 100644 --- a/dynamic_accounts_report/__manifest__.py +++ b/dynamic_accounts_report/__manifest__.py @@ -22,7 +22,7 @@ { 'name': 'Dynamic Financial Reports V16', - 'version': '16.0.1.0.5', + 'version': '16.0.1.0.6', 'category': 'Accounting', 'live_test_url': 'https://www.youtube.com/watch?v=gVQi9q9Rs-E&t=5s', 'summary': """Dynamic Financial Reports with drill diff --git a/dynamic_accounts_report/controllers/__init__.py b/dynamic_accounts_report/controllers/__init__.py index 457bae27e..39a2853b1 100644 --- a/dynamic_accounts_report/controllers/__init__.py +++ b/dynamic_accounts_report/controllers/__init__.py @@ -1,3 +1,22 @@ # -*- coding: utf-8 -*- - -from . import controllers \ No newline at end of file +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# +from . import controllers diff --git a/dynamic_accounts_report/controllers/controllers.py b/dynamic_accounts_report/controllers/controllers.py index 9fe69d514..ba10bec88 100644 --- a/dynamic_accounts_report/controllers/controllers.py +++ b/dynamic_accounts_report/controllers/controllers.py @@ -1,5 +1,24 @@ # -*- coding: utf-8 -*- - +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# import json from odoo import http from odoo.http import content_disposition, request @@ -8,8 +27,10 @@ from odoo.tools import html_escape class TBXLSXReportController(http.Controller): - @http.route('/dynamic_xlsx_reports', type='http', auth='user', methods=['POST'], csrf=False) - def get_report_xlsx(self, model, options, output_format, report_data, report_name, dfr_data, **kw): + @http.route('/dynamic_xlsx_reports', type='http', auth='user', + methods=['POST'], csrf=False) + def get_report_xlsx(self, model, options, output_format, report_data, + report_name, dfr_data, **kw): uid = request.session.uid report_obj = request.env[model].with_user(uid) dfr_data = dfr_data @@ -21,10 +42,12 @@ class TBXLSXReportController(http.Controller): None, headers=[ ('Content-Type', 'application/vnd.ms-excel'), - ('Content-Disposition', content_disposition(report_name + '.xlsx')) + ('Content-Disposition', + content_disposition(report_name + '.xlsx')) ] ) - report_obj.get_dynamic_xlsx_report(options, response, report_data, dfr_data) + report_obj.get_dynamic_xlsx_report(options, response, + report_data, dfr_data) response.set_cookie('fileToken', token) return response except Exception as e: diff --git a/dynamic_accounts_report/doc/RELEASE_NOTES.md b/dynamic_accounts_report/doc/RELEASE_NOTES.md index d23d00c9a..cfdf454d9 100644 --- a/dynamic_accounts_report/doc/RELEASE_NOTES.md +++ b/dynamic_accounts_report/doc/RELEASE_NOTES.md @@ -19,3 +19,8 @@ #### Version 16.0.1.0.5 #### BUGFIX - Report Bug Fix: Journal filter is not visible for any languages other than english, entries of all journals are taken for bank book and cash book for other languages. + +#### 24.08.2023 +#### Version 16.0.1.0.6 +#### BUGFIX +- Report Bug Fix: The issues with the analytic filter in the general ledger, partner ledger, and profit and loss statement have been fixed, and the problem with language while printing reports has also been addressed. \ No newline at end of file diff --git a/dynamic_accounts_report/models/__init__.py b/dynamic_accounts_report/models/__init__.py index e8e069cef..e37fcdeb7 100644 --- a/dynamic_accounts_report/models/__init__.py +++ b/dynamic_accounts_report/models/__init__.py @@ -1,2 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# from . import move_line from . import account_account_custom diff --git a/dynamic_accounts_report/models/account_account_custom.py b/dynamic_accounts_report/models/account_account_custom.py index 77c826135..5718efe9c 100644 --- a/dynamic_accounts_report/models/account_account_custom.py +++ b/dynamic_accounts_report/models/account_account_custom.py @@ -1,3 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# from odoo import models, api @@ -10,39 +31,42 @@ class AccountAccountCustom(models.Model): if res.account_type.startswith("asset"): for record in self.env['account.financial.report'].search( [('type', '=', 'account_type')]): - if record.get_metadata()[0].get( - 'xmlid') == 'base_accounting_kit.account_financial_report_assets0': + if (record.get_metadata()[0].get('xmlid') == + 'base_accounting_kit.account_financial_report_assets0'): record.write({"account_ids": [(4, res.id)]}) elif res.account_type.startswith( "liability") or res.account_type == "equity": for record in self.env['account.financial.report'].search( [('type', '=', 'account_type')]): - if record.get_metadata()[0].get( - 'xmlid') == 'base_accounting_kit.account_financial_report_liability0': + if (record.get_metadata()[0].get('xmlid') == + 'base_accounting_kit' + '.account_financial_report_liability0'): record.write({"account_ids": [(4, res.id)]}) elif res.account_type in ['expense', 'expense_depreciation']: for record in self.env['account.financial.report'].search( [('type', '=', 'account_type')]): - if record.get_metadata()[0].get( - 'xmlid') == 'base_accounting_kit.account_financial_report_expense0': + if (record.get_metadata()[0].get('xmlid') == + 'base_accounting_kit.account_financial_report_expense0'): record.write({"account_ids": [(4, res.id)]}) elif res.account_type == "expense_direct_cost": for record in self.env['account.financial.report'].search( [('type', '=', 'account_type')]): - if record.get_metadata()[0].get( - 'xmlid') == 'base_accounting_kit.financial_report_cost_of_revenue': + if (record.get_metadata()[0].get('xmlid') == + 'base_accounting_kit.financial_report_cost_of_revenue'): record.write({"account_ids": [(4, res.id)]}) elif res.account_type in ['income', 'equity_unaffected']: for record in self.env['account.financial.report'].search( [('type', '=', 'account_type')]): - if record.get_metadata()[0].get( - 'xmlid') == 'base_accounting_kit.account_financial_report_operating_income0': + if (record.get_metadata()[0].get('xmlid') == + 'base_accounting_kit' + '.account_financial_report_operating_income0'): record.write({"account_ids": [(4, res.id)]}) elif res.account_type == 'income_other': for record in self.env['account.financial.report'].search( [('type', '=', 'account_type')]): - if record.get_metadata()[0].get( - 'xmlid') == 'base_accounting_kit.account_financial_report_other_income0': + if (record.get_metadata()[0].get('xmlid') == + 'base_accounting_kit' + '.account_financial_report_other_income0'): record.write({"account_ids": [(4, res.id)]}) return res @@ -55,51 +79,57 @@ class AccountAccountCustom(models.Model): record.write({"account_ids": [(3, rec.id)]}) if self.account_type.startswith("asset"): for record1 in self.env[ - 'account.financial.report'].search( - [('type', '=', 'account_type')]): - if record1.get_metadata()[0].get( - 'xmlid') == 'base_accounting_kit.account_financial_report_assets0': + 'account.financial.report'].search([( + 'type', '=', 'account_type')]): + if (record1.get_metadata()[0].get('xmlid') == + 'base_accounting_kit' + '.account_financial_report_assets0'): record1.write( {"account_ids": [(4, self._origin.id)]}) elif self.account_type.startswith( "liability") or self.account_type == "equity": for record1 in self.env[ - 'account.financial.report'].search( - [('type', '=', 'account_type')]): - if record1.get_metadata()[0].get( - 'xmlid') == 'base_accounting_kit.account_financial_report_liability0': + 'account.financial.report'].search([( + 'type', '=', 'account_type')]): + if (record1.get_metadata()[0].get('xmlid') == + 'base_accounting_kit' + '.account_financial_report_liability0'): record1.write( {"account_ids": [(4, self._origin.id)]}) elif self.account_type in ['expense', 'expense_depreciation']: for record1 in self.env[ - 'account.financial.report'].search( - [('type', '=', 'account_type')]): - if record1.get_metadata()[0].get( - 'xmlid') == 'base_accounting_kit.account_financial_report_expense0': + 'account.financial.report'].search([( + 'type', '=', 'account_type')]): + if (record1.get_metadata()[0].get('xmlid') == + 'base_accounting_kit' + '.account_financial_report_expense0'): record1.write( {"account_ids": [(4, self._origin.id)]}) elif self.account_type == "expense_direct_cost": for record1 in self.env[ - 'account.financial.report'].search( - [('type', '=', 'account_type')]): - if record1.get_metadata()[0].get( - 'xmlid') == 'base_accounting_kit.financial_report_cost_of_revenue': + 'account.financial.report'].search([( + 'type', '=', 'account_type')]): + if (record1.get_metadata()[0].get('xmlid') == + 'base_accounting_kit' + '.financial_report_cost_of_revenue'): record1.write( {"account_ids": [(4, self._origin.id)]}) elif self.account_type in ['income', 'equity_unaffected']: for record1 in self.env[ - 'account.financial.report'].search( - [('type', '=', 'account_type')]): - if record1.get_metadata()[0].get( - 'xmlid') == 'base_accounting_kit.account_financial_report_operating_income0': + 'account.financial.report'].search([( + 'type', '=', 'account_type')]): + if (record1.get_metadata()[0].get('xmlid') == + 'base_accounting_kit' + '.account_financial_report_operating_income0'): record1.write( {"account_ids": [(4, self._origin.id)]}) elif self.account_type == 'income_other': for record1 in self.env[ - 'account.financial.report'].search( - [('type', '=', 'account_type')]): - if record1.get_metadata()[0].get( - 'xmlid') == 'base_accounting_kit.account_financial_report_other_income0': + 'account.financial.report'].search([( + 'type', '=', 'account_type')]): + if (record1.get_metadata()[0].get('xmlid') == + 'base_accounting_kit' + '.account_financial_report_other_income0'): record1.write( {"account_ids": [(4, self._origin.id)]}) diff --git a/dynamic_accounts_report/models/move_line.py b/dynamic_accounts_report/models/move_line.py index 01722201e..71df66ddc 100644 --- a/dynamic_accounts_report/models/move_line.py +++ b/dynamic_accounts_report/models/move_line.py @@ -1,19 +1,36 @@ -from odoo import fields, models, api, _ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# +from odoo import api, models from odoo.http import request import ast -from odoo.exceptions import AccessError, UserError, AccessDenied class AccountMoveLine(models.Model): - _inherit = "account.move.line" - """Function is updated to avoid conflict for new and old odoo V15 addons""" - + _inherit = "account.move.line" @api.model def _query_get(self, domain=None): self.check_access_rights('read') - context = dict(self._context or {}) domain = domain or [] if not isinstance(domain, (list, tuple)): @@ -26,71 +43,56 @@ class AccountMoveLine(models.Model): domain += [(date_field, '<=', context['date_to'])] if context.get('date_from'): if not context.get('strict_range'): - domain += ['|', (date_field, '>=', context['date_from']), ('account_id.include_initial_balance', '=', True)] + domain += ['|', (date_field, '>=', context['date_from']), + ('account_id.include_initial_balance', '=', True)] elif context.get('initial_bal'): domain += [(date_field, '<', context['date_from'])] else: domain += [(date_field, '>=', context['date_from'])] - if context.get('journal_ids'): - domain += [('journal_id', 'in', context['journal_ids'])] - state = context.get('state') if state and state.lower() != 'all': domain += [('parent_state', '=', state)] - - # if context.get('company_id'): - # domain += [('company_id', '=', context['company_id'])] - # elif context.get('allowed_company_ids'): - # domain += [('company_id', 'in', self.env.companies.ids)] - # else: - # domain += [('company_id', '=', self.env.company.id)] - if context.get('reconcile_date'): - domain += ['|', ('reconciled', '=', False), '|', ('matched_debit_ids.max_date', '>', context['reconcile_date']), ('matched_credit_ids.max_date', '>', context['reconcile_date'])] - + domain += ['|', ('reconciled', '=', False), '|', ( + 'matched_debit_ids.max_date', '>', context['reconcile_date']), + ( + 'matched_credit_ids.max_date', '>', + context['reconcile_date'])] if context.get('account_tag_ids'): - domain += [('account_id.tag_ids', 'in', context['account_tag_ids'].ids)] - + domain += [ + ('account_id.tag_ids', 'in', context['account_tag_ids'].ids)] + if context.get('journal_ids'): + domain += [('journal_id', 'in', context['journal_ids'])] if context.get('account_ids'): domain += [('account_id', 'in', context['account_ids'].ids)] - - # if context.get('analytic_tag_ids'): - # domain += [('analytic_tag_ids', 'in', context['analytic_tag_ids'].ids)] - - if context.get('analytic_account_ids'): - domain += [('analytic_account_id', 'in', context['analytic_account_ids'].ids)] - + if context.get('analytic_line_ids'): + domain += [ + ('analytic_line_ids', 'in', context['analytic_line_ids'].ids)] if context.get('partner_ids'): domain += [('partner_id', 'in', context['partner_ids'].ids)] - if context.get('partner_categories'): - domain += [('partner_id.category_id', 'in', context['partner_categories'].ids)] - + domain += [('partner_id.category_id', 'in', + context['partner_categories'].ids)] company_ids = self.get_current_company_value() - - domain += [('company_id', 'in', company_ids)] - where_clause = "" where_clause_params = [] tables = '' if domain: - domain.append(('display_type', 'not in', ('line_section', 'line_note'))) + domain.append( + ('display_type', 'not in', ('line_section', 'line_note'))) domain.append(('parent_state', '!=', 'cancel')) - query = self._where_calc(domain) - - # Wrap the query with 'company_id IN (...)' to avoid bypassing company access rights. + # Wrap the query with 'company_id IN (...)' to avoid bypassing + # company access rights. self._apply_ir_rules(query) - tables, where_clause, where_clause_params = query.get_sql() return tables, where_clause, where_clause_params - def get_current_company_value(self): - - cookies_cids = [int(r) for r in request.httprequest.cookies.get('cids').split(",")] \ + cookies_cids = [int(r) for r in + request.httprequest.cookies.get('cids').split(",")] \ if request.httprequest.cookies.get('cids') \ else [request.env.user.company_id.id] for company_id in cookies_cids: @@ -100,4 +102,4 @@ class AccountMoveLine(models.Model): cookies_cids = [self.env.company.id] if len(cookies_cids) == 1: cookies_cids.append(0) - return cookies_cids \ No newline at end of file + return cookies_cids diff --git a/dynamic_accounts_report/report/__init__.py b/dynamic_accounts_report/report/__init__.py index 5838e7a2f..60d52b5a3 100644 --- a/dynamic_accounts_report/report/__init__.py +++ b/dynamic_accounts_report/report/__init__.py @@ -1,3 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# from . import trial_balance from . import general_ledger from . import cash_flow_report diff --git a/dynamic_accounts_report/report/ageing.py b/dynamic_accounts_report/report/ageing.py index 3764f7f73..50af95564 100644 --- a/dynamic_accounts_report/report/ageing.py +++ b/dynamic_accounts_report/report/ageing.py @@ -1,19 +1,38 @@ -from odoo import api, models, _ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# +from odoo import api, models class PartnerAgeing(models.AbstractModel): _name = 'report.dynamic_accounts_report.partner_ageing' @api.model - def _get_report_values(self, docids, data=None): + def _get_report_values(self,docids, data=None): + print(data) if self.env.context.get('ageing_pdf_report'): - if data.get('report_data'): data.update( {'account_data': data.get('report_data')['report_lines'][0], 'Filters': data.get('report_data')['filters'], 'company': self.env.company, - }) - return data diff --git a/dynamic_accounts_report/report/cash_flow_report.py b/dynamic_accounts_report/report/cash_flow_report.py index b8077ecd8..270707bc6 100644 --- a/dynamic_accounts_report/report/cash_flow_report.py +++ b/dynamic_accounts_report/report/cash_flow_report.py @@ -1,11 +1,32 @@ -from odoo import api, models, _ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# +from odoo import api, models class GeneralLedger(models.AbstractModel): _name = 'report.dynamic_accounts_report.cash_flow' @api.model - def _get_report_values(self, docids, data=None): + def _get_report_values(self,docids, data=None): if self.env.context.get('trial_pdf_report'): if data.get('report_data'): diff --git a/dynamic_accounts_report/report/daybook.py b/dynamic_accounts_report/report/daybook.py index 4af37cec4..87de32376 100644 --- a/dynamic_accounts_report/report/daybook.py +++ b/dynamic_accounts_report/report/daybook.py @@ -1,17 +1,39 @@ -from odoo import api, models, _ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# +from odoo import api, models class DayBook(models.AbstractModel): _name = 'report.dynamic_accounts_report.day_book' @api.model - def _get_report_values(self, docids, data=None): + def _get_report_values(self,docids, data=None): if self.env.context.get('daybook_pdf_report'): if data.get('report_data'): - data.update({'account_data': data.get('report_data')['report_lines'], + data.update({'account_data': data.get('report_data')[ + 'report_lines'], 'Filters': data.get('report_data')['filters'], 'company': self.env.company, }) - return data \ No newline at end of file + return data diff --git a/dynamic_accounts_report/report/financial_reports.py b/dynamic_accounts_report/report/financial_reports.py index 76c6bdd37..ed414e3a3 100644 --- a/dynamic_accounts_report/report/financial_reports.py +++ b/dynamic_accounts_report/report/financial_reports.py @@ -1,5 +1,25 @@ # -*- coding: utf-8 -*- -from odoo import api, models, _ +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# +from odoo import api, models class InsReportBalanceSheet(models.AbstractModel): @@ -10,6 +30,7 @@ class InsReportBalanceSheet(models.AbstractModel): if self.env.context.get('bs_report'): if data.get('report_data'): data.update({ + 'doc_ids': docids, 'Filters': data.get('report_data')['filters'], 'account_data': data.get('report_data')['report_lines'], 'report_lines': data.get('report_data')['bs_lines'], diff --git a/dynamic_accounts_report/report/general_ledger.py b/dynamic_accounts_report/report/general_ledger.py index e3a166eb6..2b81b1d75 100644 --- a/dynamic_accounts_report/report/general_ledger.py +++ b/dynamic_accounts_report/report/general_ledger.py @@ -1,4 +1,25 @@ -from odoo import api, models, _ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# +from odoo import api, models class GeneralLedger(models.AbstractModel): @@ -6,14 +27,16 @@ class GeneralLedger(models.AbstractModel): @api.model def _get_report_values(self, docids, data=None): + print('_get_report_values........',data) if self.env.context.get('trial_pdf_report'): if data.get('report_data'): - data.update({'account_data': data.get('report_data')['report_lines'], - 'Filters': data.get('report_data')['filters'], - 'debit_total': data.get('report_data')['debit_total'], - 'credit_total': data.get('report_data')['credit_total'], - 'title': data.get('report_data')['name'], - 'eng_title': data.get('report_data')['eng_title'], - 'company': self.env.company, - }) + data.update( + {'doc_ids': docids, + 'account_data': data.get('report_data')['report_lines'], + 'Filters': data.get('report_data')['filters'], + 'debit_total': data.get('report_data')['debit_total'], + 'credit_total': data.get('report_data')['credit_total'], + 'title': data.get('report_data')['name'], + 'company': self.env.company, + }) return data diff --git a/dynamic_accounts_report/report/partner_ledger.py b/dynamic_accounts_report/report/partner_ledger.py index fe97bcae5..641cf133c 100644 --- a/dynamic_accounts_report/report/partner_ledger.py +++ b/dynamic_accounts_report/report/partner_ledger.py @@ -1,4 +1,25 @@ -from odoo import api, models, _ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# +from odoo import api, models class PartnerLedgerReport(models.AbstractModel): @@ -7,10 +28,11 @@ class PartnerLedgerReport(models.AbstractModel): @api.model def _get_report_values(self, docids, data=None): if self.env.context.get('partner_ledger_pdf_report'): - if data.get('report_data'): - data.update({'account_data': data.get('report_data')['report_lines'], - 'Filters': data.get('report_data')['filters'], - 'company': self.env.company, - }) + data.update({ + 'doc_ids': docids, + 'account_data': data.get('report_data')['report_lines'], + 'Filters': data.get('report_data')['filters'], + 'company': self.env.company, + }) return data diff --git a/dynamic_accounts_report/report/partner_ledger.xml b/dynamic_accounts_report/report/partner_ledger.xml index 0237eac20..113fda6f9 100644 --- a/dynamic_accounts_report/report/partner_ledger.xml +++ b/dynamic_accounts_report/report/partner_ledger.xml @@ -60,11 +60,9 @@
Account Type: -
  • - +
  • -
    Target move: @@ -72,14 +70,10 @@
    - -
    - -

    @@ -117,7 +111,6 @@ -"; - if(datas.currency[1]=='after'){ - temp_str += ""; - temp_str += ""; - - } - else{ - temp_str += ""; - temp_str += ""; - - } - return temp_str; - }, - - - journal_line_click: function (el){ - click_num++; - var self = this; - var line = $(el.target).parent().data('id'); - - return self.do_action({ - type: 'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: 'account.move', - views: [ - [false, 'form'] - ], - res_id: line, - target: 'current', - }); - - }, - - show_drop_down: function(event) { - event.preventDefault(); - var self = this; - var account_id = $(event.currentTarget).data('account-id'); - - var partner_id = $(event.currentTarget)[0].cells[0].innerText; - - var offset = 0; - var td = $(event.currentTarget).next('tr').find('td'); - if (td.length == 1) { - - self._rpc({ - model: 'account.partner.ageing', - method: 'view_report', - args: [ - [self.wizard_id] - ], - }).then(function(data) { - - _.each(data['report_lines'][0], function(rep_lines) { - _.each(rep_lines['child_lines'], function(child_line) { - child_line.amount = self.format_currency(data['currency'],child_line.amount); - - }); - }); - - - for (var i = 0; i < data['report_lines'][0].length; i++) { - if (account_id == data['report_lines'][0][i]['partner_id'] ){ - $(event.currentTarget).next('tr').find('td').remove(); - $(event.currentTarget).next('tr').after( - QWeb.render('SubSectional', { - account_data: data['report_lines'][0][i]['child_lines'], - id : data['report_lines'][0][i]['partner_id'] - })) - $(event.currentTarget).next('tr').find('td ul li:first a').css({ - 'background-color': '#00ede8', - 'font-weight': 'bold', - }); - } - } - - }); - } - }, - - view_acc_move: function(event) { - event.preventDefault(); - var self = this; - var context = {}; - var show_acc_move = function(res_model, res_id, view_id) { - var action = { - type: 'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: res_model, - views: [ - [view_id || false, 'form'] - ], - res_id: res_id, - target: 'current', - context: context, - }; - return self.do_action(action); - }; - rpc.query({ - model: 'account.move', - method: 'search_read', - domain: [ - ['id', '=', $(event.currentTarget).data('move-id')] - ], - fields: ['id'], - limit: 1, - }) - .then(function(record) { - if (record.length > 0) { - show_acc_move('account.move', record[0].id); - } else { - show_acc_move('account.move', $(event.currentTarget).data('move-id')); - } - }); - }, - - - apply_filter: function(event) { - event.preventDefault(); - var self = this; - self.initial_render = false; - - var filter_data_selected = {}; - - if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { - filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } - - - - - - var partner_ids = []; - var partner_text = []; - var span_res = document.getElementById("partner_res") - var partner_list = $(".partners").select2('data') - for (var i = 0; i < partner_list.length; i++) { - if(partner_list[i].element[0].selected === true) - {partner_ids.push(parseInt(partner_list[i].id)) - if(partner_text.includes(partner_list[i].text) === false) - {partner_text.push(partner_list[i].text) - } - span_res.value = partner_text - span_res.innerHTML=span_res.value; - } - } - if (partner_list.length == 0){ - span_res.value = "" - span_res.innerHTML=""; - } - filter_data_selected.partner_ids = partner_ids - - var partner_category_ids = []; - var partner_category_text = []; - var span_res = document.getElementById("category_res") - var category_list = $(".category").select2('data') - - for (var i = 0; i < category_list.length; i++) { - if(category_list[i].element[0].selected === true) - {partner_category_ids.push(parseInt(category_list[i].id)) - if(partner_category_text.includes(category_list[i].text) === false) - {partner_category_text.push(category_list[i].text) - } - span_res.value = partner_category_text - span_res.innerHTML=span_res.value; - } - } - if (category_list.length == 0){ - span_res.value = "" - span_res.innerHTML=""; - } - filter_data_selected.partner_category_ids = partner_category_ids - - - if ($(".target_move").length) { - - var post_res = document.getElementById("post_res") - filter_data_selected.target_move = $(".target_move")[1].value - - post_res.value = $(".target_move")[1].value - post_res.innerHTML=post_res.value; - if ($(".target_move")[1].value == "") { - post_res.innerHTML="posted"; - - } - } - - if ($(".result_selection").length) { - var account_res = document.getElementById("account_res") - filter_data_selected.result_selection = $(".result_selection")[1].value - account_res.value = $(".result_selection")[1].value - account_res.innerHTML=account_res.value; - if ($(".result_selection")[1].value == "") { - account_res.innerHTML="customer"; - - } - } - - - rpc.query({ - model: 'account.partner.ageing', - method: 'write', - args: [ - self.wizard_id, filter_data_selected - ], - }).then(function(res) { - self.initial_render = false; - self.load_data(self.initial_render); - }); - }, - - }); - core.action_registry.add("p_a", PartnerAgeing); - return PartnerAgeing; +odoo.define('dynamic_accounts_report.ageing', function(require) { + 'use strict'; + var AbstractAction = require('web.AbstractAction'); + var core = require('web.core'); + var field_utils = require('web.field_utils'); + var rpc = require('web.rpc'); + var session = require('web.session'); + var utils = require('web.utils'); + var QWeb = core.qweb; + var _t = core._t; + + var datepicker = require('web.datepicker'); + var time = require('web.time'); + window.click_num = 0; + var PartnerAgeing = AbstractAction.extend({ + template: 'AgeingTemp', + events: { + 'click .parent-line': 'journal_line_click', + 'click .child_col1': 'journal_line_click', + 'click #apply_filter': 'apply_filter', + 'click #pdf': 'print_pdf', + 'click #xlsx': 'print_xlsx', + 'click .gl-line': 'show_drop_down', + 'click .view-account-move': 'view_acc_move', + 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', + }, + + init: function(parent, action) { + this._super(parent, action); + this.currency = action.currency; + this.report_lines = action.report_lines; + + this.wizard_id = action.context.wizard | null; + + }, + + + start: function() { + var self = this; + self.initial_render = true; + rpc.query({ + model: 'account.partner.ageing', + method: 'create', + args: [{ + + }] + }).then(function(t_res) { + self.wizard_id = t_res; + + self.load_data(self.initial_render); + }) + }, + + _onCalendarIconClick: function(ev) { + var $calendarInputGroup = $(ev.currentTarget); + + var calendarOptions = { + + minDate: moment({ + y: 1000 + }), + maxDate: moment().add(200, 'y'), + calendarWeeks: true, + defaultDate: moment().format(), + sideBySide: true, + buttons: { + showClear: true, + showClose: true, + showToday: true, + }, + + icons: { + date: 'fa fa-calendar', + + }, + locale: moment.locale(), + format: time.getLangDateFormat(), + widgetParent: 'body', + allowInputToggle: true, + }; + + $calendarInputGroup.datetimepicker(calendarOptions); + }, + + + load_data: function(initial_render = true) { + + var self = this; + + self.$(".categ").empty(); + try { + var self = this; + self._rpc({ + model: 'account.partner.ageing', + method: 'view_report', + args: [ + [this.wizard_id] + ], + }).then(function(datas) { + _.each(datas['report_lines'][0], function(rep_lines) { + rep_lines.total = self.format_currency(datas['currency'], rep_lines.total); + rep_lines[4] = self.format_currency(datas['currency'], rep_lines[4]); + rep_lines[3] = self.format_currency(datas['currency'], rep_lines[3]); + rep_lines[2] = self.format_currency(datas['currency'], rep_lines[2]); + rep_lines[1] = self.format_currency(datas['currency'], rep_lines[1]); + rep_lines[0] = self.format_currency(datas['currency'], rep_lines[0]); + rep_lines['direction'] = self.format_currency(datas['currency'], rep_lines['direction']); + + }); + + if (initial_render) { + self.$('.filter_view_tb').html(QWeb.render('AgeingFilterView', { + filter_data: datas['filters'], + })); + self.$el.find('.partners').select2({ + placeholder: ' Partners...', + }); + self.$el.find('.category').select2({ + placeholder: ' Partner Category...', + }); + self.$el.find('.target_move').select2({ + placeholder: ' Target Move...', + }); + self.$el.find('.result_selection').select2({ + placeholder: ' Account Type...', + }); + + } + var child = []; + self.$('.table_view_tb').html(QWeb.render('Ageingtable', { + + report_lines: datas['report_lines'], + move_lines: datas['report_lines'][2], + filter: datas['filters'], + currency: datas['currency'], + })); + + }); + + } catch (el) { + window.location.href + } + }, + format_currency: function(currency, amount) { + if (typeof(amount) != 'number') { + amount = parseFloat(amount); + } + var formatted_value = (parseInt(amount)).toLocaleString(currency[2], { + minimumFractionDigits: 2 + }) + return formatted_value + }, + + print_pdf: function(e) { + e.preventDefault(); + + var self = this; + self._rpc({ + model: 'account.partner.ageing', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + var action = { + 'type': 'ir.actions.report', + 'report_type': 'qweb-pdf', + 'report_name': 'dynamic_accounts_report.partner_ageing', + 'report_file': 'dynamic_accounts_report.partner_ageing', + 'data': { + 'report_data': data + }, + 'context': { + 'active_model': 'account.partner.ageing', + 'landscape': 1, + 'ageing_pdf_report': true + + }, + 'display_name': 'Partner Ageing', + }; + + return self.do_action(action); + }); + }, + + + + print_xlsx: function() { + var self = this; + self._rpc({ + model: 'account.partner.ageing', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + + var action = { + // 'type': 'ir_actions_dynamic_xlsx_download', + 'data': { + 'model': 'account.partner.ageing', + 'options': JSON.stringify(data['filters']), + 'output_format': 'xlsx', + 'report_data': JSON.stringify(data['report_lines']), + 'report_name': 'Partner Ageing', + 'dfr_data': JSON.stringify(data), + }, + }; + // return self.do_action(action); + core.action_registry.map.t_b.prototype.downloadXlsx(action) + }); + }, + + + + + + create_lines_with_style: function(rec, attr, datas) { + var temp_str = ""; + var style_name = "border-bottom: 1px solid #e6e6e6;"; + var attr_name = attr + " style=" + style_name; + + + + temp_str += ""; + if (datas.currency[1] == 'after') { + temp_str += ""; + temp_str += ""; + + } else { + temp_str += ""; + temp_str += ""; + + } + return temp_str; + }, + + + journal_line_click: function(el) { + click_num++; + var self = this; + var line = $(el.target).parent().data('id'); + + return self.do_action({ + type: 'ir.actions.act_window', + view_type: 'form', + view_mode: 'form', + res_model: 'account.move', + views: [ + [false, 'form'] + ], + res_id: line, + target: 'current', + }); + + }, + + show_drop_down: function(event) { + event.preventDefault(); + var self = this; + var account_id = $(event.currentTarget).data('account-id'); + + var partner_id = $(event.currentTarget)[0].cells[0].innerText; + + var offset = 0; + var td = $(event.currentTarget).next('tr').find('td'); + if (td.length == 1) { + + self._rpc({ + model: 'account.partner.ageing', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + + _.each(data['report_lines'][0], function(rep_lines) { + _.each(rep_lines['child_lines'], function(child_line) { + child_line.amount = self.format_currency(data['currency'], child_line.amount); + + }); + }); + + + for (var i = 0; i < data['report_lines'][0].length; i++) { + if (account_id == data['report_lines'][0][i]['partner_id']) { + $(event.currentTarget).next('tr').find('td').remove(); + $(event.currentTarget).next('tr').after( + QWeb.render('SubSectional', { + account_data: data['report_lines'][0][i]['child_lines'], + id: data['report_lines'][0][i]['partner_id'] + })) + $(event.currentTarget).next('tr').find('td ul li:first a').css({ + 'background-color': '#00ede8', + 'font-weight': 'bold', + }); + } + } + + }); + } + }, + + view_acc_move: function(event) { + event.preventDefault(); + var self = this; + var context = {}; + var show_acc_move = function(res_model, res_id, view_id) { + var action = { + type: 'ir.actions.act_window', + view_type: 'form', + view_mode: 'form', + res_model: res_model, + views: [ + [view_id || false, 'form'] + ], + res_id: res_id, + target: 'current', + context: context, + }; + return self.do_action(action); + }; + rpc.query({ + model: 'account.move', + method: 'search_read', + domain: [ + ['id', '=', $(event.currentTarget).data('move-id')] + ], + fields: ['id'], + limit: 1, + }) + .then(function(record) { + if (record.length > 0) { + show_acc_move('account.move', record[0].id); + } else { + show_acc_move('account.move', $(event.currentTarget).data('move-id')); + } + }); + }, + + + apply_filter: function(event) { + event.preventDefault(); + var self = this; + self.initial_render = false; + var filter_data_selected = {}; + if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { + filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + var partner_ids = []; + var partner_text = []; + var span_res = document.getElementById("partner_res") + var partner_list = $(".partners").select2('data') + for (var i = 0; i < partner_list.length; i++) { + if (partner_list[i].element[0].selected === true) { + partner_ids.push(parseInt(partner_list[i].id)) + if (partner_text.includes(partner_list[i].text) === false) { + partner_text.push(partner_list[i].text) + } + span_res.value = partner_text + span_res.innerHTML = span_res.value; + } + } + if (partner_list.length == 0) { + span_res.value = "" + span_res.innerHTML = ""; + } + filter_data_selected.partner_ids = partner_ids + + var partner_category_ids = []; + var partner_category_text = []; + var span_res = document.getElementById("category_res") + var category_list = $(".category").select2('data') + + for (var i = 0; i < category_list.length; i++) { + if (category_list[i].element[0].selected === true) { + partner_category_ids.push(parseInt(category_list[i].id)) + if (partner_category_text.includes(category_list[i].text) === false) { + partner_category_text.push(category_list[i].text) + } + span_res.value = partner_category_text + span_res.innerHTML = span_res.value; + } + } + if (category_list.length == 0) { + span_res.value = "" + span_res.innerHTML = ""; + } + filter_data_selected.partner_category_ids = partner_category_ids + + + if ($(".target_move").length) { + + var post_res = document.getElementById("post_res") + filter_data_selected.target_move = $(".target_move")[1].value + + post_res.value = $(".target_move")[1].value + post_res.innerHTML = post_res.value; + if ($(".target_move")[1].value == "") { + post_res.innerHTML = "posted"; + + } + } + + if ($(".result_selection").length) { + var account_res = document.getElementById("account_res") + filter_data_selected.result_selection = $(".result_selection")[1].value + account_res.value = $(".result_selection")[1].value + account_res.innerHTML = account_res.value; + if ($(".result_selection")[1].value == "") { + account_res.innerHTML = "customer"; + + } + } + + + rpc.query({ + model: 'account.partner.ageing', + method: 'write', + args: [ + self.wizard_id, filter_data_selected + ], + }).then(function(res) { + self.initial_render = false; + self.load_data(self.initial_render); + }); + }, + + }); + core.action_registry.add("p_a", PartnerAgeing); + return PartnerAgeing; }); \ No newline at end of file diff --git a/dynamic_accounts_report/static/src/js/cash_flow.js b/dynamic_accounts_report/static/src/js/cash_flow.js index 5dd21db8e..5239de13f 100644 --- a/dynamic_accounts_report/static/src/js/cash_flow.js +++ b/dynamic_accounts_report/static/src/js/cash_flow.js @@ -1,386 +1,391 @@ -odoo.define('dynamic_cash_flow_statements.cash_flow', function (require) { - 'use strict'; - var AbstractAction = require('web.AbstractAction'); - var core = require('web.core'); - var field_utils = require('web.field_utils'); - var rpc = require('web.rpc'); - var session = require('web.session'); - var utils = require('web.utils'); - var QWeb = core.qweb; - var _t = core._t; - var framework = require('web.framework'); - - var datepicker = require('web.datepicker'); - var time = require('web.time'); - - window.click_num = 0; - var CashFlow = AbstractAction.extend({ - template: 'CFTemp', - events: { - 'click .parent-line': 'journal_line_click', - 'click .child_col1': 'journal_line_click', - 'click #apply_filter': 'apply_filter', - 'click #pdf': 'print_pdf', - 'click #xlsx': 'print_xlsx', - 'click .cf-line': 'get_move_lines', - 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', - }, - - init: function(parent, action) { - this._super(parent, action); - this.currency=action.currency; - this.report_lines = action.report_lines; - this.wizard_id = action.context.wizard | null; - }, - - - start: function() { - var self = this; - self.initial_render = true; - rpc.query({ - model: 'account.cash.flow', - method: 'create', - args: [{ - - }] - }).then(function(t_res) { - self.wizard_id = t_res; - self.load_data(self.initial_render); - }) - }, - _onCalendarIconClick: function (ev) { - var $calendarInputGroup = $(ev.currentTarget); - - var calendarOptions = { - - minDate: moment({ y: 1000 }), - maxDate: moment().add(200, 'y'), - calendarWeeks: true, - defaultDate: moment().format(), - sideBySide: true, - buttons: { - showClear: true, - showClose: true, - showToday: true, - }, - - icons : { - date: 'fa fa-calendar', - - }, - locale : moment.locale(), - format : time.getLangDateFormat(), - widgetParent: 'body', - allowInputToggle: true, - }; - - $calendarInputGroup.datetimepicker(calendarOptions); - }, - - get_move_lines: function(event) { - event.preventDefault(); - var self = this; - var account_id = $(event.currentTarget).data('account-id'); - var offset = 0; - var td = $(event.currentTarget).next('tr').find('td'); - if (td.length == 1) { - self._rpc({ - model: 'account.cash.flow', - method: 'view_report', - args: [ - [self.wizard_id] - ], - }).then(function(datas) { - _.each(datas['journal_res'], function(journal_lines) { - _.each(journal_lines['journal_lines'], function(rep_lines) { - rep_lines.total_debit = self.format_currency(datas['currency'],rep_lines.total_debit); - rep_lines.total_credit = self.format_currency(datas['currency'],rep_lines.total_credit); - rep_lines.balance = self.format_currency(datas['currency'],rep_lines.balance); - - - - - }); - - }); - _.each(datas['account_res'], function(journal_lines) { - _.each(journal_lines['journal_lines'], function(rep_lines) { - rep_lines.total_debit = self.format_currency(datas['currency'],rep_lines.total_debit); - rep_lines.total_credit = self.format_currency(datas['currency'],rep_lines.total_credit); - rep_lines.total_balance = self.format_currency(datas['currency'],rep_lines.total_balance); - - - }); - _.each(journal_lines['move_lines'], function(move_lines) { - move_lines.total_debit = self.format_currency(datas['currency'],move_lines.total_debit); - move_lines.total_credit = self.format_currency(datas['currency'],move_lines.total_credit); - move_lines.balance = self.format_currency(datas['currency'],move_lines.balance); - - - - - }); - }); - - - if(datas['levels']== 'detailed'){ - $(event.currentTarget).next('tr').find('td ul').after( - QWeb.render('SubSectionCF', { - count: 3, - offset: 0, - account_data: datas['journal_res'], - level:datas['levels'], - currency : datas['currency'], - line_id:parseInt(event.currentTarget.attributes[3].value), - })) - }else if(datas['levels']== 'very' || datas['levels']== false){ - $(event.currentTarget).next('tr').find('td ul').after( - QWeb.render('ChildSubSectionCF', { - count: 3, - offset: 0, - account_data: datas['account_res'], - level:datas['levels'], - currency : datas['currency'], - line_id:parseInt(event.currentTarget.attributes[3].value), - })) - } - - $(event.currentTarget).next('tr').find('td ul li:first a').css({ - 'background-color': '#00ede8', - 'font-weight': 'bold', - }); - }) - } - }, - - - load_data: function (initial_render = true) { - var self = this; - self.$(".categ").empty(); - try{ - var self = this; - self._rpc({ - model: 'account.cash.flow', - method: 'view_report', - args: [[this.wizard_id]], - }).then(function(datas) { - - - _.each(datas['fetched_data'], function(rep_lines) { - rep_lines.total_debit = self.format_currency(datas['currency'],rep_lines.total_debit); - rep_lines.total_credit = self.format_currency(datas['currency'],rep_lines.total_credit); - rep_lines.total_balance = self.format_currency(datas['currency'],rep_lines.total_balance); - - - - - }); - if (initial_render) { - self.$('.filter_view_tb').html(QWeb.render('CashFilterView', { - filter_data: datas['filters'], - })); - self.$el.find('.journals').select2({ - placeholder: 'Select Journals...', - }); - self.$el.find('.target_move').select2({ - placeholder: 'Target Move...', - }); - self.$el.find('.levels').select2({ - placeholder: 'Levels...', - }); - } - var child=[]; - - self.$('.table_view_tb').html(QWeb.render('CashTable', { - - account_data: datas['fetched_data'], - level:datas['levels'], - currency : datas['currency'], - })); - - }); - - } - catch (el) { - window.location.href - } - }, - - format_currency: function(currency, amount) { - if (typeof(amount) != 'number') { - amount = parseFloat(amount); - } - var formatted_value = (parseInt(amount)).toLocaleString(currency[2],{ - minimumFractionDigits: 2 - }) - return formatted_value - }, - - show_gl: function(e) { - var self = this; - var account_id = $(e.target).attr('data-account-id'); - var options = { - account_ids: [account_id], - } - - var action = { - type: 'ir.actions.client', - name: 'GL View', - tag: 'g_l', - target: 'new', - - domain: [['account_ids','=', account_id]], - - - } - return this.do_action(action); - - }, - print_pdf: function(e) { - e.preventDefault(); - var self = this; - self._rpc({ - model: 'account.cash.flow', - method: 'view_report', - args: [ - [self.wizard_id] - ], - }).then(function(data) { - var action = { - 'type': 'ir.actions.report', - 'report_type': 'qweb-pdf', - 'report_name': 'dynamic_accounts_report.cash_flow', - 'report_file': 'dynamic_accounts_report.cash_flow', - 'data': { - 'report_data': data - }, - 'context': { - 'active_model': 'account.cash.flow', - 'landscape': 1, - 'trial_pdf_report': true - }, - 'display_name': 'Cash Flow Statements', - }; - return self.do_action(action); - }); - }, - - - - print_xlsx: function() { - var self = this; - self._rpc({ - model: 'account.cash.flow', - method: 'view_report', - args: [ - [self.wizard_id] - ], - }).then(function(data) { - var action = { -// 'type': 'ir_actions_dynamic_xlsx_download', - 'data': { - 'model': 'account.cash.flow', - 'options': JSON.stringify(data['filters']), - 'output_format': 'xlsx', - 'report_data': JSON.stringify(data['report_lines']), - 'report_name': 'Cash Flow Statements', - 'dfr_data': JSON.stringify(data), - }, - }; -// return self.do_action(action); - self.downloadXlsx(action) - }); - }, - downloadXlsx: function (action){ - framework.blockUI(); - session.get_file({ - url: '/dynamic_xlsx_reports', - data: action.data, - complete: framework.unblockUI, - error: (error) => this.call('crash_manager', 'rpc_error', error), - }); - }, - - journal_line_click: function (el){ - click_num++; - var self = this; - var line = $(el.target).parent().data('id'); - return self.do_action({ - type: 'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: 'account.move', - views: [ - [false, 'form'] - ], - res_id: line, - target: 'current', - }); - - }, - - - apply_filter: function(event) { - - event.preventDefault(); - var self = this; - self.initial_render = false; - - var filter_data_selected = {}; - - - - if ($(".levels").length){ - var level_res = document.getElementById("level_res") - filter_data_selected.levels = $(".levels")[1].value - level_res.value = $(".levels")[1].value - level_res.innerHTML=level_res.value; - if ($(".levels").value==""){ - type_res.innerHTML="summary"; - filter_data_selected.type = "Summary" - } - } - -// if ($("#date_from").val()) { -// var dateString = $("#date_from").val(); -// filter_data_selected.date_from = dateString; -// } -// if ($("#date_to").val()) { -// var dateString = $("#date_to").val(); -// filter_data_selected.date_to = dateString; -// } - - if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { - filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } - - if (this.$el.find('.datetimepicker-input[name="date_to"]').val()) { - filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="date_to"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } - - if ($(".target_move").length) { - var post_res = document.getElementById("post_res") - filter_data_selected.target_move = $(".target_move")[1].value - post_res.value = $(".target_move")[1].value - post_res.innerHTML=post_res.value; - if ($(".target_move")[1].value == "") { - post_res.innerHTML="posted"; - - } - } - rpc.query({ - model: 'account.cash.flow', - method: 'write', - args: [ - self.wizard_id, filter_data_selected - ], - }).then(function(res) { - self.initial_render = false; - self.load_data(self.initial_render); - }); - }, - - }); - core.action_registry.add("c_f", CashFlow); - return CashFlow; +odoo.define('dynamic_cash_flow_statements.cash_flow', function(require) { + 'use strict'; + var AbstractAction = require('web.AbstractAction'); + var core = require('web.core'); + var field_utils = require('web.field_utils'); + var rpc = require('web.rpc'); + var session = require('web.session'); + var utils = require('web.utils'); + var QWeb = core.qweb; + var _t = core._t; + var framework = require('web.framework'); + + var datepicker = require('web.datepicker'); + var time = require('web.time'); + + window.click_num = 0; + var CashFlow = AbstractAction.extend({ + template: 'CFTemp', + events: { + 'click .parent-line': 'journal_line_click', + 'click .child_col1': 'journal_line_click', + 'click #apply_filter': 'apply_filter', + 'click #pdf': 'print_pdf', + 'click #xlsx': 'print_xlsx', + 'click .cf-line': 'get_move_lines', + 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', + }, + + init: function(parent, action) { + this._super(parent, action); + this.currency = action.currency; + this.report_lines = action.report_lines; + this.wizard_id = action.context.wizard | null; + }, + + + start: function() { + var self = this; + self.initial_render = true; + rpc.query({ + model: 'account.cash.flow', + method: 'create', + args: [{ + + }] + }).then(function(t_res) { + self.wizard_id = t_res; + self.load_data(self.initial_render); + }) + }, + _onCalendarIconClick: function(ev) { + var $calendarInputGroup = $(ev.currentTarget); + + var calendarOptions = { + + minDate: moment({ + y: 1000 + }), + maxDate: moment().add(200, 'y'), + calendarWeeks: true, + defaultDate: moment().format(), + sideBySide: true, + buttons: { + showClear: true, + showClose: true, + showToday: true, + }, + + icons: { + date: 'fa fa-calendar', + + }, + locale: moment.locale(), + format: time.getLangDateFormat(), + widgetParent: 'body', + allowInputToggle: true, + }; + + $calendarInputGroup.datetimepicker(calendarOptions); + }, + + get_move_lines: function(event) { + event.preventDefault(); + var self = this; + var account_id = $(event.currentTarget).data('account-id'); + var offset = 0; + var td = $(event.currentTarget).next('tr').find('td'); + if (td.length == 1) { + self._rpc({ + model: 'account.cash.flow', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(datas) { + _.each(datas['journal_res'], function(journal_lines) { + _.each(journal_lines['journal_lines'], function(rep_lines) { + rep_lines.total_debit = self.format_currency(datas['currency'], rep_lines.total_debit); + rep_lines.total_credit = self.format_currency(datas['currency'], rep_lines.total_credit); + rep_lines.balance = self.format_currency(datas['currency'], rep_lines.balance); + + + + + }); + + }); + _.each(datas['account_res'], function(journal_lines) { + _.each(journal_lines['journal_lines'], function(rep_lines) { + rep_lines.total_debit = self.format_currency(datas['currency'], rep_lines.total_debit); + rep_lines.total_credit = self.format_currency(datas['currency'], rep_lines.total_credit); + rep_lines.total_balance = self.format_currency(datas['currency'], rep_lines.total_balance); + + + }); + _.each(journal_lines['move_lines'], function(move_lines) { + move_lines.total_debit = self.format_currency(datas['currency'], move_lines.total_debit); + move_lines.total_credit = self.format_currency(datas['currency'], move_lines.total_credit); + move_lines.balance = self.format_currency(datas['currency'], move_lines.balance); + + + + + }); + }); + + + if (datas['levels'] == 'detailed') { + $(event.currentTarget).next('tr').find('td ul').after( + QWeb.render('SubSectionCF', { + count: 3, + offset: 0, + account_data: datas['journal_res'], + level: datas['levels'], + currency: datas['currency'], + line_id: parseInt(event.currentTarget.attributes[3].value), + })) + } else if (datas['levels'] == 'very' || datas['levels'] == false) { + $(event.currentTarget).next('tr').find('td ul').after( + QWeb.render('ChildSubSectionCF', { + count: 3, + offset: 0, + account_data: datas['account_res'], + level: datas['levels'], + currency: datas['currency'], + line_id: parseInt(event.currentTarget.attributes[3].value), + })) + } + + $(event.currentTarget).next('tr').find('td ul li:first a').css({ + 'background-color': '#00ede8', + 'font-weight': 'bold', + }); + }) + } + }, + + + load_data: function(initial_render = true) { + var self = this; + self.$(".categ").empty(); + try { + var self = this; + self._rpc({ + model: 'account.cash.flow', + method: 'view_report', + args: [ + [this.wizard_id] + ], + }).then(function(datas) { + + + _.each(datas['fetched_data'], function(rep_lines) { + rep_lines.total_debit = self.format_currency(datas['currency'], rep_lines.total_debit); + rep_lines.total_credit = self.format_currency(datas['currency'], rep_lines.total_credit); + rep_lines.total_balance = self.format_currency(datas['currency'], rep_lines.total_balance); + + + + + }); + if (initial_render) { + self.$('.filter_view_tb').html(QWeb.render('CashFilterView', { + filter_data: datas['filters'], + })); + self.$el.find('.journals').select2({ + placeholder: 'Select Journals...', + }); + self.$el.find('.target_move').select2({ + placeholder: 'Target Move...', + }); + self.$el.find('.levels').select2({ + placeholder: 'Levels...', + }); + } + var child = []; + + self.$('.table_view_tb').html(QWeb.render('CashTable', { + + account_data: datas['fetched_data'], + level: datas['levels'], + currency: datas['currency'], + })); + + }); + + } catch (el) { + window.location.href + } + }, + + format_currency: function(currency, amount) { + if (typeof(amount) != 'number') { + amount = parseFloat(amount); + } + var formatted_value = (parseInt(amount)).toLocaleString(currency[2], { + minimumFractionDigits: 2 + }) + return formatted_value + }, + + show_gl: function(e) { + var self = this; + var account_id = $(e.target).attr('data-account-id'); + var options = { + account_ids: [account_id], + } + + var action = { + type: 'ir.actions.client', + name: 'GL View', + tag: 'g_l', + target: 'new', + + domain: [ + ['account_ids', '=', account_id] + ], + + + } + return this.do_action(action); + + }, + print_pdf: function(e) { + e.preventDefault(); + var self = this; + self._rpc({ + model: 'account.cash.flow', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + var action = { + 'type': 'ir.actions.report', + 'report_type': 'qweb-pdf', + 'report_name': 'dynamic_accounts_report.cash_flow', + 'report_file': 'dynamic_accounts_report.cash_flow', + 'data': { + 'report_data': data + }, + 'context': { + 'active_model': 'account.cash.flow', + 'landscape': 1, + 'trial_pdf_report': true + }, + 'display_name': 'Cash Flow Statements', + }; + return self.do_action(action); + }); + }, + + + + print_xlsx: function() { + var self = this; + self._rpc({ + model: 'account.cash.flow', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + var action = { + // 'type': 'ir_actions_dynamic_xlsx_download', + 'data': { + 'model': 'account.cash.flow', + 'options': JSON.stringify(data['filters']), + 'output_format': 'xlsx', + 'report_data': JSON.stringify(data['report_lines']), + 'report_name': 'Cash Flow Statements', + 'dfr_data': JSON.stringify(data), + }, + }; + // return self.do_action(action); + self.downloadXlsx(action) + }); + }, + downloadXlsx: function(action) { + framework.blockUI(); + session.get_file({ + url: '/dynamic_xlsx_reports', + data: action.data, + complete: framework.unblockUI, + error: (error) => this.call('crash_manager', 'rpc_error', error), + }); + }, + + journal_line_click: function(el) { + click_num++; + var self = this; + var line = $(el.target).parent().data('id'); + return self.do_action({ + type: 'ir.actions.act_window', + view_type: 'form', + view_mode: 'form', + res_model: 'account.move', + views: [ + [false, 'form'] + ], + res_id: line, + target: 'current', + }); + + }, + + + apply_filter: function(event) { + + event.preventDefault(); + var self = this; + self.initial_render = false; + + var filter_data_selected = {}; + + + + if ($(".levels").length) { + var level_res = document.getElementById("level_res") + filter_data_selected.levels = $(".levels")[1].value + level_res.value = $(".levels")[1].value + level_res.innerHTML = level_res.value; + if ($(".levels").value == "") { + type_res.innerHTML = "summary"; + filter_data_selected.type = "Summary" + } + } + + // if ($("#date_from").val()) { + // var dateString = $("#date_from").val(); + // filter_data_selected.date_from = dateString; + // } + // if ($("#date_to").val()) { + // var dateString = $("#date_to").val(); + // filter_data_selected.date_to = dateString; + // } + + if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { + filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + + if (this.$el.find('.datetimepicker-input[name="date_to"]').val()) { + filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="date_to"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + + if ($(".target_move").length) { + var post_res = document.getElementById("post_res") + filter_data_selected.target_move = $(".target_move")[1].value + post_res.value = $(".target_move")[1].value + post_res.innerHTML = post_res.value; + if ($(".target_move")[1].value == "") { + post_res.innerHTML = "posted"; + + } + } + rpc.query({ + model: 'account.cash.flow', + method: 'write', + args: [ + self.wizard_id, filter_data_selected + ], + }).then(function(res) { + self.initial_render = false; + self.load_data(self.initial_render); + }); + }, + + }); + core.action_registry.add("c_f", CashFlow); + return CashFlow; }); \ No newline at end of file diff --git a/dynamic_accounts_report/static/src/js/daybook.js b/dynamic_accounts_report/static/src/js/daybook.js index beed54939..ac90ff0ee 100644 --- a/dynamic_accounts_report/static/src/js/daybook.js +++ b/dynamic_accounts_report/static/src/js/daybook.js @@ -1,439 +1,439 @@ -odoo.define('dynamic_partner_daybook.daybook', function (require) { - 'use strict'; - var AbstractAction = require('web.AbstractAction'); - var core = require('web.core'); - var field_utils = require('web.field_utils'); - var rpc = require('web.rpc'); - var session = require('web.session'); - var utils = require('web.utils'); - var QWeb = core.qweb; - var _t = core._t; - - var datepicker = require('web.datepicker'); - var time = require('web.time'); - var framework = require('web.framework'); - - window.click_num = 0; - var DayBook = AbstractAction.extend({ - template: 'DaybookTemp', - events: { - 'click .parent-line': 'journal_line_click', - 'click .child_col1': 'journal_line_click', - 'click #apply_filter': 'apply_filter', - 'click #pdf': 'print_pdf', - 'click #xlsx': 'print_xlsx', - 'click .db-line': 'show_drop_down', - 'click .view-account-move': 'view_acc_move', - 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', - }, - - init: function(parent, action) { - this._super(parent, action); - this.currency=action.currency; - this.report_lines = action.report_lines; - this.wizard_id = action.context.wizard | null; - }, - - - start: function() { - var self = this; - self.initial_render = true; - rpc.query({ - model: 'account.day.book', - method: 'create', - args: [{ - - }] - }).then(function(t_res) { - self.wizard_id = t_res; - self.load_data(self.initial_render); - }) - }, - - _onCalendarIconClick: function (ev) { - var $calendarInputGroup = $(ev.currentTarget); - - var calendarOptions = { - - minDate: moment({ y: 1000 }), - maxDate: moment().add(200, 'y'), - calendarWeeks: true, - defaultDate: moment().format(), - sideBySide: true, - buttons: { - showClear: true, - showClose: true, - showToday: true, - }, - - icons : { - date: 'fa fa-calendar', - - }, - locale : moment.locale(), - format : time.getLangDateFormat(), - widgetParent: 'body', - allowInputToggle: true, - }; - - $calendarInputGroup.datetimepicker(calendarOptions); - }, - - - load_data: function (initial_render = true) { - var self = this; - self.$(".categ").empty(); - try{ - var self = this; - self._rpc({ - model: 'account.day.book', - method: 'view_report', - args: [[this.wizard_id]], - }).then(function(datas) { - _.each(datas['report_lines'], function(rep_lines) { - rep_lines.debit = self.format_currency(datas['currency'],rep_lines.debit); - rep_lines.credit = self.format_currency(datas['currency'],rep_lines.credit); - rep_lines.balance = self.format_currency(datas['currency'],rep_lines.balance); - - }); - - if (initial_render) { - - self.$('.filter_view_db').html(QWeb.render('DayFilterView', { - filter_data: datas['filters'], - })); - self.$el.find('.journals').select2({ - placeholder: ' Journals...', - }); - self.$el.find('.account-partner').select2({ - placeholder: ' Accounts...', - }); - self.$el.find('.target_move').select2({ - placeholder: 'Target Move...', - }); - - - } - var child=[]; - - self.$('.table_view_db').html(QWeb.render('Daytable', { - - report_lines : datas['report_lines'], - filter : datas['filters'], - currency : datas['currency'], - })); - - }); - - } - catch (el) { - window.location.href - } - }, - - - format_currency: function(currency, amount) { - if (typeof(amount) != 'number') { - amount = parseFloat(amount); - } - var formatted_value = (parseInt(amount)).toLocaleString(currency[2],{ - minimumFractionDigits: 2 - }) - return formatted_value - }, - - print_pdf: function(e) { - e.preventDefault(); - - var self = this; - self._rpc({ - model: 'account.day.book', - method: 'view_report', - args: [ - [self.wizard_id] - ], - }).then(function(data) { - - var action = { - 'type': 'ir.actions.report', - 'report_type': 'qweb-pdf', - 'report_name': 'dynamic_accounts_report.day_book', - 'report_file': 'dynamic_accounts_report.day_book', - 'data': { - 'report_data': data - }, - 'context': { - 'active_model': 'account.day.book', - 'landscape': 1, - 'daybook_pdf_report': true - }, - 'display_name': 'Day Book', - }; - - return self.do_action(action); - }); - }, - - print_xlsx: function() { - var self = this; - self._rpc({ - model: 'account.day.book', - method: 'view_report', - args: [ - [self.wizard_id] - ], - }).then(function(data) { - var action = { -// 'type': 'ir_actions_dynamic_xlsx_download', - 'data': { - 'model': 'account.day.book', - 'options': JSON.stringify(data['filters']), - 'output_format': 'xlsx', - 'report_data': JSON.stringify(data['report_lines']), - 'report_name': 'Day Book', - 'dfr_data': JSON.stringify(data), - }, - }; -// return self.do_action(action); - self.downloadXlsx(action) - }); - }, - downloadXlsx: function (action){ - framework.blockUI(); - session.get_file({ - url: '/dynamic_xlsx_reports', - data: action.data, - complete: framework.unblockUI, - error: (error) => this.call('crash_manager', 'rpc_error', error), - }); - }, - - create_lines_with_style: function(rec, attr, datas) { - - var temp_str = ""; - var style_name = "border-bottom: 1px solid #e6e6e6;"; - var attr_name = attr + " style="+style_name; - temp_str += ""; - if(datas.currency[1]=='after'){ - temp_str += ""; - temp_str += ""; - } - else{ - temp_str += ""; - temp_str += ""; - } - return temp_str; - }, - - - journal_line_click: function (el){ - click_num++; - var self = this; - var line = $(el.target).parent().data('id'); - return self.do_action({ - type: 'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: 'account.move', - views: [ - [false, 'form'] - ], - res_id: line, - target: 'current', - }); - - }, - - show_drop_down: function(event) { - event.preventDefault(); - var self = this; - var account_id = $(event.currentTarget).data('account-id'); - var offset = 0; - var td = $(event.currentTarget).next('tr').find('td'); - if (td.length == 1) { - - self._rpc({ - model: 'account.day.book', - method: 'view_report', - args: [ - [self.wizard_id] - ], - }).then(function(data) { - _.each(data['report_lines'], function(rep_lines) { - _.each(rep_lines['child_lines'], function(move_line) { - - move_line.debit = self.format_currency(data['currency'],move_line.debit); - move_line.credit = self.format_currency(data['currency'],move_line.credit); - move_line.balance = self.format_currency(data['currency'],move_line.balance); - - - }); - }); - for (var i = 0; i < data['report_lines'].length; i++) { - - if (account_id == data['report_lines'][i]['id'] ){ - $(event.currentTarget).next('tr').find('td').remove(); - $(event.currentTarget).next('tr').after( - QWeb.render('SubSectiondb', { - - account_data: data['report_lines'][i]['child_lines'], - currency_symbol : data.currency[0], - id : data['report_lines'][i]['id'], - currency_position : data.currency[1], - })) - - $(event.currentTarget).next('tr').find('td ul li:first a').css({ - 'background-color': '#00ede8', - 'font-weight': 'bold', - }); - } - } - - }); - } - }, - - view_acc_move: function(event) { - - event.preventDefault(); - var self = this; - var context = {}; - var show_acc_move = function(res_model, res_id, view_id) { - var action = { - type: 'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: res_model, - views: [ - [view_id || false, 'form'] - ], - res_id: res_id, - target: 'current', - context: context, - }; - return self.do_action(action); - }; - rpc.query({ - model: 'account.move', - method: 'search_read', - domain: [ - ['id', '=', $(event.currentTarget).data('move-id')] - ], - fields: ['id'], - limit: 1, - }) - .then(function(record) { - - if (record.length > 0) { - show_acc_move('account.move', record[0].id); - } else { - show_acc_move('account.move', $(event.currentTarget).data('move-id')); - } - }); - }, - - - apply_filter: function(event) { - - event.preventDefault(); - var self = this; - self.initial_render = false; - - var filter_data_selected = {}; - - - var account_ids = []; - var account_text = []; - - var account_res = document.getElementById("acc_res") - - var account_list = $(".account-partner").select2('data') - for (var i = 0; i < account_list.length; i++) { - if(account_list[i].element[0].selected === true){ - - account_ids.push(parseInt(account_list[i].id)) - if(account_text.includes(account_list[i].text) === false){ - account_text.push(account_list[i].text) - } - account_res.value = account_text - account_res.innerHTML=account_res.value; - } - } - if (account_list.length == 0){ - account_res.value = "" - account_res.innerHTML=""; - - } - - filter_data_selected.account_ids = account_ids - - - - var journal_ids = []; - var journal_text = []; - var journal_res = document.getElementById("journal_res") - var journal_list = $(".journals").select2('data') - for (var i = 0; i < journal_list.length; i++) { - if(journal_list[i].element[0].selected === true){ - - journal_ids.push(parseInt(journal_list[i].id)) - if(journal_text.includes(journal_list[i].text) === false){ - journal_text.push(journal_list[i].text) - } - journal_res.value = journal_text - journal_res.innerHTML=journal_res.value; - } - } - if (journal_list.length == 0){ - journal_res.value = "" - journal_res.innerHTML=""; - - } - filter_data_selected.journal_ids = journal_ids - -// if ($("#date_from").val()) { -// var dateString = $("#date_from").val(); -// -// filter_data_selected.date_from = dateString; -// } -// if ($("#date_to").val()) { -// var dateString = $("#date_to").val(); -// filter_data_selected.date_to = dateString; -// } - - if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { - filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } - - if (this.$el.find('.datetimepicker-input[name="date_to"]').val()) { - filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="date_to"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } - - if ($(".target_move").length) { - - var post_res = document.getElementById("post_res") - filter_data_selected.target_move = $(".target_move")[1].value - post_res.value = $(".target_move")[1].value - post_res.innerHTML=post_res.value; - if ($(".target_move")[1].value == "") { - post_res.innerHTML="posted"; - - } - } - - rpc.query({ - model: 'account.day.book', - method: 'write', - args: [ - self.wizard_id, filter_data_selected - ], - }).then(function(res) { - self.initial_render = false; - self.load_data(self.initial_render); - }); - }, - - }); - core.action_registry.add("d_b", DayBook); - return DayBook; -}); +odoo.define('dynamic_partner_daybook.daybook', function(require) { + 'use strict'; + var AbstractAction = require('web.AbstractAction'); + var core = require('web.core'); + var field_utils = require('web.field_utils'); + var rpc = require('web.rpc'); + var session = require('web.session'); + var utils = require('web.utils'); + var QWeb = core.qweb; + var _t = core._t; + + var datepicker = require('web.datepicker'); + var time = require('web.time'); + var framework = require('web.framework'); + + window.click_num = 0; + var DayBook = AbstractAction.extend({ + template: 'DaybookTemp', + events: { + 'click .parent-line': 'journal_line_click', + 'click .child_col1': 'journal_line_click', + 'click #apply_filter': 'apply_filter', + 'click #pdf': 'print_pdf', + 'click #xlsx': 'print_xlsx', + 'click .db-line': 'show_drop_down', + 'click .view-account-move': 'view_acc_move', + 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', + }, + + init: function(parent, action) { + this._super(parent, action); + this.currency = action.currency; + this.report_lines = action.report_lines; + this.wizard_id = action.context.wizard | null; + }, + + + start: function() { + var self = this; + self.initial_render = true; + rpc.query({ + model: 'account.day.book', + method: 'create', + args: [{ + + }] + }).then(function(t_res) { + self.wizard_id = t_res; + self.load_data(self.initial_render); + }) + }, + + _onCalendarIconClick: function(ev) { + var $calendarInputGroup = $(ev.currentTarget); + + var calendarOptions = { + + minDate: moment({ + y: 1000 + }), + maxDate: moment().add(200, 'y'), + calendarWeeks: true, + defaultDate: moment().format(), + sideBySide: true, + buttons: { + showClear: true, + showClose: true, + showToday: true, + }, + + icons: { + date: 'fa fa-calendar', + + }, + locale: moment.locale(), + format: time.getLangDateFormat(), + widgetParent: 'body', + allowInputToggle: true, + }; + + $calendarInputGroup.datetimepicker(calendarOptions); + }, + + + load_data: function(initial_render = true) { + var self = this; + self.$(".categ").empty(); + try { + var self = this; + self._rpc({ + model: 'account.day.book', + method: 'view_report', + args: [ + [this.wizard_id] + ], + }).then(function(datas) { + _.each(datas['report_lines'], function(rep_lines) { + rep_lines.debit = self.format_currency(datas['currency'], rep_lines.debit); + rep_lines.credit = self.format_currency(datas['currency'], rep_lines.credit); + rep_lines.balance = self.format_currency(datas['currency'], rep_lines.balance); + + }); + + if (initial_render) { + + self.$('.filter_view_db').html(QWeb.render('DayFilterView', { + filter_data: datas['filters'], + })); + self.$el.find('.journals').select2({ + placeholder: ' Journals...', + }); + self.$el.find('.account-partner').select2({ + placeholder: ' Accounts...', + }); + self.$el.find('.target_move').select2({ + placeholder: 'Target Move...', + }); + + + } + var child = []; + + self.$('.table_view_db').html(QWeb.render('Daytable', { + + report_lines: datas['report_lines'], + filter: datas['filters'], + currency: datas['currency'], + })); + + }); + + } catch (el) { + window.location.href + } + }, + + + format_currency: function(currency, amount) { + if (typeof(amount) != 'number') { + amount = parseFloat(amount); + } + var formatted_value = (parseInt(amount)).toLocaleString(currency[2], { + minimumFractionDigits: 2 + }) + return formatted_value + }, + + print_pdf: function(e) { + e.preventDefault(); + + var self = this; + self._rpc({ + model: 'account.day.book', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + + var action = { + 'type': 'ir.actions.report', + 'report_type': 'qweb-pdf', + 'report_name': 'dynamic_accounts_report.day_book', + 'report_file': 'dynamic_accounts_report.day_book', + 'data': { + 'report_data': data + }, + 'context': { + 'active_model': 'account.day.book', + 'landscape': 1, + 'daybook_pdf_report': true + }, + 'display_name': 'Day Book', + }; + + return self.do_action(action); + }); + }, + + print_xlsx: function() { + var self = this; + self._rpc({ + model: 'account.day.book', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + var action = { + // 'type': 'ir_actions_dynamic_xlsx_download', + 'data': { + 'model': 'account.day.book', + 'options': JSON.stringify(data['filters']), + 'output_format': 'xlsx', + 'report_data': JSON.stringify(data['report_lines']), + 'report_name': 'Day Book', + 'dfr_data': JSON.stringify(data), + }, + }; + // return self.do_action(action); + self.downloadXlsx(action) + }); + }, + downloadXlsx: function(action) { + framework.blockUI(); + session.get_file({ + url: '/dynamic_xlsx_reports', + data: action.data, + complete: framework.unblockUI, + error: (error) => this.call('crash_manager', 'rpc_error', error), + }); + }, + + create_lines_with_style: function(rec, attr, datas) { + + var temp_str = ""; + var style_name = "border-bottom: 1px solid #e6e6e6;"; + var attr_name = attr + " style=" + style_name; + temp_str += ""; + if (datas.currency[1] == 'after') { + temp_str += ""; + temp_str += ""; + } else { + temp_str += ""; + temp_str += ""; + } + return temp_str; + }, + + + journal_line_click: function(el) { + click_num++; + var self = this; + var line = $(el.target).parent().data('id'); + return self.do_action({ + type: 'ir.actions.act_window', + view_type: 'form', + view_mode: 'form', + res_model: 'account.move', + views: [ + [false, 'form'] + ], + res_id: line, + target: 'current', + }); + + }, + + show_drop_down: function(event) { + event.preventDefault(); + var self = this; + var account_id = $(event.currentTarget).data('account-id'); + var offset = 0; + var td = $(event.currentTarget).next('tr').find('td'); + if (td.length == 1) { + + self._rpc({ + model: 'account.day.book', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + _.each(data['report_lines'], function(rep_lines) { + _.each(rep_lines['child_lines'], function(move_line) { + + move_line.debit = self.format_currency(data['currency'], move_line.debit); + move_line.credit = self.format_currency(data['currency'], move_line.credit); + move_line.balance = self.format_currency(data['currency'], move_line.balance); + + + }); + }); + for (var i = 0; i < data['report_lines'].length; i++) { + + if (account_id == data['report_lines'][i]['id']) { + $(event.currentTarget).next('tr').find('td').remove(); + $(event.currentTarget).next('tr').after( + QWeb.render('SubSectiondb', { + + account_data: data['report_lines'][i]['child_lines'], + currency_symbol: data.currency[0], + id: data['report_lines'][i]['id'], + currency_position: data.currency[1], + })) + + $(event.currentTarget).next('tr').find('td ul li:first a').css({ + 'background-color': '#00ede8', + 'font-weight': 'bold', + }); + } + } + + }); + } + }, + + view_acc_move: function(event) { + + event.preventDefault(); + var self = this; + var context = {}; + var show_acc_move = function(res_model, res_id, view_id) { + var action = { + type: 'ir.actions.act_window', + view_type: 'form', + view_mode: 'form', + res_model: res_model, + views: [ + [view_id || false, 'form'] + ], + res_id: res_id, + target: 'current', + context: context, + }; + return self.do_action(action); + }; + rpc.query({ + model: 'account.move', + method: 'search_read', + domain: [ + ['id', '=', $(event.currentTarget).data('move-id')] + ], + fields: ['id'], + limit: 1, + }) + .then(function(record) { + + if (record.length > 0) { + show_acc_move('account.move', record[0].id); + } else { + show_acc_move('account.move', $(event.currentTarget).data('move-id')); + } + }); + }, + + + apply_filter: function(event) { + event.preventDefault(); + var self = this; + self.initial_render = false; + + var filter_data_selected = {}; + + + var account_ids = []; + var account_text = []; + + var account_res = document.getElementById("acc_res") + var account_list = $(".account-partner").select2('data') + for (var i = 0; i < account_list.length; i++) { + if (account_list[i].element[0].selected === true) { + + account_ids.push(parseInt(account_list[i].id)) + if (account_text.includes(account_list[i].text) === false) { + account_text.push(account_list[i].text) + } + account_res.value = account_text + account_res.innerHTML = account_res.value; + } + } + if (account_list.length == 0) { + account_res.value = "" + account_res.innerHTML = ""; + + } + + filter_data_selected.account_ids = account_ids + + + + var journal_ids = []; + var journal_text = []; + var journal_res = document.getElementById("journal_res") + var journal_list = $(".journals").select2('data') + for (var i = 0; i < journal_list.length; i++) { + if (journal_list[i].element[0].selected === true) { + + journal_ids.push(parseInt(journal_list[i].id)) + if (journal_text.includes(journal_list[i].text) === false) { + journal_text.push(journal_list[i].text) + } + journal_res.value = journal_text + journal_res.innerHTML = journal_res.value; + } + } + if (journal_list.length == 0) { + journal_res.value = "" + journal_res.innerHTML = ""; + + } + filter_data_selected.journal_ids = journal_ids + + // if ($("#date_from").val()) { + // var dateString = $("#date_from").val(); + // + // filter_data_selected.date_from = dateString; + // } + // if ($("#date_to").val()) { + // var dateString = $("#date_to").val(); + // filter_data_selected.date_to = dateString; + // } + + if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { + filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + + if (this.$el.find('.datetimepicker-input[name="date_to"]').val()) { + filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="date_to"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + + if ($(".target_move").length) { + + var post_res = document.getElementById("post_res") + filter_data_selected.target_move = $(".target_move")[1].value + post_res.value = $(".target_move")[1].value + post_res.innerHTML = post_res.value; + if ($(".target_move")[1].value == "") { + post_res.innerHTML = "posted"; + + } + } + + rpc.query({ + model: 'account.day.book', + method: 'write', + args: [ + self.wizard_id, filter_data_selected + ], + }).then(function(res) { + self.initial_render = false; + self.load_data(self.initial_render); + }); + }, + + }); + core.action_registry.add("d_b", DayBook); + return DayBook; +}); \ No newline at end of file diff --git a/dynamic_accounts_report/static/src/js/financial_reports.js b/dynamic_accounts_report/static/src/js/financial_reports.js index 5459920c3..6796d4f00 100644 --- a/dynamic_accounts_report/static/src/js/financial_reports.js +++ b/dynamic_accounts_report/static/src/js/financial_reports.js @@ -1,247 +1,246 @@ -odoo.define('dynamic_accounts_report.financial_reports', function (require) { - 'use strict'; - var AbstractAction = require('web.AbstractAction'); - var core = require('web.core'); - var field_utils = require('web.field_utils'); - var rpc = require('web.rpc'); - var session = require('web.session'); - var utils = require('web.utils'); - var QWeb = core.qweb; - var _t = core._t; - var framework = require('web.framework'); - - var datepicker = require('web.datepicker'); - var time = require('web.time'); - - window.click_num = 0; - var ProfitAndLoss = AbstractAction.extend({ - template: 'dfr_template_new', - events: { - 'click .parent-line': 'journal_line_click', - 'click .child_col1': 'journal_line_click', - 'click #apply_filter': 'apply_filter', - 'click #pdf': 'print_pdf', - 'click #xlsx': 'print_xlsx', - 'click .show-gl': 'show_gl', - 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', - }, - - init: function(parent, action) { - this._super(parent, action); - this.currency=action.currency; - this.report_lines = action.report_lines; - this.wizard_id = action.context.wizard | null; - }, - start: function() { - var self = this; - self.initial_render = true; - rpc.query({ - model: 'dynamic.balance.sheet.report', - method: 'create', - args: [{ - }] - }).then(function(t_res) { - self.wizard_id = t_res; - self.load_data(self.initial_render); - }) - }, - - _onCalendarIconClick: function (ev) { - var $calendarInputGroup = $(ev.currentTarget); - - var calendarOptions = { - - minDate: moment({ y: 1000 }), - maxDate: moment().add(200, 'y'), - calendarWeeks: true, - defaultDate: moment().format(), - sideBySide: true, - buttons: { - showClear: true, - showClose: true, - showToday: true, - }, - - icons : { - date: 'fa fa-calendar', - - }, - locale : moment.locale(), - format : time.getLangDateFormat(), - widgetParent: 'body', - allowInputToggle: true, - }; - - $calendarInputGroup.datetimepicker(calendarOptions); - }, - - load_data: function (initial_render = true) { - var self = this; - var action_title = self._title; - self.$(".categ").empty(); - try{ - var self = this; - self._rpc({ - model: 'dynamic.balance.sheet.report', - method: 'view_report', - args: [[this.wizard_id], action_title, self.searchModel.config.context.lang], - }).then(function(datas) { - if (initial_render) { - self.$('.filter_view_dfr').html(QWeb.render('DfrFilterView', { - filter_data: datas['filters'], - title : datas['name'], - })); - self.$el.find('.journals').select2({ - placeholder: ' Journals...', - }); - self.$el.find('.account-partner').select2({ - placeholder: ' Accounts...', - }); - self.$el.find('.account-tag').select2({ - placeholder: 'Account Tag...', - }); - self.$el.find('.analytics').select2({ - placeholder: 'Analytic Accounts...', - }); - self.$el.find('.analytic-tag').select2({ - placeholder: 'Analytic Tag...', - }); - self.$el.find('.target_move').select2({ - placeholder: 'Target Move...', - }); - } - var child=[]; - console.log(datas, "datas") - self.$('.table_view_dfr').html(QWeb.render('dfr_table', { - - report_lines : datas['report_lines'], - filter : datas['filters'], - currency : datas['currency'], - credit_total : datas['credit_total'], - debit_total : datas['debit_total'], - debit_balance : datas['debit_balance'], - bs_lines : datas['bs_lines'], - lang: datas['lang'], - })); - }); - } - catch (el) { - window.location.href - } - }, - - format_currency: function(currency, amount) { - if (typeof(amount) != 'number') { - amount = parseFloat(amount); - } - var formatted_value = (parseInt(amount)).toLocaleString(currency[2],{ - minimumFractionDigits: 2 - }) - return formatted_value - }, - - show_gl: function(e) { - var self = this; - var account_id = $(e.target).attr('data-account-id'); - var options = { - account_ids: [account_id], - } - var action = { - type: 'ir.actions.client', - name: 'GL View', - tag: 'g_l', - target: 'new', - domain: [(['account_ids','=', account_id])], - } - return this.do_action(action); - }, - - print_pdf: function(e) { - e.preventDefault(); - var self = this; - var action_title = self._title; - self._rpc({ - model: 'dynamic.balance.sheet.report', - method: 'view_report', - args: [ - [self.wizard_id], action_title, self.searchModel.config.context.lang - ], - }).then(function(data) { - var action = { - 'type': 'ir.actions.report', - 'report_type': 'qweb-pdf', - 'report_name': 'dynamic_accounts_report.balance_sheet', - 'report_file': 'dynamic_accounts_report.balance_sheet', - 'data': { - 'report_data': data, - 'report_name': action_title - }, - 'context': { - 'active_model': 'dynamic.balance.sheet.report', - 'landscape': 1, - 'bs_report': true - }, - 'display_name': action_title, - }; - return self.do_action(action); - }); - }, - - print_xlsx: function() { - var self = this; - var action_title = self._title; - self._rpc({ - model: 'dynamic.balance.sheet.report', - method: 'view_report', - args: [ - [self.wizard_id], action_title, self.searchModel.config.context.lang - ], - }).then(function(data) { - var action = { -// 'type': 'ir_actions_dynamic_xlsx_download', - 'data': { - 'model': 'dynamic.balance.sheet.report', - 'options': JSON.stringify(data['filters']), - 'output_format': 'xlsx', - 'report_data': action_title, - 'report_name': action_title, - 'dfr_data': JSON.stringify(data['bs_lines']), - }, - }; -// return self.do_action(action); - self.downloadXlsx(action) - }); - }, - downloadXlsx: function (action){ - framework.blockUI(); - session.get_file({ - url: '/dynamic_xlsx_reports', - data: action.data, - complete: framework.unblockUI, - error: (error) => this.call('crash_manager', 'rpc_error', error), - }); - }, - journal_line_click: function (el){ - click_num++; - var self = this; - var line = $(el.target).parent().data('id'); - return self.do_action({ - type: 'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: 'account.move', - views: [ - [false, 'form'] - ], - res_id: line, - target: 'current', - }); - - }, - - apply_filter: function(event) { - - event.preventDefault(); +odoo.define('dynamic_accounts_report.financial_reports', function(require) { + 'use strict'; + var AbstractAction = require('web.AbstractAction'); + var core = require('web.core'); + var field_utils = require('web.field_utils'); + var rpc = require('web.rpc'); + var session = require('web.session'); + var utils = require('web.utils'); + var QWeb = core.qweb; + var _t = core._t; + var framework = require('web.framework'); + + var datepicker = require('web.datepicker'); + var time = require('web.time'); + + window.click_num = 0; + var ProfitAndLoss = AbstractAction.extend({ + template: 'dfr_template_new', + events: { + 'click .parent-line': 'journal_line_click', + 'click .child_col1': 'journal_line_click', + 'click #apply_filter': 'apply_filter', + 'click #pdf': 'print_pdf', + 'click #xlsx': 'print_xlsx', + 'click .show-gl': 'show_gl', + 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', + }, + + init: function(parent, action) { + this._super(parent, action); + this.currency = action.currency; + this.report_lines = action.report_lines; + this.wizard_id = action.context.wizard | null; + }, + start: function() { + var self = this; + self.initial_render = true; + rpc.query({ + model: 'dynamic.balance.sheet.report', + method: 'create', + args: [{}] + }).then(function(t_res) { + self.wizard_id = t_res; + self.load_data(self.initial_render); + }) + }, + + _onCalendarIconClick: function(ev) { + var $calendarInputGroup = $(ev.currentTarget); + + var calendarOptions = { + + minDate: moment({ + y: 1000 + }), + maxDate: moment().add(200, 'y'), + calendarWeeks: true, + defaultDate: moment().format(), + sideBySide: true, + buttons: { + showClear: true, + showClose: true, + showToday: true, + }, + + icons: { + date: 'fa fa-calendar', + + }, + locale: moment.locale(), + format: time.getLangDateFormat(), + widgetParent: 'body', + allowInputToggle: true, + }; + + $calendarInputGroup.datetimepicker(calendarOptions); + }, + + load_data: function(initial_render = true) { + var self = this; + var action_title = self._title; + self.$(".categ").empty(); + try { + var self = this; + self._rpc({ + model: 'dynamic.balance.sheet.report', + method: 'view_report', + args: [ + [this.wizard_id], action_title, self.searchModel.config.context.lang + ], + }).then(function(datas) { + if (initial_render) { + self.$('.filter_view_dfr').html(QWeb.render('DfrFilterView', { + filter_data: datas['filters'], + title: datas['name'], + })); + self.$el.find('.journals').select2({ + placeholder: ' Journals...', + }); + self.$el.find('.account').select2({ + placeholder: ' Accounts...', + }); + self.$el.find('.account-tag').select2({ + placeholder: 'Account Tag...', + }); + self.$el.find('.analytics').select2({ + placeholder: 'Analytic Accounts...', + }); + self.$el.find('.analytic-tag').select2({ + placeholder: 'Analytic Tag...', + }); + self.$el.find('.target_move').select2({ + placeholder: 'Target Move...', + }); + } + var child = []; + self.$('.table_view_dfr').html(QWeb.render('dfr_table', { + report_lines: datas['report_lines'], + filter: datas['filters'], + currency: datas['currency'], + credit_total: datas['credit_total'], + debit_total: datas['debit_total'], + debit_balance: datas['debit_balance'], + bs_lines: datas['bs_lines'], + lang: datas['lang'], + })); + }); + } catch (el) { + window.location.href + } + }, + + format_currency: function(currency, amount) { + if (typeof(amount) != 'number') { + amount = parseFloat(amount); + } + var formatted_value = (parseInt(amount)).toLocaleString(currency[2], { + minimumFractionDigits: 2 + }) + return formatted_value + }, + + show_gl: function(e) { + var self = this; + var account_id = $(e.target).attr('data-account-id'); + var options = { + account_ids: [account_id], + } + var action = { + type: 'ir.actions.client', + name: 'GL View', + tag: 'g_l', + target: 'new', + domain: [(['account_ids', '=', account_id])], + } + return this.do_action(action); + }, + + print_pdf: function(e) { + e.preventDefault(); + var self = this; + var action_title = self._title; + self._rpc({ + model: 'dynamic.balance.sheet.report', + method: 'view_report', + args: [ + [self.wizard_id], action_title, self.searchModel.config.context.lang + ], + }).then(function(data) { + var action = { + 'type': 'ir.actions.report', + 'report_type': 'qweb-pdf', + 'report_name': 'dynamic_accounts_report.balance_sheet', + 'report_file': 'dynamic_accounts_report.balance_sheet', + 'data': { + 'report_data': data, + 'report_name': action_title + }, + 'context': { + 'active_model': 'dynamic.balance.sheet.report', + 'landscape': 1, + 'bs_report': true + }, + 'display_name': action_title, + }; + return self.do_action(action); + }); + }, + + print_xlsx: function() { + var self = this; + var action_title = self._title; + self._rpc({ + model: 'dynamic.balance.sheet.report', + method: 'view_report', + args: [ + [self.wizard_id], action_title, self.searchModel.config.context.lang + ], + }).then(function(data) { + var action = { + // 'type': 'ir_actions_dynamic_xlsx_download', + 'data': { + 'model': 'dynamic.balance.sheet.report', + 'options': JSON.stringify(data['filters']), + 'output_format': 'xlsx', + 'report_data': action_title, + 'report_name': action_title, + 'dfr_data': JSON.stringify(data['bs_lines']), + }, + }; + // return self.do_action(action); + self.downloadXlsx(action) + }); + }, + downloadXlsx: function(action) { + framework.blockUI(); + session.get_file({ + url: '/dynamic_xlsx_reports', + data: action.data, + complete: framework.unblockUI, + error: (error) => this.call('crash_manager', 'rpc_error', error), + }); + }, + journal_line_click: function(el) { + click_num++; + var self = this; + var line = $(el.target).parent().data('id'); + return self.do_action({ + type: 'ir.actions.act_window', + view_type: 'form', + view_mode: 'form', + res_model: 'account.move', + views: [ + [false, 'form'] + ], + res_id: line, + target: 'current', + }); + + }, + + apply_filter: function(event) { + event.preventDefault(); var self = this; self.initial_render = false; var filter_data_selected = {}; @@ -266,142 +265,138 @@ odoo.define('dynamic_accounts_report.financial_reports', function (require) { } filter_data_selected.account_ids = account_ids - - - var journal_ids = []; - var journal_text = []; - var journal_res = document.getElementById("journal_res") - var journal_list = $(".journals").select2('data') - for (var i = 0; i < journal_list.length; i++) { - if(journal_list[i].element[0].selected === true){ - - journal_ids.push(parseInt(journal_list[i].id)) - if(journal_text.includes(journal_list[i].text) === false){ - journal_text.push(journal_list[i].text) - } - journal_res.value = journal_text - journal_res.innerHTML=journal_res.value; - } - } - if (journal_list.length == 0){ - journal_res.value = "" - journal_res.innerHTML=""; - - } - filter_data_selected.journal_ids = journal_ids - - var account_tag_ids = []; - var account_tag_text = []; - var account_tag_res = document.getElementById("acc_tag_res") - - var account_tag_list = $(".account-tag").select2('data') - for (var i = 0; i < account_tag_list.length; i++) { - if(account_tag_list[i].element[0].selected === true){ - - account_tag_ids.push(parseInt(account_tag_list[i].id)) - if(account_tag_text.includes(account_tag_list[i].text) === false){ - account_tag_text.push(account_tag_list[i].text) - } - - account_tag_res.value = account_tag_text - account_tag_res.innerHTML=account_tag_res.value; - } - } - if (account_tag_list.length == 0){ - account_tag_res.value = "" - account_tag_res.innerHTML=""; - - } - filter_data_selected.account_tag_ids = account_tag_ids - -// var analytic_ids = [] -// var analytic_text = []; -// var analytic_res = document.getElementById("analytic_res") -// var analytic_list = $(".analytics").select2('data') -// -// for (var i = 0; i < analytic_list.length; i++) { -// if(analytic_list[i].element[0].selected === true){ + var journal_ids = []; + var journal_text = []; + var journal_res = document.getElementById("journal_res") + var journal_list = $(".journals").select2('data') + for (var i = 0; i < journal_list.length; i++) { + if (journal_list[i].element[0].selected === true) { + + journal_ids.push(parseInt(journal_list[i].id)) + if (journal_text.includes(journal_list[i].text) === false) { + journal_text.push(journal_list[i].text) + } + journal_res.value = journal_text + journal_res.innerHTML = journal_res.value; + } + } + if (journal_list.length == 0) { + journal_res.value = "" + journal_res.innerHTML = ""; + + } + filter_data_selected.journal_ids = journal_ids + + var account_tag_ids = []; + var account_tag_text = []; + var account_tag_res = document.getElementById("acc_tag_res") + + var account_tag_list = $(".account-tag").select2('data') + for (var i = 0; i < account_tag_list.length; i++) { + if (account_tag_list[i].element[0].selected === true) { + + account_tag_ids.push(parseInt(account_tag_list[i].id)) + if (account_tag_text.includes(account_tag_list[i].text) === false) { + account_tag_text.push(account_tag_list[i].text) + } + + account_tag_res.value = account_tag_text + account_tag_res.innerHTML = account_tag_res.value; + } + } + if (account_tag_list.length == 0) { + account_tag_res.value = "" + account_tag_res.innerHTML = ""; + + } + filter_data_selected.account_tag_ids = account_tag_ids + + var analytic_ids = [] + var analytic_text = []; + var analytic_res = document.getElementById("analytic_res") + var analytic_list = $(".analytics").select2('data') + + for (var i = 0; i < analytic_list.length; i++) { + if (analytic_list[i].element[0].selected === true) { + + analytic_ids.push(parseInt(analytic_list[i].id)) + if (analytic_text.includes(analytic_list[i].text) === false) { + analytic_text.push(analytic_list[i].text) + } + analytic_res.value = analytic_text + analytic_res.innerHTML = analytic_res.value; + } + } + if (analytic_list.length == 0) { + analytic_res.value = "" + analytic_res.innerHTML = ""; + + } + filter_data_selected.analytic_ids = analytic_ids + +// var analytic_tag_ids = []; +// var analytic_tag_text = []; +// var analytic_tag_res = document.getElementById("analic_tag_res") +// var analytic_tag_list = $(".analytic-tag").select2('data') +// for (var i = 0; i < analytic_tag_list.length; i++) { +// if (analytic_tag_list[i].element[0].selected === true) { // -// analytic_ids.push(parseInt(analytic_list[i].id)) -// if(analytic_text.includes(analytic_list[i].text) === false){ -// analytic_text.push(analytic_list[i].text) -// } -// analytic_res.value = analytic_text -// analytic_res.innerHTML=analytic_res.value; -// } -// } -// if (analytic_list.length == 0){ -// analytic_res.value = "" -// analytic_res.innerHTML=""; +// analytic_tag_ids.push(parseInt(analytic_tag_list[i].id)) +// if (analytic_tag_text.includes(analytic_tag_list[i].text) === false) { +// analytic_tag_text.push(analytic_tag_list[i].text) // -// } -// filter_data_selected.analytic_ids = analytic_ids - -// var analytic_tag_ids = []; -// var analytic_tag_text = []; -//// var analytic_tag_res = document.getElementById("analic_tag_res") -// var analytic_tag_list = $(".analytic-tag").select2('data') -// for (var i = 0; i < analytic_tag_list.length; i++) { -// if(analytic_tag_list[i].element[0].selected === true){ +// } // -// analytic_tag_ids.push(parseInt(analytic_tag_list[i].id)) -// if(analytic_tag_text.includes(analytic_tag_list[i].text) === false){ -// analytic_tag_text.push(analytic_tag_list[i].text) +// analytic_tag_res.value = analytic_tag_text +// analytic_tag_res.innerHTML = analytic_tag_res.value; +// } +// } +// if (analytic_tag_list.length == 0) { +// analytic_tag_res.value = "" +// analytic_tag_res.innerHTML = ""; // -// } -// -// analytic_tag_res.value = analytic_tag_text -// analytic_tag_res.innerHTML=analytic_tag_res.value; -// } -// } -// if (analytic_tag_list.length == 0){ -// analytic_tag_res.value = "" -// analytic_tag_res.innerHTML=""; -// -// } -// filter_data_selected.analytic_tag_ids = analytic_tag_ids - - - if ($("#date_from").val()) { - var dateString = $("#date_from").val(); - filter_data_selected.date_from = dateString; - } - if ($("#date_to").val()) { - var dateString = $("#date_to").val(); - filter_data_selected.date_to = dateString; - } - if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { - filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } - - if (this.$el.find('.datetimepicker-input[name="date_to"]').val()) { - filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="date_to"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } - - if ($(".target_move").length) { - var post_res = document.getElementById("post_res") - filter_data_selected.target_move = $(".target_move")[1].value - post_res.value = $(".target_move")[1].value - post_res.innerHTML=post_res.value; - if ($(".target_move")[1].value == "") { - post_res.innerHTML="posted"; - - } - } - - rpc.query({ - model: 'dynamic.balance.sheet.report', - method: 'write', - args: [ - self.wizard_id, filter_data_selected - ], - }).then(function(res) { - self.initial_render = false; - self.load_data(self.initial_render); - }); - }, - - }); - core.action_registry.add("dfr_n", ProfitAndLoss); - return ProfitAndLoss; -}); +// } +// filter_data_selected.analytic_tag_ids = analytic_tag_ids + + if ($("#date_from").val()) { + var dateString = $("#date_from").val(); + filter_data_selected.date_from = dateString; + } + if ($("#date_to").val()) { + var dateString = $("#date_to").val(); + filter_data_selected.date_to = dateString; + } + if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { + filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + + if (this.$el.find('.datetimepicker-input[name="date_to"]').val()) { + filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="date_to"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + + if ($(".target_move").length) { + var post_res = document.getElementById("post_res") + filter_data_selected.target_move = $(".target_move")[1].value + post_res.value = $(".target_move")[1].value + post_res.innerHTML = post_res.value; + if ($(".target_move")[1].value == "") { + post_res.innerHTML = "posted"; + + } + } + rpc.query({ + model: 'dynamic.balance.sheet.report', + method: 'write', + args: [ + self.wizard_id, filter_data_selected + ], + }).then(function(res) { + self.initial_render = false; + self.load_data(self.initial_render); + }); + }, + + }); + core.action_registry.add("dfr_n", ProfitAndLoss); + return ProfitAndLoss; +}); \ No newline at end of file diff --git a/dynamic_accounts_report/static/src/js/general_ledger.js b/dynamic_accounts_report/static/src/js/general_ledger.js index 60e9c4b45..f0c02c334 100644 --- a/dynamic_accounts_report/static/src/js/general_ledger.js +++ b/dynamic_accounts_report/static/src/js/general_ledger.js @@ -1,509 +1,471 @@ -odoo.define('dynamic_accounts_report.general_ledger', function (require) { - 'use strict'; - var AbstractAction = require('web.AbstractAction'); - var core = require('web.core'); - var field_utils = require('web.field_utils'); - var rpc = require('web.rpc'); - var session = require('web.session'); - var utils = require('web.utils'); - var QWeb = core.qweb; - var _t = core._t; - var trial = require('dynamic_accounts_report.trial_balance'); - var framework = require('web.framework'); - - var datepicker = require('web.datepicker'); - var time = require('web.time'); - - window.click_num = 0; - var GeneralLedger = AbstractAction.extend({ - template: 'GeneralTemp', - events: { - 'click .parent-line': 'journal_line_click', - 'click .child_col1': 'journal_line_click', - 'click #apply_filter': 'apply_filter', - 'click #pdf': 'print_pdf', - 'click #xlsx': 'print_xlsx', - 'click .gl-line': 'show_drop_down', - 'click .view-account-move': 'view_acc_move', - 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', - }, - - init: function(parent, action) { - this._super(parent, action); - this.currency=action.currency; - this.report_lines = action.report_lines; - this.wizard_id = action.context.wizard | null; - }, - - - start: function() { - var self = this; - self.initial_render = true; - if (this.searchModel.config.domain.length != 0) { - rpc.query({ - model: 'account.general.ledger', - method: 'create', - args: [{ - account_ids : [this.searchModel.config.domain[0][2]] - }] - }).then(function(t_res) { - self.wizard_id = t_res; - self.load_data(self.initial_render); - }) - }else{ - rpc.query({ - model: 'account.general.ledger', - method: 'create', - args: [{ - - }] - }).then(function(t_res) { - self.wizard_id = t_res; - self.load_data(self.initial_render); - }) - } - }, - - - _onCalendarIconClick: function (ev) { - var $calendarInputGroup = $(ev.currentTarget); - - var calendarOptions = { - - minDate: moment({ y: 1000 }), - maxDate: moment().add(200, 'y'), - calendarWeeks: true, - defaultDate: moment().format(), - sideBySide: true, - buttons: { - showClear: true, - showClose: true, - showToday: true, - }, - - icons : { - date: 'fa fa-calendar', - - }, - locale : moment.locale(), - format : time.getLangDateFormat(), - widgetParent: 'body', - allowInputToggle: true, - }; - - $calendarInputGroup.datetimepicker(calendarOptions); - }, - - - load_data: function (initial_render = true) { - var self = this; - self.$(".categ").empty(); - try{ - var self = this; - var action_title = self._title - self._rpc({ - model: 'account.general.ledger', - method: 'view_report', - args: [[this.wizard_id], action_title], - }).then(function(datas) { -// _.each(datas['report_lines'], function(rep_lines) { -// rep_lines.debit = self.format_currency(datas['currency'],rep_lines.debit); -// rep_lines.credit = self.format_currency(datas['currency'],rep_lines.credit); -// rep_lines.balance = self.format_currency(datas['currency'],rep_lines.balance); -// -// -// -// -// }); - - if (initial_render) { - self.$('.filter_view_tb').html(QWeb.render('GLFilterView', { - filter_data: datas['filters'], - title : datas['name'], -// eng_title : datas['eng_title'], - })); - self.$el.find('.journals').select2({ - placeholder: ' Journals...', - }); - self.$el.find('.account-partner').select2({ - placeholder: ' Accounts...', - }); - self.$el.find('.analytics').select2({ - placeholder: 'Analytic Accounts...', - }); -// self.$el.find('.analytic_tags').select2({ -// placeholder: 'Analytic Tags...', -// }); - self.$el.find('.target_move').select2({ - placeholder: 'Target Move...', - }); - - } - var child=[]; - self.$('.table_view_tb').html(QWeb.render('GLTable', { - - report_lines : datas['report_lines'], - filter : datas['filters'], - currency : datas['currency'], - credit_total : datas['credit_total'], - debit_total : datas['debit_total'], - debit_balance : datas['debit_balance'] - })); - - }); - - } - catch (el) { - window.location.href - } - }, - - print_pdf: function(e) { - e.preventDefault(); - var self = this; - var action_title = self._title - self._rpc({ - model: 'account.general.ledger', - method: 'view_report', - args: [ - [self.wizard_id], action_title - ], - }).then(function(data) { - var action = { - 'type': 'ir.actions.report', - 'report_type': 'qweb-pdf', - 'report_name': 'dynamic_accounts_report.general_ledger', - 'report_file': 'dynamic_accounts_report.general_ledger', - 'data': { - 'report_data': data - }, - 'context': { - 'active_model': 'account.general.ledger', - 'landscape': 1, - 'trial_pdf_report': true - }, - 'display_name': action_title, - }; - return self.do_action(action); - }); - }, - - print_xlsx: function() { - var self = this; - var action_title = self._title - self._rpc({ - model: 'account.general.ledger', - method: 'view_report', - args: [ - [self.wizard_id], action_title - ], - }).then(function(data) { - var action = { -// 'type': 'ir_actions_dynamic_xlsx_download', - 'data': { - 'model': 'account.general.ledger', - 'options': JSON.stringify(data['filters']), - 'output_format': 'xlsx', - 'report_data': JSON.stringify(data['report_lines']), - 'report_name': action_title, - 'dfr_data': JSON.stringify(data), - }, - }; -// return self.do_action(action); - self.downloadXlsx(action) - }); - }, - - downloadXlsx: function (action){ - framework.blockUI(); - session.get_file({ - url: '/dynamic_xlsx_reports', - data: action.data, - complete: framework.unblockUI, - error: (error) => this.call('crash_manager', 'rpc_error', error), - }); - }, - - - - create_lines_with_style: function(rec, attr, datas) { - var temp_str = ""; - var style_name = "border-bottom: 1px solid #e6e6e6;"; - var attr_name = attr + " style="+style_name; - - temp_str += ""; - if(datas.currency[1]=='after'){ - temp_str += ""; - temp_str += ""; - } - else{ - temp_str += ""; - temp_str += ""; - - } - return temp_str; - }, - - - journal_line_click: function (el){ - click_num++; - var self = this; - var line = $(el.target).parent().data('id'); - return self.do_action({ - type: 'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: 'account.move', - views: [ - [false, 'form'] - ], - res_id: line, - target: 'current', - }); - - }, - format_currency: function(currency, amount) { - if (typeof(amount) != 'number') { - amount = parseFloat(amount); - } - var formatted_value = (parseInt(amount)).toLocaleString(currency[2],{ - minimumFractionDigits: 2 - }) - return formatted_value - }, - - show_drop_down: function(event) { - event.preventDefault(); - var self = this; - var account_id = $(event.currentTarget).data('account-id'); - var offset = 0; - var td = $(event.currentTarget).next('tr').find('td'); - if (td.length == 1) { - var action_title = self._title - self._rpc({ - model: 'account.general.ledger', - method: 'get_accounts_line', - args: [ - [self.wizard_id], account_id, action_title - ], - }).then(function(data) { -// _.each(data['report_lines'], function(rep_lines) { -// _.each(rep_lines['move_lines'], function(move_line) { -// -// move_line.debit = self.format_currency(data['currency'],move_line.debit); -// move_line.credit = self.format_currency(data['currency'],move_line.credit); -// move_line.balance = self.format_currency(data['currency'],move_line.balance); -// -// -// }); -// }); - - for (var i = 0; i < data['report_lines'].length; i++) { - - if (account_id == data['report_lines'][i]['id'] ){ - $(event.currentTarget).next('tr').find('td').remove(); - $(event.currentTarget).next('tr').after( - QWeb.render('SubSection', { - account_data: data['report_lines'][i]['move_lines'], - currency_symbol : data.currency[0], - id : data['report_lines'][i]['id'], - currency_position : data.currency[1], - - })) - $(event.currentTarget).next('tr').find('td ul li:first a').css({ - 'background-color': '#00ede8', - 'font-weight': 'bold', - }); - } - } - - }); - } - }, - - view_acc_move: function(event) { - event.preventDefault(); - var self = this; - var context = {}; - var show_acc_move = function(res_model, res_id, view_id) { - var action = { - type: 'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: res_model, - views: [ - [view_id || false, 'form'] - ], - res_id: res_id, - target: 'current', - context: context, - }; - return self.do_action(action); - }; - rpc.query({ - model: 'account.move', - method: 'search_read', - domain: [ - ['id', '=', $(event.currentTarget).data('move-id')] - ], - fields: ['id'], - limit: 1, - }) - .then(function(record) { - if (record.length > 0) { - show_acc_move('account.move', record[0].id); - } else { - show_acc_move('account.move', $(event.currentTarget).data('move-id')); - } - }); - }, - - apply_filter: function(event) { - event.preventDefault(); - var self = this; - self.initial_render = false; - - var filter_data_selected = {}; - - - var account_ids = []; - var account_text = []; - - var account_res = document.getElementById("acc_res") - var account_list = $(".account-partner").select2('data') - for (var i = 0; i < account_list.length; i++) { - if(account_list[i].element[0].selected === true){ - account_ids.push(parseInt(account_list[i].id)) - if(account_text.includes(account_list[i].text) === false){ - account_text.push(account_list[i].text) - } - account_res.value = account_text - account_res.innerHTML=account_res.value; - } - } - if (account_list.length == 0){ - account_res.value = "" - account_res.innerHTML=""; - - } - filter_data_selected.account_ids = account_ids - - - if(!(this._title == 'Bank Book' || this._title == 'Cash Book')){ - - var journal_ids = []; - var journal_text = []; - var journal_res = document.getElementById("journal_res") - var journal_list = $(".journals").select2('data') - - for (var i = 0; i < journal_list.length; i++) { - if(journal_list[i].element[0].selected === true){ - - journal_ids.push(parseInt(journal_list[i].id)) - if(journal_text.includes(journal_list[i].text) === false){ - journal_text.push(journal_list[i].text) - } - journal_res.value = journal_text - journal_res.innerHTML=journal_res.value; - } - } - if (journal_list.length == 0){ - journal_res.value = "" - journal_res.innerHTML=""; - - } - filter_data_selected.journal_ids = journal_ids - - } - - - -// var analytic_ids = [] -// var analytic_text = []; -//// var analytic_res = document.getElementById("analytic_res") -// var analytic_list = $(".analytics").select2('data') -// -// for (var i = 0; i < analytic_list.length; i++) { -// if(analytic_list[i].element[0].selected === true){ -// -// analytic_ids.push(parseInt(analytic_list[i].id)) -// if(analytic_text.includes(analytic_list[i].text) === false){ -// analytic_text.push(analytic_list[i].text) -// } -// analytic_res.value = analytic_text -// analytic_res.innerHTML=analytic_res.value; -// } -// } -// if (analytic_list.length == 0){ -// analytic_res.value = "" -// analytic_res.innerHTML=""; -// -// } -// filter_data_selected.analytic_ids = analytic_ids -// -// var analytic_tag_ids = [] -// var analytic_tag_text = []; -// var analytic_tag_res = document.getElementById("analytic_tag_res") -// var analytic_tag_list = $(".analytic_tags").select2('data') -// for (var i = 0; i < analytic_tag_list.length; i++) { -// if(analytic_tag_list[i].element[0].selected === true){ -// -// analytic_tag_ids.push(parseInt(analytic_tag_list[i].id)) -// if(analytic_tag_text.includes(analytic_tag_list[i].text) === false){ -// analytic_tag_text.push(analytic_tag_list[i].text) -// } -// analytic_tag_res.value = analytic_tag_text -// analytic_tag_res.innerHTML=analytic_tag_res.value; -// } -// } -// if (analytic_tag_list.length == 0){ -// analytic_tag_res.value = "" -// analytic_tag_res.innerHTML=""; -// -// } -// filter_data_selected.analytic_tag_ids = analytic_tag_ids - -// if ($("#date_from").val()) { -// -// var dateString = $("#date_from").val(); -// filter_data_selected.date_from = dateString; -// } -// if ($("#date_to").val()) { -// var dateString = $("#date_to").val(); -// filter_data_selected.date_to = dateString; -// } - - if (this.$el.find('.datetimepicker-input[name="gen_date_from"]').val()) { - filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="gen_date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } - - if (this.$el.find('.datetimepicker-input[name="gen_date_to"]').val()) { - filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="gen_date_to"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } - - if ($(".target_move").length) { - var post_res = document.getElementById("post_res") - filter_data_selected.target_move = $(".target_move")[1].value - post_res.value = $(".target_move")[1].value - post_res.innerHTML=post_res.value; - if ($(".target_move")[1].value == "") { - post_res.innerHTML="posted"; - - } - } - rpc.query({ - model: 'account.general.ledger', - method: 'write', - args: [ - self.wizard_id, filter_data_selected - ], - }).then(function(res) { - self.initial_render = false; - self.load_data(self.initial_render); - }); - }, - - }); - core.action_registry.add("g_l", GeneralLedger); - return GeneralLedger; +odoo.define('dynamic_accounts_report.general_ledger', function(require) { + 'use strict'; + var AbstractAction = require('web.AbstractAction'); + var core = require('web.core'); + var field_utils = require('web.field_utils'); + var rpc = require('web.rpc'); + var session = require('web.session'); + var utils = require('web.utils'); + var QWeb = core.qweb; + var _t = core._t; + var trial = require('dynamic_accounts_report.trial_balance'); + var framework = require('web.framework'); + + var datepicker = require('web.datepicker'); + var time = require('web.time'); + window.click_num = 0; + var GeneralLedger = AbstractAction.extend({ + template: 'GeneralTemp', + events: { + 'click .parent-line': 'journal_line_click', + 'click .child_col1': 'journal_line_click', + 'click #apply_filter': 'apply_filter', + 'click #pdf': 'print_pdf', + 'click #xlsx': 'print_xlsx', + 'click .gl-line': 'show_drop_down', + 'click .view-account-move': 'view_acc_move', + 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', + }, + init: function(parent, action) { + this._super(parent, action); + this.currency = action.currency; + this.report_lines = action.report_lines; + this.wizard_id = action.context.wizard | null; + }, + start: function() { + var self = this; + self.initial_render = true; + if (this.searchModel.config.domain.length != 0) { + rpc.query({ + model: 'account.general.ledger', + method: 'create', + args: [{ + account_ids: [this.searchModel.config.domain[0][2]] + }] + }).then(function(t_res) { + self.wizard_id = t_res; + self.load_data(self.initial_render); + }) + } else { + rpc.query({ + model: 'account.general.ledger', + method: 'create', + args: [{}] + }).then(function(t_res) { + self.wizard_id = t_res; + self.load_data(self.initial_render); + }) + } + }, + + _onCalendarIconClick: function(ev) { + var $calendarInputGroup = $(ev.currentTarget); + var calendarOptions = { + minDate: moment({ + y: 1000 + }), + maxDate: moment().add(200, 'y'), + calendarWeeks: true, + defaultDate: moment().format(), + sideBySide: true, + buttons: { + showClear: true, + showClose: true, + showToday: true, + }, + icons: { + date: 'fa fa-calendar', + }, + locale: moment.locale(), + format: time.getLangDateFormat(), + widgetParent: 'body', + allowInputToggle: true, + }; + + $calendarInputGroup.datetimepicker(calendarOptions); + }, + + load_data: function(initial_render = true) { + var self = this; + self.$(".categ").empty(); + try { + var self = this; + var action_title = self._title + self._rpc({ + model: 'account.general.ledger', + method: 'view_report', + args: [ + [this.wizard_id], action_title + ], + }).then(function(datas) { + // _.each(datas['report_lines'], function(rep_lines) { + // rep_lines.debit = self.format_currency(datas['currency'],rep_lines.debit); + // rep_lines.credit = self.format_currency(datas['currency'],rep_lines.credit); + // rep_lines.balance = self.format_currency(datas['currency'],rep_lines.balance); + // }); + + if (initial_render) { + self.$('.filter_view_tb').html(QWeb.render('GLFilterView', { + filter_data: datas['filters'], + title: datas['name'], + // eng_title : datas['eng_title'], + })); + self.$el.find('.journals').select2({ + placeholder: ' Journals...', + }); + self.$el.find('.account-partner').select2({ + placeholder: ' Accounts...', + }); + self.$el.find('.account-tag').select2({ + placeholder: ' Account Tag...', + }); + self.$el.find('.analytics').select2({ + placeholder: 'Analytic Accounts...', + }); + self.$el.find('.target_move').select2({ + placeholder: 'Target Move...', + }); + } + var child = []; + self.$('.table_view_tb').html(QWeb.render('GLTable', { + report_lines: datas['report_lines'], + filter: datas['filters'], + currency: datas['currency'], + credit_total: datas['credit_total'], + debit_total: datas['debit_total'], + debit_balance: datas['debit_balance'] + })); + }); + } catch (el) { + window.location.href + } + }, + + print_pdf: function(e) { + e.preventDefault(); + var self = this; + var action_title = self._title + self._rpc({ + model: 'account.general.ledger', + method: 'view_report', + args: [ + [self.wizard_id], action_title + ], + }).then(function(data) { + var action = { + 'type': 'ir.actions.report', + 'report_type': 'qweb-pdf', + 'report_name': 'dynamic_accounts_report.general_ledger', + 'report_file': 'dynamic_accounts_report.general_ledger', + 'data': { + 'report_data': data + }, + 'context': { + 'active_model': 'account.general.ledger', + 'landscape': 1, + 'trial_pdf_report': true + }, + 'display_name': action_title, + }; + return self.do_action(action); + }); + }, + + print_xlsx: function() { + var self = this; + var action_title = self._title + self._rpc({ + model: 'account.general.ledger', + method: 'view_report', + args: [ + [self.wizard_id], action_title + ], + }).then(function(data) { + var action = { + // 'type': 'ir_actions_dynamic_xlsx_download', + 'data': { + 'model': 'account.general.ledger', + 'options': JSON.stringify(data['filters']), + 'output_format': 'xlsx', + 'report_data': JSON.stringify(data['report_lines']), + 'report_name': action_title, + 'dfr_data': JSON.stringify(data), + }, + }; + // return self.do_action(action); + self.downloadXlsx(action) + }); + }, + + downloadXlsx: function(action) { + framework.blockUI(); + session.get_file({ + url: '/dynamic_xlsx_reports', + data: action.data, + complete: framework.unblockUI, + error: (error) => this.call('crash_manager', 'rpc_error', error), + }); + }, + + create_lines_with_style: function(rec, attr, datas) { + var temp_str = ""; + var style_name = "border-bottom: 1px solid #e6e6e6;"; + var attr_name = attr + " style=" + style_name; + + temp_str += ""; + if (datas.currency[1] == 'after') { + temp_str += ""; + temp_str += ""; + } else { + temp_str += ""; + temp_str += ""; + + } + return temp_str; + }, + + journal_line_click: function(el) { + click_num++; + var self = this; + var line = $(el.target).parent().data('id'); + return self.do_action({ + type: 'ir.actions.act_window', + view_type: 'form', + view_mode: 'form', + res_model: 'account.move', + views: [ + [false, 'form'] + ], + res_id: line, + target: 'current', + }); + + }, + + format_currency: function(currency, amount) { + if (typeof(amount) != 'number') { + amount = parseFloat(amount); + } + var formatted_value = (parseInt(amount)).toLocaleString(currency[2], { + minimumFractionDigits: 2 + }) + return formatted_value + }, + + show_drop_down: function(event) { + event.preventDefault(); + var self = this; + var account_id = $(event.currentTarget).data('account-id'); + var offset = 0; + var td = $(event.currentTarget).next('tr').find('td'); + if (td.length == 1) { + var action_title = self._title + self._rpc({ + model: 'account.general.ledger', + method: 'get_accounts_line', + args: [ + [self.wizard_id], account_id, action_title + ], + }).then(function(data) { + // _.each(data['report_lines'], function(rep_lines) { + // _.each(rep_lines['move_lines'], function(move_line) { + // + // move_line.debit = self.format_currency(data['currency'],move_line.debit); + // move_line.credit = self.format_currency(data['currency'],move_line.credit); + // move_line.balance = self.format_currency(data['currency'],move_line.balance); + // + // + // }); + // }); + + for (var i = 0; i < data['report_lines'].length; i++) { + + if (account_id == data['report_lines'][i]['id']) { + $(event.currentTarget).next('tr').find('td').remove(); + $(event.currentTarget).next('tr').after( + QWeb.render('SubSection', { + account_data: data['report_lines'][i]['move_lines'], + currency_symbol: data.currency[0], + id: data['report_lines'][i]['id'], + currency_position: data.currency[1], + + })) + $(event.currentTarget).next('tr').find('td ul li:first a').css({ + 'background-color': '#00ede8', + 'font-weight': 'bold', + }); + } + } + + }); + } + }, + + view_acc_move: function(event) { + event.preventDefault(); + var self = this; + var context = {}; + var show_acc_move = function(res_model, res_id, view_id) { + var action = { + type: 'ir.actions.act_window', + view_type: 'form', + view_mode: 'form', + res_model: res_model, + views: [ + [view_id || false, 'form'] + ], + res_id: res_id, + target: 'current', + context: context, + }; + return self.do_action(action); + }; + rpc.query({ + model: 'account.move', + method: 'search_read', + domain: [ + ['id', '=', $(event.currentTarget).data('move-id')] + ], + fields: ['id'], + limit: 1, + }) + .then(function(record) { + if (record.length > 0) { + show_acc_move('account.move', record[0].id); + } else { + show_acc_move('account.move', $(event.currentTarget).data('move-id')); + } + }); + }, + + apply_filter: function(event) { + event.preventDefault(); + var self = this; + self.initial_render = false; + var filter_data_selected = {}; + + //Account filter + var account_ids = []; + var account_text = []; + var account_res = document.getElementById("account_res") + var account_list = $(".account-partner").select2('data') + for (var i = 0; i < account_list.length; i++) { + if (account_list[i].element[0].selected === true) { + account_ids.push(parseInt(account_list[i].id)) + if (account_text.includes(account_list[i].text) === false) { + account_text.push(account_list[i].text) + } + account_res.value = account_text + account_res.innerHTML = account_res.value; + } + } + if (account_list.length == 0) { + account_res.value = "" + account_res.innerHTML = ""; + } + filter_data_selected.account_ids = account_ids + + //Account Tag filter + var account_tag_ids = []; + var account_tag_text = []; + var account_tag_res = document.getElementById("acc_tag_res") + + var account_tag_list = $(".account-tag").select2('data') + for (var i = 0; i < account_tag_list.length; i++) { + if (account_tag_list[i].element[0].selected === true) { + + account_tag_ids.push(parseInt(account_tag_list[i].id)) + if (account_tag_text.includes(account_tag_list[i].text) === false) { + account_tag_text.push(account_tag_list[i].text) + } + + account_tag_res.value = account_tag_text + account_tag_res.innerHTML = account_tag_res.value; + } + } + if (account_tag_list.length == 0) { + account_tag_res.value = "" + account_tag_res.innerHTML = ""; + + } + filter_data_selected.account_tag_ids = account_tag_ids + + //Journal Filter + if (!(this._title == 'Bank Book' || this._title == 'Cash Book')) { + var journal_ids = []; + var journal_text = []; + var journal_res = document.getElementById("journal_res") + var journal_list = $(".journals").select2('data') + for (var i = 0; i < journal_list.length; i++) { + if (journal_list[i].element[0].selected === true) { + journal_ids.push(parseInt(journal_list[i].id)) + if (journal_text.includes(journal_list[i].text) === false) { + journal_text.push(journal_list[i].text) + } + journal_res.value = journal_text + journal_res.innerHTML = journal_res.value; + } + } + if (journal_list.length == 0) { + journal_res.value = "" + journal_res.innerHTML = ""; + } + filter_data_selected.journal_ids = journal_ids + } + + //Analytic Filter + var analytic_ids = []; + var analytic_text = []; + var analytic_res = document.getElementById("analytic_res") + var analytic_list = $(".analytics").select2('data') + for (var i = 0; i < analytic_list.length; i++) { + if (analytic_list[i].element[0].selected === true) { + analytic_ids.push(parseInt(analytic_list[i].id)) + if (analytic_text.includes(analytic_list[i].text) === false) { + analytic_text.push(analytic_list[i].text) + } + analytic_res.value = analytic_text + analytic_res.innerHTML = analytic_res.value; + } + } + if (analytic_list.length == 0) { + analytic_res.value = "" + analytic_res.innerHTML = ""; + } + filter_data_selected.analytic_ids = analytic_ids + + //Date range filter + if (this.$el.find('.datetimepicker-input[name="gen_date_from"]').val()) { + filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="gen_date_from"]').val(), + time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + if (this.$el.find('.datetimepicker-input[name="gen_date_to"]').val()) { + filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="gen_date_to"]').val(), + time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + + //Target Move Filter + if ($(".target_move").length) { + var post_res = document.getElementById("post_res") + filter_data_selected.target_move = $(".target_move")[1].value + post_res.value = $(".target_move")[1].value + post_res.innerHTML = post_res.value; + if ($(".target_move")[1].value == "") { + post_res.innerHTML = "posted"; + } + } + rpc.query({ + model: 'account.general.ledger', + method: 'write', + args: [ + self.wizard_id, filter_data_selected + ], + }).then(function(res) { + self.initial_render = false; + self.load_data(self.initial_render); + }); + }, + }); + core.action_registry.add("g_l", GeneralLedger); + return GeneralLedger; }); \ No newline at end of file diff --git a/dynamic_accounts_report/static/src/js/partner_ledger.js b/dynamic_accounts_report/static/src/js/partner_ledger.js index 6ee4ecfb2..d43442f84 100644 --- a/dynamic_accounts_report/static/src/js/partner_ledger.js +++ b/dynamic_accounts_report/static/src/js/partner_ledger.js @@ -1,473 +1,461 @@ -odoo.define('dynamic_accounts_report.partner_ledger', function (require) { - 'use strict'; - var AbstractAction = require('web.AbstractAction'); - var core = require('web.core'); - var field_utils = require('web.field_utils'); - var rpc = require('web.rpc'); - var session = require('web.session'); - var utils = require('web.utils'); - var QWeb = core.qweb; - var _t = core._t; - - var datepicker = require('web.datepicker'); - var time = require('web.time'); - - window.click_num = 0; - var PartnerLedger = AbstractAction.extend({ - template: 'PartnerTemp', - events: { - 'click .parent-line': 'journal_line_click', - 'click .child_col1': 'journal_line_click', - 'click #apply_filter': 'apply_filter', - 'click #pdf': 'print_pdf', - 'click #xlsx': 'print_xlsx', - 'click .pl-line': 'show_drop_down', - 'click .view-account-move': 'view_acc_move', - 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', - - }, - - init: function(parent, action) { - this._super(parent, action); - this.currency=action.currency; - this.report_lines = action.report_lines; - this.wizard_id = action.context.wizard | null; - }, - - start: function() { - var self = this; - self.initial_render = true; - rpc.query({ - model: 'account.partner.ledger', - method: 'create', - args: [{ - }] - }).then(function(t_res) { - self.wizard_id = t_res; - self.load_data(self.initial_render); - }) - }, - - _onCalendarIconClick: function (ev) { - var $calendarInputGroup = $(ev.currentTarget); - - var calendarOptions = { - - minDate: moment({ y: 1000 }), - maxDate: moment().add(200, 'y'), - calendarWeeks: true, - defaultDate: moment().format(), - sideBySide: true, - buttons: { - showClear: true, - showClose: true, - showToday: true, - }, - - icons : { - date: 'fa fa-calendar', - - }, - locale : moment.locale(), - format : time.getLangDateFormat(), - widgetParent: 'body', - allowInputToggle: true, - }; - - $calendarInputGroup.datetimepicker(calendarOptions); - }, - - load_data: function (initial_render = true) { - var self = this; - self.$(".categ").empty(); - try{ - var self = this; - self._rpc({ - model: 'account.partner.ledger', - method: 'view_report', - args: [[this.wizard_id]], - }).then(function(datas) { - _.each(datas['report_lines'], function(rep_lines) { - rep_lines.debit = self.format_currency(datas['currency'],rep_lines.debit); - rep_lines.credit = self.format_currency(datas['currency'],rep_lines.credit); - rep_lines.balance = self.format_currency(datas['currency'],rep_lines.balance); - - - - - }); - - - - if (initial_render) { - self.$('.filter_view_tb').html(QWeb.render('PLFilterView', { - filter_data: datas['filters'], - })); - self.$el.find('.journals').select2({ - placeholder: ' Journals...', - }); - - self.$el.find('.account-partner').select2({ - placeholder: ' Accounts...', - }); - self.$el.find('.partners').select2({ - placeholder: 'Partners...', - }); - self.$el.find('.reconciled').select2({ - placeholder: 'Reconciled status...', - }); - self.$el.find('.type').select2({ - placeholder: 'Account Type...', - }); - self.$el.find('.category').select2({ - placeholder: 'Partner Tag...', - }); - self.$el.find('.acc').select2({ - placeholder: 'Select Acc...', - }); - self.$el.find('.target_move').select2({ - placeholder: 'Target Move...', - }); - } - var child=[]; - self.$('.table_view_tb').html(QWeb.render('PLTable', { - report_lines : datas['report_lines'], - filter : datas['filters'], - currency : datas['currency'], - credit_total : datas['credit_total'], - debit_total : datas['debit_total'], - debit_balance : datas['debit_balance'] - })); - }); - - } - catch (el) { - window.location.href - } - }, - - - - format_currency: function(currency, amount) { - if (typeof(amount) != 'number') { - amount = parseFloat(amount); - } - var formatted_value = (parseInt(amount)).toLocaleString(currency[2],{ - minimumFractionDigits: 2 - }) - return formatted_value - }, - - print_pdf: function(e) { - e.preventDefault(); - var self = this; - self._rpc({ - model: 'account.partner.ledger', - method: 'view_report', - args: [ - [self.wizard_id] - ], - }).then(function(data) { - var action = { - 'type': 'ir.actions.report', - 'report_type': 'qweb-pdf', - 'report_name': 'dynamic_accounts_report.partner_ledger', - 'report_file': 'dynamic_accounts_report.partner_ledger', - 'data': { - 'report_data': data - }, - 'context': { - 'active_model': 'account.partner.ledger', - 'landscape': 1, - 'partner_ledger_pdf_report': true - }, - 'display_name': 'Partner Ledger', - }; - return self.do_action(action); - }); - }, - - - - print_xlsx: function() { - var self = this; - self._rpc({ - model: 'account.partner.ledger', - method: 'view_report', - args: [ - [self.wizard_id] - ], - }).then(function(data) { - var action = { -// 'type': 'ir_actions_dynamic_xlsx_download', - 'data': { - 'model': 'account.partner.ledger', - 'options': JSON.stringify(data['filters']), - 'output_format': 'xlsx', - 'report_data': JSON.stringify(data['report_lines']), - 'report_name': 'Partner Ledger', - 'dfr_data': JSON.stringify(data), - }, - }; -// return self.do_action(action); - core.action_registry.map.t_b.prototype.downloadXlsx(action) - }); - }, - - journal_line_click: function (el){ - click_num++; - var self = this; - var line = $(el.target).parent().data('id'); - return self.do_action({ - type: 'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: 'account.move', - views: [ - [false, 'form'] - ], - res_id: line, - target: 'current', - }); - }, - - show_drop_down: function(event) { - event.preventDefault(); - var self = this; - var account_id = $(event.currentTarget).data('account-id'); - var offset = 0; - var td = $(event.currentTarget).next('tr').find('td'); - if (td.length == 1) { - self._rpc({ - model: 'account.partner.ledger', - method: 'view_report', - args: [ - [self.wizard_id] - ], - }).then(function(data) { - _.each(data['report_lines'], function(rep_lines) { - _.each(rep_lines['move_lines'], function(move_line) { - - move_line.debit = self.format_currency(data['currency'],move_line.debit); - move_line.credit = self.format_currency(data['currency'],move_line.credit); - move_line.balance = self.format_currency(data['currency'],move_line.balance); - - - }); - }); - for (var i = 0; i < data['report_lines'].length; i++) { - - if (account_id == data['report_lines'][i]['id'] ){ - $(event.currentTarget).next('tr').find('td').remove(); - $(event.currentTarget).next('tr').after( - QWeb.render('SubSectionPL', { - account_data: data['report_lines'][i]['move_lines'], - id : data['report_lines'][i]['id'] - })) - $(event.currentTarget).next('tr').find('td ul li:first a').css({ - 'background-color': '#00ede8', - 'font-weight': 'bold', - }); - } - } - }); - } - }, - - view_acc_move: function(event) { - event.preventDefault(); - var self = this; - var context = {}; - var show_acc_move = function(res_model, res_id, view_id) { - var action = { - type: 'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: res_model, - views: [ - [view_id || false, 'form'] - ], - res_id: res_id, - target: 'current', - context: context, - }; - return self.do_action(action); - }; - rpc.query({ - model: 'account.move', - method: 'search_read', - domain: [ - ['id', '=', $(event.currentTarget).data('move-id')] - ], - fields: ['id'], - limit: 1, - }) - .then(function(record) { - if (record.length > 0) { - show_acc_move('account.move', record[0].id); - } else { - show_acc_move('account.move', $(event.currentTarget).data('move-id')); - } - }); - }, - - apply_filter: function(event) { - event.preventDefault(); - var self = this; - self.initial_render = false; - var filter_data_selected = {}; - - var account_ids = []; - var account_text = []; - var span_res = document.getElementById("account_res") - var account_list = $(".account-partner").select2('data') - for (var i = 0; i < account_list.length; i++) { - if(account_list[i].element[0].selected === true) - {account_ids.push(parseInt(account_list[i].id)) - if(account_text.includes(account_list[i].text) === false) - {account_text.push(account_list[i].text) - } - span_res.value = account_text - span_res.innerHTML=span_res.value; - } - } - if (account_list.length == 0){ - span_res.value = "" - span_res.innerHTML=""; } - filter_data_selected.account_ids = account_ids - - - var journal_ids = []; - var journal_text = []; - var journal_res = document.getElementById("journal_res") - var journal_list = $(".journals").select2('data') - for (var i = 0; i < journal_list.length; i++) { - if(journal_list[i].element[0].selected === true){ - journal_ids.push(parseInt(journal_list[i].id)) - if(journal_text.includes(journal_list[i].text) === false){ - journal_text.push(journal_list[i].text) - } - journal_res.value = journal_text - journal_res.innerHTML=journal_res.value; - } - } - if (journal_list.length == 0){ - journal_res.value = "" - journal_res.innerHTML=""; - } - filter_data_selected.journal_ids = journal_ids - - var partner_ids = []; - var partner_text = []; - var span_res = document.getElementById("partner_res") - var partner_list = $(".partners").select2('data') - for (var i = 0; i < partner_list.length; i++) { - if(partner_list[i].element[0].selected === true) - {partner_ids.push(parseInt(partner_list[i].id)) - if(partner_text.includes(partner_list[i].text) === false) - {partner_text.push(partner_list[i].text) - } - span_res.value = partner_text - span_res.innerHTML=span_res.value; - } - } - if (partner_list.length == 0){ - span_res.value = "" - span_res.innerHTML=""; - } - filter_data_selected.partner_ids = partner_ids - - var account_type_id = []; - var account_type_ids_text = []; - var span_res = document.getElementById("type_res") - var type_list = $(".type").select2('data') - for (var i = 0; i < type_list.length; i++) { - if(type_list[i].element[0].selected === true) - {account_type_id.push(parseInt(type_list[i].id)) - if(account_type_ids_text.includes(type_list[i].text) === false) - {account_type_ids_text.push(type_list[i].text) - } - span_res.value = account_type_ids_text - span_res.innerHTML=span_res.value; - } - } - if (type_list.length == 0){ - span_res.value = "" - span_res.innerHTML=""; - } - filter_data_selected.account_type_id = account_type_id - - var partner_category_ids = []; - var partner_category_text = []; - var span_res = document.getElementById("category_res") - var category_list = $(".category").select2('data') - for (var i = 0; i < category_list.length; i++) { - if(category_list[i].element[0].selected === true) - {partner_category_ids.push(parseInt(category_list[i].id)) - if(partner_category_text.includes(category_list[i].text) === false) - {partner_category_text.push(category_list[i].text) - } - span_res.value = partner_category_text - span_res.innerHTML=span_res.value; - } - } - if (category_list.length == 0){ - span_res.value = "" - span_res.innerHTML=""; - } - filter_data_selected.partner_category_ids = partner_category_ids - -// if ($("#date_from").val()) { -// var dateString = $("#date_from").val(); -// filter_data_selected.date_from = dateString; -// } -// if ($("#date_to").val()) { -// var dateString = $("#date_to").val(); -// filter_data_selected.date_to = dateString; -// } - - if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { - filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } - - if (this.$el.find('.datetimepicker-input[name="date_to"]').val()) { - filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="date_to"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } - - if ($(".reconciled").length){ - var reconciled_res = document.getElementById("reconciled_res") - filter_data_selected.reconciled = $(".reconciled")[1].value - reconciled_res.value = $(".reconciled")[1].value - reconciled_res.innerHTML=reconciled_res.value; - if ($(".reconciled").value==""){ - reconciled_res.innerHTML="unreconciled"; - filter_data_selected.reconciled = "unreconciled" - } - } - - if ($(".target_move").length) { - var post_res = document.getElementById("post_res") - filter_data_selected.target_move = $(".target_move")[1].value - post_res.value = $(".target_move")[1].value - post_res.innerHTML=post_res.value; - if ($(".target_move")[1].value == "") { - post_res.innerHTML="posted"; - - } - } - rpc.query({ - model: 'account.partner.ledger', - method: 'write', - args: [ - self.wizard_id, filter_data_selected - ], - }).then(function(res) { - self.initial_render = false; - self.load_data(self.initial_render); - }); - }, - - }); - core.action_registry.add("p_l", PartnerLedger); - return PartnerLedger; -}); +odoo.define('dynamic_accounts_report.partner_ledger', function(require) { + 'use strict'; + var AbstractAction = require('web.AbstractAction'); + var core = require('web.core'); + var field_utils = require('web.field_utils'); + var rpc = require('web.rpc'); + var session = require('web.session'); + var utils = require('web.utils'); + var QWeb = core.qweb; + var _t = core._t; + var datepicker = require('web.datepicker'); + var time = require('web.time'); + var framework = require('web.framework'); + + window.click_num = 0; + var PartnerLedger = AbstractAction.extend({ + template: 'PartnerTemp', + events: { + 'click .parent-line': 'journal_line_click', + 'click .child_col1': 'journal_line_click', + 'click #apply_filter': 'apply_filter', + 'click #pdf': 'print_pdf', + 'click #xlsx': 'print_xlsx', + 'click .pl-line': 'show_drop_down', + 'click .view-account-move': 'view_acc_move', + 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', + + }, + + init: function(parent, action) { + this._super(parent, action); + this.currency = action.currency; + this.report_lines = action.report_lines; + this.wizard_id = action.context.wizard | null; + }, + + start: function() { + var self = this; + self.initial_render = true; + rpc.query({ + model: 'account.partner.ledger', + method: 'create', + args: [{}] + }).then(function(t_res) { + self.wizard_id = t_res; + self.load_data(self.initial_render); + }) + }, + + _onCalendarIconClick: function(ev) { + var $calendarInputGroup = $(ev.currentTarget); + + var calendarOptions = { + + minDate: moment({ + y: 1000 + }), + maxDate: moment().add(200, 'y'), + calendarWeeks: true, + defaultDate: moment().format(), + sideBySide: true, + buttons: { + showClear: true, + showClose: true, + showToday: true, + }, + + icons: { + date: 'fa fa-calendar', + + }, + locale: moment.locale(), + format: time.getLangDateFormat(), + widgetParent: 'body', + allowInputToggle: true, + }; + + $calendarInputGroup.datetimepicker(calendarOptions); + }, + + load_data: function(initial_render = true) { + var self = this; + self.$(".categ").empty(); + try { + var self = this; + self._rpc({ + model: 'account.partner.ledger', + method: 'view_report', + args: [ + [this.wizard_id] + ], + }).then(function(datas) { + _.each(datas['report_lines'], function(rep_lines) { + rep_lines.debit = self.format_currency(datas['currency'], rep_lines.debit); + rep_lines.credit = self.format_currency(datas['currency'], rep_lines.credit); + rep_lines.balance = self.format_currency(datas['currency'], rep_lines.balance) + }); + if (initial_render) { + self.$('.filter_view_tb').html(QWeb.render('PLFilterView', { + filter_data: datas['filters'], + })); + self.$el.find('.journals').select2({ + placeholder: ' Journals...', + }); + + self.$el.find('.account-partner').select2({ + placeholder: ' Accounts...', + }); + self.$el.find('.partners').select2({ + placeholder: 'Partners...', + }); + self.$el.find('.reconciled').select2({ + placeholder: 'Reconciled status...', + }); + self.$el.find('.type').select2({ + placeholder: 'Account Type...', + }); + self.$el.find('.category').select2({ + placeholder: 'Partner Tag...', + }); + self.$el.find('.acc').select2({ + placeholder: 'Select Acc...', + }); + self.$el.find('.target_move').select2({ + placeholder: 'Target Move...', + }); + } + var child = []; + self.$('.table_view_tb').html(QWeb.render('PLTable', { + report_lines: datas['report_lines'], + filter: datas['filters'], + currency: datas['currency'], + credit_total: datas['credit_total'], + debit_total: datas['debit_total'], + debit_balance: datas['debit_balance'] + })); + }); + + } catch (el) { + window.location.href + } + }, + + format_currency: function(currency, amount) { + if (typeof(amount) != 'number') { + amount = parseFloat(amount); + } + var formatted_value = (parseInt(amount)).toLocaleString(currency[2], { + minimumFractionDigits: 2 + }) + return formatted_value + }, + + print_pdf: function(e) { + e.preventDefault(); + var self = this; + self._rpc({ + model: 'account.partner.ledger', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + var action = { + 'type': 'ir.actions.report', + 'report_type': 'qweb-pdf', + 'report_name': 'dynamic_accounts_report.partner_ledger', + 'report_file': 'dynamic_accounts_report.partner_ledger', + 'data': { + 'report_data': data + }, + 'context': { + 'active_model': 'account.partner.ledger', + 'landscape': 1, + 'partner_ledger_pdf_report': true + }, + 'display_name': 'Partner Ledger', + }; + return self.do_action(action); + }); + }, + + print_xlsx: function() { + var self = this; + var action_title = self._title + self._rpc({ + model: 'account.partner.ledger', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + var action = { + // 'type': 'ir_actions_dynamic_xlsx_download', + 'data': { + 'model': 'account.partner.ledger', + 'options': JSON.stringify(data['filters']), + 'output_format': 'xlsx', + 'report_data': JSON.stringify(data['report_lines']), + 'report_name': action_title, + 'dfr_data': JSON.stringify(data), + }, + }; + // return self.do_action(action); + // core.action_registry.map.t_b.prototype.downloadXlsx(action) + self.downloadXlsx(action) + }); + }, + downloadXlsx: function(action) { + framework.blockUI(); + session.get_file({ + url: '/dynamic_xlsx_reports', + data: action.data, + complete: framework.unblockUI, + error: (error) => this.call('crash_manager', 'rpc_error', error), + }); + }, + + journal_line_click: function(el) { + click_num++; + var self = this; + var line = $(el.target).parent().data('id'); + return self.do_action({ + type: 'ir.actions.act_window', + view_type: 'form', + view_mode: 'form', + res_model: 'account.move', + views: [ + [false, 'form'] + ], + res_id: line, + target: 'current', + }); + }, + + show_drop_down: function(event) { + event.preventDefault(); + var self = this; + var account_id = $(event.currentTarget).data('account-id'); + var offset = 0; + var td = $(event.currentTarget).next('tr').find('td'); + if (td.length == 1) { + self._rpc({ + model: 'account.partner.ledger', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + _.each(data['report_lines'], function(rep_lines) { + _.each(rep_lines['move_lines'], function(move_line) { + + move_line.debit = self.format_currency(data['currency'], move_line.debit); + move_line.credit = self.format_currency(data['currency'], move_line.credit); + move_line.balance = self.format_currency(data['currency'], move_line.balance); + }); + }); + for (var i = 0; i < data['report_lines'].length; i++) { + + if (account_id == data['report_lines'][i]['id']) { + $(event.currentTarget).next('tr').find('td').remove(); + $(event.currentTarget).next('tr').after( + QWeb.render('SubSectionPL', { + account_data: data['report_lines'][i]['move_lines'], + id: data['report_lines'][i]['id'] + })) + $(event.currentTarget).next('tr').find('td ul li:first a').css({ + 'background-color': '#00ede8', + 'font-weight': 'bold', + }); + } + } + }); + } + }, + + view_acc_move: function(event) { + event.preventDefault(); + var self = this; + var context = {}; + var show_acc_move = function(res_model, res_id, view_id) { + var action = { + type: 'ir.actions.act_window', + view_type: 'form', + view_mode: 'form', + res_model: res_model, + views: [ + [view_id || false, 'form'] + ], + res_id: res_id, + target: 'current', + context: context, + }; + return self.do_action(action); + }; + rpc.query({ + model: 'account.move', + method: 'search_read', + domain: [ + ['id', '=', $(event.currentTarget).data('move-id')] + ], + fields: ['id'], + limit: 1, + }) + .then(function(record) { + if (record.length > 0) { + show_acc_move('account.move', record[0].id); + } else { + show_acc_move('account.move', $(event.currentTarget).data('move-id')); + } + }); + }, + + apply_filter: function(event) { + event.preventDefault(); + var self = this; + self.initial_render = false; + var filter_data_selected = {}; + + //Account filter + var account_ids = []; + var account_text = []; + var span_res = document.getElementById("account_res") + var account_list = $(".account-partner").select2('data') + for (var i = 0; i < account_list.length; i++) { + if (account_list[i].element[0].selected === true) { + account_ids.push(parseInt(account_list[i].id)) + if (account_text.includes(account_list[i].text) === false) { + account_text.push(account_list[i].text) + } + span_res.value = account_text + span_res.innerHTML = span_res.value; + } + } + if (account_list.length == 0) { + span_res.value = "" + span_res.innerHTML = ""; + } + filter_data_selected.account_ids = account_ids + + //Journal Filter + var journal_ids = []; + var journal_text = []; + var journal_res = document.getElementById("journal_res") + var journal_list = $(".journals").select2('data') + for (var i = 0; i < journal_list.length; i++) { + if (journal_list[i].element[0].selected === true) { + journal_ids.push(parseInt(journal_list[i].id)) + if (journal_text.includes(journal_list[i].text) === false) { + journal_text.push(journal_list[i].text) + } + journal_res.value = journal_text + journal_res.innerHTML = journal_res.value; + } + } + if (journal_list.length == 0) { + journal_res.value = "" + journal_res.innerHTML = ""; + } + filter_data_selected.journal_ids = journal_ids + + //Partner Filter + var partner_ids = []; + var partner_text = []; + var span_res = document.getElementById("partner_res") + var partner_list = $(".partners").select2('data') + for (var i = 0; i < partner_list.length; i++) { + if (partner_list[i].element[0].selected === true) { + partner_ids.push(parseInt(partner_list[i].id)) + if (partner_text.includes(partner_list[i].text) === false) { + partner_text.push(partner_list[i].text) + } + span_res.value = partner_text + span_res.innerHTML = span_res.value; + } + } + if (partner_list.length == 0) { + span_res.value = "" + span_res.innerHTML = ""; + } + filter_data_selected.partner_ids = partner_ids + + //Account Type Filter + if ($(".type").length) { + var type_res = document.getElementById("type_res") + filter_data_selected.account_type = $(".type")[1].value + type_res.value = $(".type")[1].value + type_res.innerHTML = account_type.value; + if ($(".type").value == "") { + type_res.innerHTML = "asset_receivable"; + filter_data_selected.account_type = "asset_receivable" + } + } + + //Partner Category Filter + var partner_category_ids = []; + var partner_category_text = []; + var span_res = document.getElementById("category_res") + var category_list = $(".category").select2('data') + for (var i = 0; i < category_list.length; i++) { + if (category_list[i].element[0].selected === true) { + partner_category_ids.push(parseInt(category_list[i].id)) + if (partner_category_text.includes(category_list[i].text) === false) { + partner_category_text.push(category_list[i].text) + } + span_res.value = partner_category_text + span_res.innerHTML = span_res.value; + } + } + if (category_list.length == 0) { + span_res.value = "" + span_res.innerHTML = ""; + } + filter_data_selected.partner_category_ids = partner_category_ids + + //Date range filter + if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { + filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + if (this.$el.find('.datetimepicker-input[name="date_to"]').val()) { + filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="date_to"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + + //Reconciled Filter + if ($(".reconciled").length) { + var reconciled_res = document.getElementById("reconciled_res") + filter_data_selected.reconciled = $(".reconciled")[1].value + reconciled_res.value = $(".reconciled")[1].value + reconciled_res.innerHTML = reconciled_res.value; + if ($(".reconciled").value == "") { + reconciled_res.innerHTML = "unreconciled"; + filter_data_selected.reconciled = "unreconciled" + } + } + + //Target Move Filter + if ($(".target_move").length) { + var post_res = document.getElementById("post_res") + filter_data_selected.target_move = $(".target_move")[1].value + post_res.value = $(".target_move")[1].value + post_res.innerHTML = post_res.value; + if ($(".target_move")[1].value == "") { + post_res.innerHTML = "posted"; + } + } + rpc.query({ + model: 'account.partner.ledger', + method: 'write', + args: [ + self.wizard_id, filter_data_selected + ], + }).then(function(res) { + self.initial_render = false; + self.load_data(self.initial_render); + }); + }, + + }); + core.action_registry.add("p_l", PartnerLedger); + return PartnerLedger; +}); \ No newline at end of file diff --git a/dynamic_accounts_report/static/src/js/trial_balance.js b/dynamic_accounts_report/static/src/js/trial_balance.js index 00a53e163..057260f80 100644 --- a/dynamic_accounts_report/static/src/js/trial_balance.js +++ b/dynamic_accounts_report/static/src/js/trial_balance.js @@ -1,338 +1,336 @@ -odoo.define('dynamic_accounts_report.trial_balance', function (require) { - 'use strict'; - var AbstractAction = require('web.AbstractAction'); - var core = require('web.core'); - var field_utils = require('web.field_utils'); - var rpc = require('web.rpc'); - var session = require('web.session'); - var utils = require('web.utils'); - - var QWeb = core.qweb; - var _t = core._t; - var framework = require('web.framework'); - - - var datepicker = require('web.datepicker'); - var time = require('web.time'); - -// import framework from 'web.framework'; -// import { download } from "@web/core/network/download"; - - -// import { registry } from "@web/core/registry"; -// const serviceRegistry = registry.category("services"); - - window.click_num = 0; - var TrialBalance = AbstractAction.extend({ - template: 'TrialTemp', - events: { - 'click .parent-line': 'journal_line_click', - 'click .child_col1': 'journal_line_click', - 'click #apply_filter': 'apply_filter', - 'click #pdf': 'print_pdf', - 'click #xlsx': 'print_xlsx', - 'click .show-gl': 'show_gl', - 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', - }, - - init: function(parent, action) { - this._super(parent, action); - this.currency=action.currency; - this.report_lines = action.report_lines; - this.wizard_id = action.context.wizard | null; - }, - - - start: function() { - var self = this; - self.initial_render = true; - rpc.query({ - model: 'account.trial.balance', - method: 'create', - args: [{ - - }] - }).then(function(t_res) { - self.wizard_id = t_res; - self.load_data(self.initial_render); - }) - }, - - - load_data: function (initial_render = true) { - var self = this; - self.$(".categ").empty(); - try{ - var self = this; - self._rpc({ - model: 'account.trial.balance', - method: 'view_report', - args: [[this.wizard_id]], - }).then(function(datas) { - - - - _.each(datas['report_lines'], function(rep_lines) { - rep_lines.debit = self.format_currency(datas['currency'],rep_lines.debit); - rep_lines.credit = self.format_currency(datas['currency'],rep_lines.credit); - rep_lines.balance = self.format_currency(datas['currency'],rep_lines.balance); - - - - }); - if (initial_render) { - self.$('.filter_view_tb').html(QWeb.render('TrialFilterView', { - filter_data: datas['filters'], - })); - self.$el.find('.journals').select2({ - placeholder: 'Select Journals...', - }); - self.$el.find('.target_move').select2({ - placeholder: 'Target Move...', - }); -// self.$el.find('#start_dateee').select2({ -// placeholder: 'Date.', -// }); - } - var child=[]; - - self.$('.table_view_tb').html(QWeb.render('TrialTable', { - - report_lines : datas['report_lines'], - filter : datas['filters'], - currency : datas['currency'], - credit_total : self.format_currency(datas['currency'],datas['debit_total']), - debit_total : self.format_currency(datas['currency'],datas['debit_total']), - })); - - }); - - } - catch (el) { - window.location.href - } - }, - - show_gl: function(e) { - var self = this; - var account_id = $(e.target).attr('data-account-id'); - var options = { - account_ids: [account_id], - } - - var action = { - type: 'ir.actions.client', - name: 'GL View', - tag: 'g_l', - target: 'new', - - domain: [['account_ids','=', account_id]], - - - } - return this.do_action(action); - - }, - - print_pdf: function(e) { - e.preventDefault(); - var self = this; - self._rpc({ - model: 'account.trial.balance', - method: 'view_report', - args: [ - [self.wizard_id] - ], - }).then(function(data) { - var action = { - 'type': 'ir.actions.report', - 'report_type': 'qweb-pdf', - 'report_name': 'dynamic_accounts_report.trial_balance', - 'report_file': 'dynamic_accounts_report.trial_balance', - 'data': { - 'report_data': data - }, - 'context': { - 'active_model': 'account.trial.balance', - 'landscape': 1, - 'trial_pdf_report': true - }, - 'display_name': 'Trial Balance', - }; - return self.do_action(action); - }); - }, - - _onCalendarIconClick: function (ev) { - var $calendarInputGroup = $(ev.currentTarget); - - var calendarOptions = { - -// minDate: moment({ y: 1000 }), -// maxDate: moment().add(200, 'y'), -// calendarWeeks: true, -// defaultDate: moment().format(), -// sideBySide: true, -// buttons: { -// showClear: true, -// showClose: true, -// showToday: true, -// }, - - icons : { - date: 'fa fa-calendar', - - }, - locale : moment.locale(), - format : time.getLangDateFormat(), - widgetParent: 'body', - allowInputToggle: true, - }; - - $calendarInputGroup.datetimepicker(calendarOptions); - }, - - - - format_currency: function(currency, amount) { - if (typeof(amount) != 'number') { - amount = parseFloat(amount); - } - var formatted_value = (parseInt(amount)).toLocaleString(currency[2],{ - minimumFractionDigits: 2 - }) - return formatted_value - }, - - print_xlsx: function() { - var self = this; - self._rpc({ - model: 'account.trial.balance', - method: 'view_report', - args: [ - [self.wizard_id] - ], - }).then(function(data) { - var action = { -// 'type': 'ir_actions_dynamic_xlsx_download', - 'data': { - 'model': 'account.trial.balance', - 'options': JSON.stringify(data['filters']), - 'output_format': 'xlsx', - 'report_data': JSON.stringify(data['report_lines']), - 'report_name': 'Trial Balance', - 'dfr_data': JSON.stringify(data), - }, - }; - -// return self.do_action(action); - self.downloadXlsx(action); - }); - }, - - downloadXlsx: function (action){ - framework.blockUI(); - session.get_file({ - url: '/dynamic_xlsx_reports', - data: action.data, - complete: framework.unblockUI, - error: (error) => this.call('crash_manager', 'rpc_error', error), - }); - }, - - journal_line_click: function (el){ - click_num++; - var self = this; - var line = $(el.target).parent().data('id'); - return self.do_action({ - type: 'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: 'account.move', - views: [ - [false, 'form'] - ], - res_id: line, - target: 'current', - }); - - }, - - - apply_filter: function(event) { - - event.preventDefault(); - var self = this; - self.initial_render = false; - - - - - var filter_data_selected = {}; - var journal_ids = []; - var journal_text = []; - var journal_res = document.getElementById("journal_res") - var journal_list = $(".journals").select2('data') - - for (var i = 0; i < journal_list.length; i++) { - if(journal_list[i].element[0].selected === true){ - - journal_ids.push(parseInt(journal_list[i].id)) - if(journal_text.includes(journal_list[i].text) === false){ - journal_text.push(journal_list[i].text) - } - journal_res.value = journal_text - journal_res.innerHTML=journal_res.value; - } - } - if (journal_list.length == 0){ - journal_res.value = "" - journal_res.innerHTML=""; - - } - filter_data_selected.journal_ids = journal_ids - - if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { - filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } - - if (this.$el.find('.datetimepicker-input[name="date_to"]').val()) { - filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="date_to"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); - } -// if ($("#date_from").val()) { -// var dateString = $("#date_from").val(); -// filter_data_selected.date_from = dateString; -// } - - -// if ($("#date_to").val()) { -// var dateString = $("#date_to").val(); -// filter_data_selected.date_to = dateString; -// } - - if ($(".target_move").length) { - var post_res = document.getElementById("post_res") - filter_data_selected.target_move = $(".target_move")[1].value - post_res.value = $(".target_move")[1].value - post_res.innerHTML=post_res.value; - if ($(".target_move")[1].value == "") { - post_res.innerHTML="posted"; - - } - } - rpc.query({ - model: 'account.trial.balance', - method: 'write', - args: [ - self.wizard_id, filter_data_selected - ], - }).then(function(res) { - self.initial_render = false; - self.load_data(self.initial_render); - }); - }, - - }); - core.action_registry.add("t_b", TrialBalance); - return TrialBalance; +odoo.define('dynamic_accounts_report.trial_balance', function(require) { + 'use strict'; + var AbstractAction = require('web.AbstractAction'); + var core = require('web.core'); + var field_utils = require('web.field_utils'); + var rpc = require('web.rpc'); + var session = require('web.session'); + var utils = require('web.utils'); + + var QWeb = core.qweb; + var _t = core._t; + var framework = require('web.framework'); + + + var datepicker = require('web.datepicker'); + var time = require('web.time'); + + // import framework from 'web.framework'; + // import { download } from "@web/core/network/download"; + + + // import { registry } from "@web/core/registry"; + // const serviceRegistry = registry.category("services"); + + window.click_num = 0; + var TrialBalance = AbstractAction.extend({ + template: 'TrialTemp', + events: { + 'click .parent-line': 'journal_line_click', + 'click .child_col1': 'journal_line_click', + 'click #apply_filter': 'apply_filter', + 'click #pdf': 'print_pdf', + 'click #xlsx': 'print_xlsx', + 'click .show-gl': 'show_gl', + 'mousedown div.input-group.date[data-target-input="nearest"]': '_onCalendarIconClick', + }, + + init: function(parent, action) { + this._super(parent, action); + this.currency = action.currency; + this.report_lines = action.report_lines; + this.wizard_id = action.context.wizard | null; + }, + + + start: function() { + var self = this; + self.initial_render = true; + rpc.query({ + model: 'account.trial.balance', + method: 'create', + args: [{ + + }] + }).then(function(t_res) { + self.wizard_id = t_res; + self.load_data(self.initial_render); + }) + }, + + + load_data: function(initial_render = true) { + var self = this; + self.$(".categ").empty(); + try { + var self = this; + self._rpc({ + model: 'account.trial.balance', + method: 'view_report', + args: [ + [this.wizard_id] + ], + }).then(function(datas) { + + + + _.each(datas['report_lines'], function(rep_lines) { + rep_lines.debit = self.format_currency(datas['currency'], rep_lines.debit); + rep_lines.credit = self.format_currency(datas['currency'], rep_lines.credit); + rep_lines.balance = self.format_currency(datas['currency'], rep_lines.balance); + + + + }); + if (initial_render) { + self.$('.filter_view_tb').html(QWeb.render('TrialFilterView', { + filter_data: datas['filters'], + })); + self.$el.find('.journals').select2({ + placeholder: 'Select Journals...', + }); + self.$el.find('.target_move').select2({ + placeholder: 'Target Move...', + }); + // self.$el.find('#start_dateee').select2({ + // placeholder: 'Date.', + // }); + } + var child = []; + + self.$('.table_view_tb').html(QWeb.render('TrialTable', { + + report_lines: datas['report_lines'], + filter: datas['filters'], + currency: datas['currency'], + credit_total: self.format_currency(datas['currency'], datas['debit_total']), + debit_total: self.format_currency(datas['currency'], datas['debit_total']), + })); + + }); + + } catch (el) { + window.location.href + } + }, + + show_gl: function(e) { + var self = this; + var account_id = $(e.target).attr('data-account-id'); + var options = { + account_ids: [account_id], + } + + var action = { + type: 'ir.actions.client', + name: 'GL View', + tag: 'g_l', + target: 'new', + + domain: [ + ['account_ids', '=', account_id] + ], + + + } + return this.do_action(action); + + }, + + print_pdf: function(e) { + e.preventDefault(); + var self = this; + self._rpc({ + model: 'account.trial.balance', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + var action = { + 'type': 'ir.actions.report', + 'report_type': 'qweb-pdf', + 'report_name': 'dynamic_accounts_report.trial_balance', + 'report_file': 'dynamic_accounts_report.trial_balance', + 'data': { + 'report_data': data + }, + 'context': { + 'active_model': 'account.trial.balance', + 'landscape': 1, + 'trial_pdf_report': true + }, + 'display_name': 'Trial Balance', + }; + return self.do_action(action); + }); + }, + + _onCalendarIconClick: function(ev) { + var $calendarInputGroup = $(ev.currentTarget); + + var calendarOptions = { + + // minDate: moment({ y: 1000 }), + // maxDate: moment().add(200, 'y'), + // calendarWeeks: true, + // defaultDate: moment().format(), + // sideBySide: true, + // buttons: { + // showClear: true, + // showClose: true, + // showToday: true, + // }, + + icons: { + date: 'fa fa-calendar', + + }, + locale: moment.locale(), + format: time.getLangDateFormat(), + widgetParent: 'body', + allowInputToggle: true, + }; + + $calendarInputGroup.datetimepicker(calendarOptions); + }, + + + + format_currency: function(currency, amount) { + if (typeof(amount) != 'number') { + amount = parseFloat(amount); + } + var formatted_value = (parseInt(amount)).toLocaleString(currency[2], { + minimumFractionDigits: 2 + }) + return formatted_value + }, + + print_xlsx: function() { + var self = this; + self._rpc({ + model: 'account.trial.balance', + method: 'view_report', + args: [ + [self.wizard_id] + ], + }).then(function(data) { + var action = { + // 'type': 'ir_actions_dynamic_xlsx_download', + 'data': { + 'model': 'account.trial.balance', + 'options': JSON.stringify(data['filters']), + 'output_format': 'xlsx', + 'report_data': JSON.stringify(data['report_lines']), + 'report_name': 'Trial Balance', + 'dfr_data': JSON.stringify(data), + }, + }; + + // return self.do_action(action); + self.downloadXlsx(action); + }); + }, + + downloadXlsx: function(action) { + framework.blockUI(); + session.get_file({ + url: '/dynamic_xlsx_reports', + data: action.data, + complete: framework.unblockUI, + error: (error) => this.call('crash_manager', 'rpc_error', error), + }); + }, + + journal_line_click: function(el) { + click_num++; + var self = this; + var line = $(el.target).parent().data('id'); + return self.do_action({ + type: 'ir.actions.act_window', + view_type: 'form', + view_mode: 'form', + res_model: 'account.move', + views: [ + [false, 'form'] + ], + res_id: line, + target: 'current', + }); + + }, + + + apply_filter: function(event) { + event.preventDefault(); + var self = this; + self.initial_render = false; + var filter_data_selected = {}; + var journal_ids = []; + var journal_text = []; + var journal_res = document.getElementById("journal_res") + var journal_list = $(".journals").select2('data') + + for (var i = 0; i < journal_list.length; i++) { + if (journal_list[i].element[0].selected === true) { + + journal_ids.push(parseInt(journal_list[i].id)) + if (journal_text.includes(journal_list[i].text) === false) { + journal_text.push(journal_list[i].text) + } + journal_res.value = journal_text + journal_res.innerHTML = journal_res.value; + } + } + if (journal_list.length == 0) { + journal_res.value = "" + journal_res.innerHTML = ""; + + } + filter_data_selected.journal_ids = journal_ids + + if (this.$el.find('.datetimepicker-input[name="date_from"]').val()) { + filter_data_selected.date_from = moment(this.$el.find('.datetimepicker-input[name="date_from"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + + if (this.$el.find('.datetimepicker-input[name="date_to"]').val()) { + filter_data_selected.date_to = moment(this.$el.find('.datetimepicker-input[name="date_to"]').val(), time.getLangDateFormat()).locale('en').format('YYYY-MM-DD'); + } + // if ($("#date_from").val()) { + // var dateString = $("#date_from").val(); + // filter_data_selected.date_from = dateString; + // } + + + // if ($("#date_to").val()) { + // var dateString = $("#date_to").val(); + // filter_data_selected.date_to = dateString; + // } + + if ($(".target_move").length) { + var post_res = document.getElementById("post_res") + filter_data_selected.target_move = $(".target_move")[1].value + post_res.value = $(".target_move")[1].value + post_res.innerHTML = post_res.value; + if ($(".target_move")[1].value == "") { + post_res.innerHTML = "posted"; + + } + } + rpc.query({ + model: 'account.trial.balance', + method: 'write', + args: [ + self.wizard_id, filter_data_selected + ], + }).then(function(res) { + self.initial_render = false; + self.load_data(self.initial_render); + }); + }, + + }); + core.action_registry.add("t_b", TrialBalance); + return TrialBalance; }); \ No newline at end of file diff --git a/dynamic_accounts_report/static/src/xml/financial_reports_view.xml b/dynamic_accounts_report/static/src/xml/financial_reports_view.xml index e2dd53677..95a429af1 100644 --- a/dynamic_accounts_report/static/src/xml/financial_reports_view.xml +++ b/dynamic_accounts_report/static/src/xml/financial_reports_view.xml @@ -2,392 +2,238 @@
    -
    +


    -
    +
    -
    diff --git a/dynamic_accounts_report/report/trial_balance.py b/dynamic_accounts_report/report/trial_balance.py index bc33bbc04..62097fabb 100644 --- a/dynamic_accounts_report/report/trial_balance.py +++ b/dynamic_accounts_report/report/trial_balance.py @@ -1,18 +1,42 @@ -from odoo import api, models, _ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2022-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# 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 . +# +############################################################################# +from odoo import api, models class TrialBalance(models.AbstractModel): _name = 'report.dynamic_accounts_report.trial_balance' @api.model - def _get_report_values(self, docids, data=None): + def _get_report_values(self,docids, data=None): if self.env.context.get('trial_pdf_report'): if data.get('report_data'): - data.update({'account_data': data.get('report_data')['report_lines'], + data.update({'account_data': data.get('report_data' + )['report_lines'], 'Filters': data.get('report_data')['filters'], - 'debit_total': data.get('report_data')['debit_total'], - 'credit_total': data.get('report_data')['credit_total'], + 'debit_total': data.get('report_data' + )['debit_total'], + 'credit_total': data.get('report_data' + )['credit_total'], 'company': self.env.company, }) return data diff --git a/dynamic_accounts_report/static/description/index.html b/dynamic_accounts_report/static/description/index.html index 5ffd1f8ed..83b243dba 100644 --- a/dynamic_accounts_report/static/description/index.html +++ b/dynamic_accounts_report/static/description/index.html @@ -612,7 +612,6 @@

    - View Source move from Cash Book Report

    "+rec['code'] +rec['name'] +"
    "+rec['debit'].toFixed(2)+datas.currency[0]+""+rec['credit'].toFixed(2) +datas.currency[0]+ ""+datas.currency[0]+rec['debit'].toFixed(2) + ""+datas.currency[0]+rec['credit'].toFixed(2) + "" + rec['code'] + rec['name'] + "" + rec['debit'].toFixed(2) + datas.currency[0] + "" + rec['credit'].toFixed(2) + datas.currency[0] + "" + datas.currency[0] + rec['debit'].toFixed(2) + "" + datas.currency[0] + rec['credit'].toFixed(2) + ""+rec['code'] +rec['name'] +""+rec['debit'].toFixed(2)+datas.currency[0]+""+rec['credit'].toFixed(2) +datas.currency[0]+ ""+datas.currency[0]+rec['debit'].toFixed(2) + ""+datas.currency[0]+rec['credit'].toFixed(2) + "" + rec['code'] + rec['name'] + "" + rec['debit'].toFixed(2) + datas.currency[0] + "" + rec['credit'].toFixed(2) + datas.currency[0] + "" + datas.currency[0] + rec['debit'].toFixed(2) + "" + datas.currency[0] + rec['credit'].toFixed(2) + ""+rec['code'] +rec['name'] +""+rec['debit'].toFixed(2)+datas.currency[0]+""+rec['credit'].toFixed(2) +datas.currency[0]+ ""+datas.currency[0]+rec['debit'].toFixed(2) + ""+datas.currency[0]+rec['credit'].toFixed(2) + "" + rec['code'] + rec['name'] + "" + rec['debit'].toFixed(2) + datas.currency[0] + "" + rec['credit'].toFixed(2) + datas.currency[0] + "" + datas.currency[0] + rec['debit'].toFixed(2) + "" + datas.currency[0] + rec['credit'].toFixed(2) + "
    - - - - + + + - - + - - - + - - + - - - + - - - - + + + - + - + - - + + - - + + - - -
    - Debit - - Credit - - Balance - f Debit Credit Balance
    +
    - - - - - - + - + + - + - + - - + - + - +
    - + - + - + - +
    -

    - +

    -
    - - + +


    -
    - +
    - - - Date Range - + + Date Range