Browse Source

May 16 : [UPDT] Updated 'dynamic_accounts_report'

pull/275/head
AjmalCybro 2 years ago
parent
commit
9a357e1fdd
  1. 20
      dynamic_accounts_report/__init__.py
  2. 9
      dynamic_accounts_report/__manifest__.py
  3. 20
      dynamic_accounts_report/controllers/__init__.py
  4. 32
      dynamic_accounts_report/controllers/controllers.py
  5. 5
      dynamic_accounts_report/doc/RELEASE_NOTES.md
  6. 21
      dynamic_accounts_report/report/__init__.py
  7. 21
      dynamic_accounts_report/report/ageing.py
  8. 30
      dynamic_accounts_report/report/cash_flow_report.py
  9. 30
      dynamic_accounts_report/report/daybook.py
  10. 20
      dynamic_accounts_report/report/financial_reports.py
  11. 36
      dynamic_accounts_report/report/general_ledger.py
  12. 21
      dynamic_accounts_report/report/partner_ledger.py
  13. 42
      dynamic_accounts_report/report/trial_balance.py
  14. 3
      dynamic_accounts_report/static/src/js/general_ledger.js
  15. 1
      dynamic_accounts_report/static/src/js/partner_ledger.js
  16. 21
      dynamic_accounts_report/wizard/__init__.py
  17. 22
      dynamic_accounts_report/wizard/ageing.py
  18. 21
      dynamic_accounts_report/wizard/balance_sheet.py
  19. 21
      dynamic_accounts_report/wizard/balance_sheet_config.py
  20. 21
      dynamic_accounts_report/wizard/cash_flow.py
  21. 21
      dynamic_accounts_report/wizard/daybook.py
  22. 273
      dynamic_accounts_report/wizard/general_ledger.py
  23. 100
      dynamic_accounts_report/wizard/partner_leadger.py
  24. 21
      dynamic_accounts_report/wizard/trial_balance.py

20
dynamic_accounts_report/__init__.py

@ -1,4 +1,24 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from . import controllers from . import controllers
from . import wizard from . import wizard

9
dynamic_accounts_report/__manifest__.py

@ -27,11 +27,14 @@
'live_test_url': 'https://www.youtube.com/watch?v=gVQi9q9Rs-E&t=5s', 'live_test_url': 'https://www.youtube.com/watch?v=gVQi9q9Rs-E&t=5s',
'summary': """Dynamic Financial Reports with drill 'summary': """Dynamic Financial Reports with drill
down and filters Community Edition""", down and filters Community Edition""",
'description': "Dynamic Financial Reports, DynamicFinancialReports, FinancialReport, Accountingreports, odoo reports, odoo" 'description': "Dynamic Financial Reports, DynamicFinancialReports, "
"This module creates dynamic Accounting General Ledger, Trial Balance, Balance Sheet " "FinancialReport, Accountingreports, odoo reports, odoo"
"This module creates dynamic Accounting General Ledger, "
"Trial Balance, Balance Sheet "
"Proft and Loss, Cash Flow Statements, Partner Ledger," "Proft and Loss, Cash Flow Statements, Partner Ledger,"
"Partner Ageing, Day book" "Partner Ageing, Day book"
"Bank book and Cash book reports in Odoo 14 community edition.", "Bank book and Cash book reports in Odoo 14"
"community edition.",
'author': 'Cybrosys Techno Solutions', 'author': 'Cybrosys Techno Solutions',
'website': "https://www.cybrosys.com", 'website': "https://www.cybrosys.com",
'company': 'Cybrosys Techno Solutions', 'company': 'Cybrosys Techno Solutions',

20
dynamic_accounts_report/controllers/__init__.py

@ -1,3 +1,23 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from . import controllers from . import controllers

32
dynamic_accounts_report/controllers/controllers.py

@ -1,4 +1,24 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import json import json
from odoo import http from odoo import http
@ -8,8 +28,10 @@ from odoo.tools import html_escape
class TBXLSXReportController(http.Controller): class TBXLSXReportController(http.Controller):
@http.route('/dynamic_xlsx_reports', type='http', auth='user', methods=['POST'], csrf=False) @http.route('/dynamic_xlsx_reports', type='http', auth='user',
def get_report_xlsx(self, model, options, output_format, token, report_data, report_name, dfr_data, **kw): methods=['POST'], csrf=False)
def get_report_xlsx(self, model, options, output_format, token, report_data,
report_name, dfr_data, **kw):
uid = request.session.uid uid = request.session.uid
report_obj = request.env[model].with_user(uid) report_obj = request.env[model].with_user(uid)
@ -21,10 +43,12 @@ class TBXLSXReportController(http.Controller):
None, None,
headers=[ headers=[
('Content-Type', 'application/vnd.ms-excel'), ('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) response.set_cookie('fileToken', token)
return response return response
except Exception as e: except Exception as e:

5
dynamic_accounts_report/doc/RELEASE_NOTES.md

@ -46,3 +46,8 @@
#### Version 14.0.1.2.7 #### Version 14.0.1.2.7
#### UPDT AND BUGFIX #### UPDT AND BUGFIX
- Loading Issue and orderby date - Loading Issue and orderby date
#### 27.04.2023
#### Version 14.0.1.2.7
#### UPDT AND BUGFIX
- Update and Bugfix in General Ledger

21
dynamic_accounts_report/report/__init__.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from . import trial_balance from . import trial_balance
from . import general_ledger from . import general_ledger
from . import cash_flow_report from . import cash_flow_report

21
dynamic_accounts_report/report/ageing.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from odoo import api, models, _ from odoo import api, models, _

30
dynamic_accounts_report/report/cash_flow_report.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from odoo import api, models, _ from odoo import api, models, _
@ -9,8 +30,9 @@ class GeneralLedger(models.AbstractModel):
if self.env.context.get('trial_pdf_report'): if self.env.context.get('trial_pdf_report'):
if data.get('report_data'): if data.get('report_data'):
data.update({'account_data': data.get('report_data')['report_lines'], data.update(
'Filters': data.get('report_data')['filters'], {'account_data': data.get('report_data')['report_lines'],
'company': self.env.company, 'Filters': data.get('report_data')['filters'],
}) 'company': self.env.company,
})
return data return data

30
dynamic_accounts_report/report/daybook.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from odoo import api, models, _ from odoo import api, models, _
@ -10,8 +31,9 @@ class DayBook(models.AbstractModel):
if self.env.context.get('daybook_pdf_report'): if self.env.context.get('daybook_pdf_report'):
if data.get('report_data'): if data.get('report_data'):
data.update({'account_data': data.get('report_data')['report_lines'], data.update(
'Filters': data.get('report_data')['filters'], {'account_data': data.get('report_data')['report_lines'],
'company': self.env.company, 'Filters': data.get('report_data')['filters'],
}) 'company': self.env.company,
})
return data return data

20
dynamic_accounts_report/report/financial_reports.py

@ -1,4 +1,24 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from odoo import api, models, _ from odoo import api, models, _

36
dynamic_accounts_report/report/general_ledger.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from odoo import api, models, _ from odoo import api, models, _
@ -10,11 +31,12 @@ class GeneralLedger(models.AbstractModel):
if self.env.context.get('trial_pdf_report'): if self.env.context.get('trial_pdf_report'):
if data.get('report_data'): if data.get('report_data'):
data.update({'account_data': data.get('report_data')['report_lines'], data.update(
'Filters': data.get('report_data')['filters'], {'account_data': data.get('report_data')['report_lines'],
'debit_total': data.get('report_data')['debit_total'], 'Filters': data.get('report_data')['filters'],
'credit_total': data.get('report_data')['credit_total'], 'debit_total': data.get('report_data')['debit_total'],
'title': data.get('report_data')['name'], 'credit_total': data.get('report_data')['credit_total'],
'company': self.env.company, 'title': data.get('report_data')['name'],
}) 'company': self.env.company,
})
return data return data

21
dynamic_accounts_report/report/partner_ledger.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from odoo import api, models, _ from odoo import api, models, _

42
dynamic_accounts_report/report/trial_balance.py

@ -1,3 +1,45 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from odoo import api, models, _ from odoo import api, models, _

3
dynamic_accounts_report/static/src/js/general_ledger.js

@ -167,6 +167,7 @@ odoo.define('dynamic_cash_flow_statements.general_ledger', function (require) {
[self.wizard_id], action_title [self.wizard_id], action_title
], ],
}).then(function(data) { }).then(function(data) {
console.log(data,"de")
var action = { var action = {
'type': 'ir.actions.report', 'type': 'ir.actions.report',
'report_type': 'qweb-pdf', 'report_type': 'qweb-pdf',
@ -196,6 +197,7 @@ odoo.define('dynamic_cash_flow_statements.general_ledger', function (require) {
[self.wizard_id], action_title [self.wizard_id], action_title
], ],
}).then(function(data) { }).then(function(data) {
console.log(data['report_lines'])
var action = { var action = {
'type': 'ir_actions_dynamic_xlsx_download', 'type': 'ir_actions_dynamic_xlsx_download',
'data': { 'data': {
@ -265,6 +267,7 @@ odoo.define('dynamic_cash_flow_statements.general_ledger', function (require) {
event.preventDefault(); event.preventDefault();
var self = this; var self = this;
var account_id = $(event.currentTarget).data('account-id'); var account_id = $(event.currentTarget).data('account-id');
console.log(account_id,"acc")
var offset = 0; var offset = 0;
var td = $(event.currentTarget).next('tr').find('td'); var td = $(event.currentTarget).next('tr').find('td');
if (td.length == 1) { if (td.length == 1) {

1
dynamic_accounts_report/static/src/js/partner_ledger.js

@ -200,6 +200,7 @@ odoo.define('dynamic_accounts_report.partner_ledger', function (require) {
[self.wizard_id] [self.wizard_id]
], ],
}).then(function(data) { }).then(function(data) {
console.log(data['report_lines'])
var action = { var action = {
'type': 'ir_actions_dynamic_xlsx_download', 'type': 'ir_actions_dynamic_xlsx_download',
'data': { 'data': {

21
dynamic_accounts_report/wizard/__init__.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from . import general_ledger from . import general_ledger
from . import trial_balance from . import trial_balance
from . import cash_flow from . import cash_flow

22
dynamic_accounts_report/wizard/ageing.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import time import time
from datetime import datetime from datetime import datetime
@ -37,6 +58,7 @@ class AgeingView(models.TransientModel):
@api.model @api.model
def view_report(self, option): def view_report(self, option):
print(self,option)
r = self.env['account.partner.ageing'].search([('id', '=', option[0])]) r = self.env['account.partner.ageing'].search([('id', '=', option[0])])
data = { data = {

21
dynamic_accounts_report/wizard/balance_sheet.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import time import time
from odoo import fields, models, api, _ from odoo import fields, models, api, _

21
dynamic_accounts_report/wizard/balance_sheet_config.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import re import re
from odoo import models, fields, api from odoo import models, fields, api

21
dynamic_accounts_report/wizard/cash_flow.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import time import time
from datetime import datetime from datetime import datetime

21
dynamic_accounts_report/wizard/daybook.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import time import time
from datetime import date from datetime import date
from datetime import timedelta, datetime from datetime import timedelta, datetime

273
dynamic_accounts_report/wizard/general_ledger.py

@ -1,9 +1,31 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import time import time
from odoo import fields, models, api, _ from odoo import fields, models, api, _
import io import io
import json import json
from odoo.exceptions import AccessError, UserError, AccessDenied from odoo.exceptions import AccessError, UserError, AccessDenied
try: try:
from odoo.tools.misc import xlsxwriter from odoo.tools.misc import xlsxwriter
except ImportError: except ImportError:
@ -22,12 +44,14 @@ class GeneralView(models.TransientModel):
"account.account", "account.account",
string="Accounts", string="Accounts",
) )
account_tag_ids = fields.Many2many("account.account.tag", string="Account Tags") account_tag_ids = fields.Many2many("account.account.tag",
string="Account Tags")
analytic_ids = fields.Many2many( analytic_ids = fields.Many2many(
"account.analytic.account", string="Analytic Accounts" "account.analytic.account", string="Analytic Accounts"
) )
analytic_tag_ids = fields.Many2many("account.analytic.tag", string="Analytic Tags") analytic_tag_ids = fields.Many2many("account.analytic.tag",
string="Analytic Tags")
display_account = fields.Selection( display_account = fields.Selection(
[('all', 'All'), ('movement', 'With movements'), [('all', 'All'), ('movement', 'With movements'),
@ -46,24 +70,30 @@ class GeneralView(models.TransientModel):
r = self.env['account.general.ledger'].search([('id', '=', option[0])]) r = self.env['account.general.ledger'].search([('id', '=', option[0])])
self = r self = r
new_title = '' new_title = ''
trans_title = self.env['ir.translation'].search([('value', '=', title), ('module', '=', 'dynamic_accounts_report')], limit=1).src trans_title = self.env['ir.translation'].search(
[('value', '=', title), ('module', '=', 'dynamic_accounts_report')],
limit=1).src
company_id = self.env.companies.ids company_id = self.env.companies.ids
if r.journal_ids: if r.journal_ids:
journals = r.journal_ids journals = r.journal_ids
else: else:
journals = self.env['account.journal'].search([('company_id', 'in', company_id)]) journals = self.env['account.journal'].search(
[('company_id', 'in', company_id)])
if title == 'General Ledger' or trans_title == 'General Ledger': if title == 'General Ledger' or trans_title == 'General Ledger':
if r.journal_ids: if r.journal_ids:
journals = r.journal_ids journals = r.journal_ids
else: else:
journals = self.env['account.journal'].search([('company_id', 'in', company_id)]) journals = self.env['account.journal'].search(
[('company_id', 'in', company_id)])
new_title = title new_title = title
if title == 'Bank Book' or trans_title == 'Bank Book': if title == 'Bank Book' or trans_title == 'Bank Book':
journals = self.env['account.journal'].search([('type', '=', 'bank'), ('company_id', 'in', company_id)]) journals = self.env['account.journal'].search(
[('type', '=', 'bank'), ('company_id', 'in', company_id)])
new_title = title new_title = title
if title == 'Cash Book' or trans_title == 'Cash Book': if title == 'Cash Book' or trans_title == 'Cash Book':
journals = self.env['account.journal'].search([('type', '=', 'cash'), ('company_id', 'in', company_id)]) journals = self.env['account.journal'].search(
[('type', '=', 'cash'), ('company_id', 'in', company_id)])
new_title = title new_title = title
r.write({ r.write({
'titles': new_title, 'titles': new_title,
@ -106,11 +136,13 @@ class GeneralView(models.TransientModel):
data = self.get_filter_data(option) data = self.get_filter_data(option)
filters = {} filters = {}
if data.get('journal_ids'): if data.get('journal_ids'):
filters['journals'] = self.env['account.journal'].browse(data.get('journal_ids')).mapped('code') filters['journals'] = self.env['account.journal'].browse(
data.get('journal_ids')).mapped('code')
else: else:
filters['journals'] = ['All'] filters['journals'] = ['All']
if data.get('account_ids', []): if data.get('account_ids', []):
filters['accounts'] = self.env['account.account'].browse(data.get('account_ids', [])).mapped('code') filters['accounts'] = self.env['account.account'].browse(
data.get('account_ids', [])).mapped('code')
else: else:
filters['accounts'] = ['All'] filters['accounts'] = ['All']
if data.get('account_tag_ids', []): if data.get('account_tag_ids', []):
@ -153,14 +185,16 @@ class GeneralView(models.TransientModel):
account_tags = r.account_tag_ids if r.account_tag_ids else self.env[ account_tags = r.account_tag_ids if r.account_tag_ids else self.env[
'account.account.tag'].search([]) 'account.account.tag'].search([])
analytics = r.analytic_ids if r.analytic_ids else self.env['account.analytic.account'].search( analytics = r.analytic_ids if r.analytic_ids else self.env[
'account.analytic.account'].search(
company_domain) company_domain)
analytic_tags = r.analytic_tag_ids if r.analytic_tag_ids else self.env[ analytic_tags = r.analytic_tag_ids if r.analytic_tag_ids else self.env[
'account.analytic.tag'].search([]) 'account.analytic.tag'].search([])
journal_ids = r.journal_ids if r.journal_ids else self.env[
journal_ids = r.journal_ids if r.journal_ids else self.env['account.journal'].search(company_domain, order="company_id, name") 'account.journal'].search(company_domain, order="company_id, name")
accounts_ids = self.account_ids if self.account_ids else self.env['account.account'].search(company_domain, order="company_id, name") accounts_ids = self.account_ids if self.account_ids else self.env[
'account.account'].search(company_domain, order="company_id, name")
journals = [] journals = []
o_company = False o_company = False
for j in journal_ids: for j in journal_ids:
@ -178,8 +212,6 @@ class GeneralView(models.TransientModel):
o_company = j.company_id o_company = j.company_id
accounts.append((j.id, j.name)) accounts.append((j.id, j.name))
filter_dict = { filter_dict = {
'journal_ids': r.journal_ids.ids, 'journal_ids': r.journal_ids.ids,
'analytic_ids': r.analytic_ids.ids, 'analytic_ids': r.analytic_ids.ids,
@ -196,14 +228,14 @@ class GeneralView(models.TransientModel):
'accounts_list': accounts, 'accounts_list': accounts,
'account_tag_list': [(a.id, a.name) for a in account_tags], 'account_tag_list': [(a.id, a.name) for a in account_tags],
'analytic_list': [(anl.id, anl.name) for anl in analytics], 'analytic_list': [(anl.id, anl.name) for anl in analytics],
'analytic_tag_list': [(anltag.id, anltag.name) for anltag in analytic_tags], 'analytic_tag_list': [(anltag.id, anltag.name) for anltag in
analytic_tags],
'company_name': ', '.join(self.env.companies.mapped('name')), 'company_name': ', '.join(self.env.companies.mapped('name')),
} }
filter_dict.update(default_filters) filter_dict.update(default_filters)
return filter_dict return filter_dict
def _get_report_values(self, data): def _get_report_values(self, data):
docs = data['model'] docs = data['model']
display_account = data['display_account'] display_account = data['display_account']
init_balance = True init_balance = True
@ -216,16 +248,33 @@ class GeneralView(models.TransientModel):
accounts = self.env['account.account'].search(company_domain) accounts = self.env['account.account'].search(company_domain)
if not accounts: if not accounts:
raise UserError(_("No Accounts Found! Please Add One")) raise UserError(_("No Accounts Found! Please Add One"))
account_res = self._get_accounts(accounts, init_balance, display_account, data) account_res = self._get_accounts(accounts, init_balance,
display_account, data)
list_ac = []
for rec in account_res:
list_ac.append(rec['account_id'])
title = "General Ledger"
account_line = self.get_accounts_line(list_ac, title)['report_lines']
acc_line_list = []
acc_line_list.clear()
for line in account_line[0]['move_lines']:
acc_line_list.append(line)
for res in account_res:
line_list = []
line_list.clear()
for line in acc_line_list:
if line['account_id'] == res['account_id']:
line_list.append(line)
res['move_lines'] = line_list
debit_total = 0 debit_total = 0
debit_total = sum(x['debit'] for x in account_res) debit_total = sum(x['debit'] for x in account_res)
credit_total = sum(x['credit'] for x in account_res) credit_total = sum(x['credit'] for x in account_res)
debit_balance = round(debit_total,2) - round(credit_total,2) debit_balance = round(debit_total, 2) - round(credit_total, 2)
return { return {
'doc_ids': self.ids, 'doc_ids': self.ids,
'debit_total': debit_total, 'debit_total': debit_total,
'credit_total': credit_total, 'credit_total': credit_total,
'debit_balance':debit_balance, 'debit_balance': debit_balance,
'docs': docs, 'docs': docs,
'time': time, 'time': time,
'Accounts': account_res, 'Accounts': account_res,
@ -245,26 +294,29 @@ class GeneralView(models.TransientModel):
if vals.get('journal_ids') == []: if vals.get('journal_ids') == []:
vals.update({'journal_ids': [(5,)]}) vals.update({'journal_ids': [(5,)]})
if vals.get('account_ids'): if vals.get('account_ids'):
vals.update({'account_ids': [(4, j) for j in vals.get('account_ids')]}) vals.update(
{'account_ids': [(4, j) for j in vals.get('account_ids')]})
if vals.get('account_ids') == []: if vals.get('account_ids') == []:
vals.update({'account_ids': [(5,)]}) vals.update({'account_ids': [(5,)]})
if vals.get('account_tag_ids'): if vals.get('account_tag_ids'):
vals.update({'account_tag_ids': [(4, j) for j in vals.get('account_tag_ids')]}) vals.update({'account_tag_ids': [(4, j) for j in
vals.get('account_tag_ids')]})
if vals.get('account_tag_ids') == []: if vals.get('account_tag_ids') == []:
vals.update({'account_tag_ids': [(5,)]}) vals.update({'account_tag_ids': [(5,)]})
if vals.get('analytic_ids'): if vals.get('analytic_ids'):
vals.update({'analytic_ids': [(4, j) for j in vals.get('analytic_ids')]}) vals.update(
{'analytic_ids': [(4, j) for j in vals.get('analytic_ids')]})
if vals.get('analytic_ids') == []: if vals.get('analytic_ids') == []:
vals.update({'analytic_ids': [(5,)]}) vals.update({'analytic_ids': [(5,)]})
if vals.get('analytic_tag_ids') == []: if vals.get('analytic_tag_ids') == []:
vals.update({'analytic_tag_ids': [(4, j) for j in vals.get('analytic_tag_ids')]}) vals.update({'analytic_tag_ids': [(4, j) for j in
vals.get('analytic_tag_ids')]})
if vals.get('analytic_tag_ids') == []: if vals.get('analytic_tag_ids') == []:
vals.update({'analytic_tag_ids': [(5,)]}) vals.update({'analytic_tag_ids': [(5,)]})
res = super(GeneralView, self).write(vals) res = super(GeneralView, self).write(vals)
return res return res
def _get_accounts(self, accounts, init_balance, display_account, data): def _get_accounts(self, accounts, init_balance, display_account, data):
cr = self.env.cr cr = self.env.cr
MoveLine = self.env['account.move.line'] MoveLine = self.env['account.move.line']
move_lines = {x: [] for x in accounts.ids} move_lines = {x: [] for x in accounts.ids}
@ -289,18 +341,20 @@ class GeneralView(models.TransientModel):
if data.get('date_from'): if data.get('date_from'):
new_filter += " AND l.date < '%s'" % data.get('date_from') new_filter += " AND l.date < '%s'" % data.get('date_from')
if data['journals']: if data['journals']:
new_filter += ' AND j.id IN %s' % str(tuple(data['journals'].ids) + tuple([0])) new_filter += ' AND j.id IN %s' % str(
tuple(data['journals'].ids) + tuple([0]))
if data.get('accounts'): if data.get('accounts'):
WHERE = "WHERE l.account_id IN %s" % str(tuple(data.get('accounts').ids) + tuple([0])) WHERE = "WHERE l.account_id IN %s" % str(
tuple(data.get('accounts').ids) + tuple([0]))
else: else:
WHERE = "WHERE l.account_id IN %s" WHERE = "WHERE l.account_id IN %s"
if data.get('analytics'): if data.get('analytics'):
WHERE += ' AND anl.id IN %s' % str(tuple(data.get('analytics').ids) + tuple([0])) WHERE += ' AND anl.id IN %s' % str(
tuple(data.get('analytics').ids) + tuple([0]))
if data.get('analytic_tags'): if data.get('analytic_tags'):
WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str( WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str(
tuple(data.get('analytic_tags').ids) + tuple([0])) tuple(data.get('analytic_tags').ids) + tuple([0]))
sql = ("""SELECT 0 AS lid, l.account_id AS account_id, '' AS ldate, '' AS lcode, 0.0 AS amount_currency, '' AS lref, 'Initial Balance' AS lname, COALESCE(SUM(l.debit),0.0) AS debit, COALESCE(SUM(l.credit),0.0) AS credit, COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) as balance, '' AS lpartner_id,\ sql = ("""SELECT 0 AS lid, l.account_id AS account_id, '' AS ldate, '' AS lcode, 0.0 AS amount_currency, '' AS lref, 'Initial Balance' AS lname, COALESCE(SUM(l.debit),0.0) AS debit, COALESCE(SUM(l.credit),0.0) AS credit, COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) as balance, '' AS lpartner_id,\
'' AS move_name, '' AS mmove_id, '' AS currency_code,\ '' AS move_name, '' AS mmove_id, '' AS currency_code,\
NULL AS currency_id,\ NULL AS currency_id,\
@ -315,7 +369,7 @@ class GeneralView(models.TransientModel):
LEFT JOIN account_analytic_account anl ON (l.analytic_account_id=anl.id) LEFT JOIN account_analytic_account anl ON (l.analytic_account_id=anl.id)
LEFT JOIN account_analytic_tag_account_move_line_rel anltag ON (anltag.account_move_line_id=l.id) LEFT JOIN account_analytic_tag_account_move_line_rel anltag ON (anltag.account_move_line_id=l.id)
JOIN account_journal j ON (l.journal_id=j.id)""" JOIN account_journal j ON (l.journal_id=j.id)"""
+ WHERE + new_filter + ' GROUP BY l.account_id') + WHERE + new_filter + ' GROUP BY l.account_id')
if data.get('accounts'): if data.get('accounts'):
params = tuple(init_where_params) params = tuple(init_where_params)
else: else:
@ -330,7 +384,8 @@ class GeneralView(models.TransientModel):
if where_clause.strip(): if where_clause.strip():
wheres.append(where_clause.strip()) wheres.append(where_clause.strip())
final_filters = " AND ".join(wheres) final_filters = " AND ".join(wheres)
final_filters = final_filters.replace('account_move_line__move_id', 'm').replace( final_filters = final_filters.replace('account_move_line__move_id',
'm').replace(
'account_move_line', 'l') 'account_move_line', 'l')
new_final_filter = final_filters new_final_filter = final_filters
if data['target_move'] == 'posted': if data['target_move'] == 'posted':
@ -343,21 +398,23 @@ class GeneralView(models.TransientModel):
new_final_filter += " AND l.date <= '%s'" % data.get('date_to') new_final_filter += " AND l.date <= '%s'" % data.get('date_to')
if data['journals']: if data['journals']:
new_final_filter += ' AND j.id IN %s' % str(tuple(data['journals'].ids) + tuple([0])) new_final_filter += ' AND j.id IN %s' % str(
tuple(data['journals'].ids) + tuple([0]))
if data.get('accounts'): if data.get('accounts'):
WHERE = "WHERE l.account_id IN %s" % str(tuple(data.get('accounts').ids) + tuple([0])) WHERE = "WHERE l.account_id IN %s" % str(
tuple(data.get('accounts').ids) + tuple([0]))
else: else:
WHERE = "WHERE l.account_id IN %s" WHERE = "WHERE l.account_id IN %s"
if data.get('analytics'): if data.get('analytics'):
WHERE += ' AND anl.id IN %s' % str(tuple(data.get('analytics').ids) + tuple([0])) WHERE += ' AND anl.id IN %s' % str(
tuple(data.get('analytics').ids) + tuple([0]))
if data.get('analytic_tags'): if data.get('analytic_tags'):
WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str( WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str(
tuple(data.get('analytic_tags').ids) + tuple([0])) tuple(data.get('analytic_tags').ids) + tuple([0]))
# Get move lines base on sql query and Calculate the total balance of move lines # Get move lines base on sql query and Calculate the total balance of move lines
sql = ('''SELECT l.account_id AS account_id, a.code AS code,a.id AS id, a.name AS name, ROUND(COALESCE(SUM(l.debit),0),2) AS debit, ROUND(COALESCE(SUM(l.credit),0),2) AS credit, ROUND(COALESCE(SUM(l.balance),0),2) AS balance sql = ('''SELECT l.account_id AS account_id, a.code AS code,a.id AS id, a.name AS name, ROUND(COALESCE(SUM(l.debit),0),2) AS debit, ROUND(COALESCE(SUM(l.credit),0),2) AS credit, ROUND(COALESCE(SUM(l.balance),0),2) AS balance
FROM account_move_line l\ FROM account_move_line l\
JOIN account_move m ON (l.move_id=m.id)\ JOIN account_move m ON (l.move_id=m.id)\
LEFT JOIN res_currency c ON (l.currency_id=c.id)\ LEFT JOIN res_currency c ON (l.currency_id=c.id)\
@ -374,40 +431,8 @@ class GeneralView(models.TransientModel):
params = (tuple(accounts.ids),) + tuple(where_params) params = (tuple(accounts.ids),) + tuple(where_params)
cr.execute(sql, params) cr.execute(sql, params)
account_res = cr.dictfetchall() account_res = cr.dictfetchall()
return account_res return account_res
# for row in cr.dictfetchall():
# balance = 0
# for line in move_lines.get(row['account_id']):
# balance += round(line['debit'],2) - round(line['credit'],2)
# row['balance'] += round(balance,2)
# row['m_id'] = row['account_id']
# move_lines[row.pop('account_id')].append(row)
#
# # Calculate the debit, credit and balance for Accounts
# account_res = []
# for account in accounts:
# currency = account.currency_id and account.currency_id or account.company_id.currency_id
# res = dict((fn, 0.0) for fn in ['credit', 'debit', 'balance'])
# res['code'] = account.code
# res['name'] = account.name
# res['id'] = account.id
# res['move_lines'] = move_lines[account.id]
# for line in res.get('move_lines'):
# res['debit'] += round(line['debit'],2)
# res['credit'] += round(line['credit'],2)
# res['balance'] = round(line['balance'],2)
# if display_account == 'all':
# account_res.append(res)
# if display_account == 'movement' and res.get('move_lines'):
# account_res.append(res)
# if display_account == 'not_zero' and not currency.is_zero(
# res['balance']):
# account_res.append(res)
#
# return account_res
@api.model @api.model
def _get_currency(self): def _get_currency(self):
journal = self.env['account.journal'].browse( journal = self.env['account.journal'].browse(
@ -419,29 +444,36 @@ class GeneralView(models.TransientModel):
lang = 'en_US' lang = 'en_US'
lang = lang.replace("_", '-') lang = lang.replace("_", '-')
currency_array = [self.env.company.currency_id.symbol, currency_array = [self.env.company.currency_id.symbol,
self.env.company.currency_id.position,lang] self.env.company.currency_id.position, lang]
return currency_array return currency_array
def get_accounts_line(self, account_id, title): def get_accounts_line(self, account_id, title):
trans_title = self.env['ir.translation'].search([('value', '=', title), ('module', '=', 'dynamic_accounts_report')], limit=1).src trans_title = self.env['ir.translation'].search(
[('value', '=', title), ('module', '=', 'dynamic_accounts_report')],
limit=1).src
company_id = self.env.companies.ids company_id = self.env.companies.ids
if self.journal_ids: if self.journal_ids:
journals = self.journal_ids journals = self.journal_ids
else: else:
journals = self.env['account.journal'].search([('company_id', 'in', company_id)]) journals = self.env['account.journal'].search(
[('company_id', 'in', company_id)])
if title == 'General Ledger' or trans_title == 'General Ledger': if title == 'General Ledger' or trans_title == 'General Ledger':
if self.journal_ids: if self.journal_ids:
journals = self.journal_ids journals = self.journal_ids
else: else:
journals = self.env['account.journal'].search([('company_id', 'in', company_id)]) journals = self.env['account.journal'].search(
[('company_id', 'in', company_id)])
if title == 'Bank Book' or trans_title == 'Bank Book': if title == 'Bank Book' or trans_title == 'Bank Book':
journals = self.env['account.journal'].search([('type', '=', 'bank'), ('company_id', 'in', company_id)]) journals = self.env['account.journal'].search(
[('type', '=', 'bank'), ('company_id', 'in', company_id)])
if title == 'Cash Book' or trans_title == 'Cash Book': if title == 'Cash Book' or trans_title == 'Cash Book':
journals = self.env['account.journal'].search([('type', '=', 'cash'), ('company_id', 'in', company_id)]) journals = self.env['account.journal'].search(
[('type', '=', 'cash'), ('company_id', 'in', company_id)])
if account_id: if account_id:
accounts = self.env['account.account'].search([('id', '=', account_id)]) accounts = self.env['account.account'].search(
[('id', '=', account_id)])
else: else:
company_id = self.env.companies company_id = self.env.companies
company_domain = [('company_id', 'in', company_id.ids)] company_domain = [('company_id', 'in', company_id.ids)]
@ -473,13 +505,16 @@ class GeneralView(models.TransientModel):
if self.date_from: if self.date_from:
new_filter += " AND l.date < '%s'" % self.date_from new_filter += " AND l.date < '%s'" % self.date_from
if journals: if journals:
new_filter += ' AND j.id IN %s' % str(tuple(journals.ids) + tuple([0])) new_filter += ' AND j.id IN %s' % str(
tuple(journals.ids) + tuple([0]))
if accounts: if accounts:
WHERE = "WHERE l.account_id IN %s" % str(tuple(accounts.ids) + tuple([0])) WHERE = "WHERE l.account_id IN %s" % str(
tuple(accounts.ids) + tuple([0]))
else: else:
WHERE = "WHERE l.account_id IN %s" WHERE = "WHERE l.account_id IN %s"
if self.analytic_ids: if self.analytic_ids:
WHERE += ' AND anl.id IN %s' % str(tuple(self.analytic_ids.ids) + tuple([0])) WHERE += ' AND anl.id IN %s' % str(
tuple(self.analytic_ids.ids) + tuple([0]))
if self.analytic_tag_ids: if self.analytic_tag_ids:
WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str( WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str(
tuple(self.analytic_tags.ids) + tuple([0])) tuple(self.analytic_tags.ids) + tuple([0]))
@ -513,7 +548,8 @@ class GeneralView(models.TransientModel):
if where_clause.strip(): if where_clause.strip():
wheres.append(where_clause.strip()) wheres.append(where_clause.strip())
final_filters = " AND ".join(wheres) final_filters = " AND ".join(wheres)
final_filters = final_filters.replace('account_move_line__move_id', 'm').replace( final_filters = final_filters.replace('account_move_line__move_id',
'm').replace(
'account_move_line', 'l') 'account_move_line', 'l')
new_final_filter = final_filters new_final_filter = final_filters
if self.target_move == 'posted': if self.target_move == 'posted':
@ -526,13 +562,16 @@ class GeneralView(models.TransientModel):
new_final_filter += " AND l.date <= '%s'" % self.date_to new_final_filter += " AND l.date <= '%s'" % self.date_to
if journals: if journals:
new_final_filter += ' AND j.id IN %s' % str(tuple(journals.ids) + tuple([0])) new_final_filter += ' AND j.id IN %s' % str(
tuple(journals.ids) + tuple([0]))
if accounts: if accounts:
WHERE = "WHERE l.account_id IN %s" % str(tuple(accounts.ids) + tuple([0])) WHERE = "WHERE l.account_id IN %s" % str(
tuple(accounts.ids) + tuple([0]))
else: else:
WHERE = "WHERE l.account_id IN %s" WHERE = "WHERE l.account_id IN %s"
if self.analytic_ids: if self.analytic_ids:
WHERE += ' AND anl.id IN %s' % str(tuple(self.analytics.ids) + tuple([0])) WHERE += ' AND anl.id IN %s' % str(
tuple(self.analytics.ids) + tuple([0]))
if self.analytic_tag_ids: if self.analytic_tag_ids:
WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str( WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str(
@ -550,29 +589,11 @@ class GeneralView(models.TransientModel):
LEFT JOIN account_analytic_tag_account_move_line_rel anltag ON (anltag.account_move_line_id=l.id) LEFT JOIN account_analytic_tag_account_move_line_rel anltag ON (anltag.account_move_line_id=l.id)
JOIN account_journal j ON (l.journal_id=j.id)\ JOIN account_journal j ON (l.journal_id=j.id)\
JOIN account_account a ON (l.account_id = a.id) ''' JOIN account_account a ON (l.account_id = a.id) '''
+ WHERE + new_final_filter + ''' GROUP BY l.id, m.id, l.account_id, l.date, j.code, l.currency_id, l.amount_currency, l.ref, l.name, m.name, c.symbol, c.position, p.name ORDER BY l.date''' ) + WHERE + new_final_filter + ''' GROUP BY l.id, m.id, l.account_id, l.date, j.code, l.currency_id, l.amount_currency, l.ref, l.name, m.name, c.symbol, c.position, p.name ORDER BY l.date''')
# sql = ('''SELECT l.account_id AS account_id, a.code AS code, a.name AS name, COALESCE(SUM(l.debit),0) AS debit, COALESCE(SUM(l.credit),0) AS credit, COALESCE(SUM(l.balance),0) AS balance
#
# FROM account_move_line l\
# JOIN account_move m ON (l.move_id=m.id)\
# LEFT JOIN res_currency c ON (l.currency_id=c.id)\
# LEFT JOIN res_partner p ON (l.partner_id=p.id)\
# LEFT JOIN account_analytic_account anl ON (l.analytic_account_id=anl.id)
# LEFT JOIN account_account_tag_account_move_line_rel acc ON (acc.account_move_line_id=l.id)
# LEFT JOIN account_analytic_tag_account_move_line_rel anltag ON (anltag.account_move_line_id=l.id)
# JOIN account_journal j ON (l.journal_id=j.id)\
# JOIN account_account a ON (l.account_id = a.id) '''
# + WHERE + new_final_filter + ''' GROUP BY l.account_id, a.code, a.name''')
# if self.account_ids:
# params = tuple(where_params)
# else:
# params = (tuple(accounts.ids),) + tuple(where_params)
params = tuple(where_params) params = tuple(where_params)
cr.execute(sql, params) cr.execute(sql, params)
account_ress = cr.dictfetchall() account_ress = cr.dictfetchall()
i=0 i = 0
# Calculate the debit, credit and balance for Accounts # Calculate the debit, credit and balance for Accounts
account_res = [] account_res = []
for account in accounts: for account in accounts:
@ -591,7 +612,7 @@ class GeneralView(models.TransientModel):
'currency': currency, 'currency': currency,
} }
def get_dynamic_xlsx_report(self, data, response ,report_data, dfr_data): def get_dynamic_xlsx_report(self, data, response, report_data, dfr_data):
report_data_main = json.loads(report_data) report_data_main = json.loads(report_data)
output = io.BytesIO() output = io.BytesIO()
name_data = json.loads(dfr_data) name_data = json.loads(dfr_data)
@ -605,16 +626,21 @@ class GeneralView(models.TransientModel):
'border': 1, 'border': 1,
'border_color': 'black'}) 'border_color': 'black'})
txt = workbook.add_format({'font_size': '10px', 'border': 1}) txt = workbook.add_format({'font_size': '10px', 'border': 1})
txt_l = workbook.add_format({'font_size': '10px', 'border': 1, 'bold': True}) txt_l = workbook.add_format(
sheet.merge_range('A2:J3', filters.get('company_name') + ':' + name_data.get('name'), head) {'font_size': '10px', 'border': 1, 'bold': True})
sheet.merge_range('A2:J3',
filters.get('company_name') + ':' + name_data.get(
'name'), head)
date_head = workbook.add_format({'align': 'center', 'bold': True, date_head = workbook.add_format({'align': 'center', 'bold': True,
'font_size': '10px'}) 'font_size': '10px'})
date_style = workbook.add_format({'align': 'center', date_style = workbook.add_format({'align': 'center',
'font_size': '10px'}) 'font_size': '10px'})
if filters.get('date_from'): if filters.get('date_from'):
sheet.merge_range('B4:C4', 'From: ' + filters.get('date_from'), date_head) sheet.merge_range('B4:C4', 'From: ' + filters.get('date_from'),
date_head)
if filters.get('date_to'): if filters.get('date_to'):
sheet.merge_range('H4:I4', 'To: ' + filters.get('date_to'), date_head) sheet.merge_range('H4:I4', 'To: ' + filters.get('date_to'),
date_head)
# sheet.merge_range('A5:J6', 'Journals: ' + ', '.join( # sheet.merge_range('A5:J6', 'Journals: ' + ', '.join(
# [lt or '' for lt in filters['journals']]) + ' Target Moves: ' + filters.get('target_move'), date_head) # [lt or '' for lt in filters['journals']]) + ' Target Moves: ' + filters.get('target_move'), date_head)
@ -626,10 +652,10 @@ class GeneralView(models.TransientModel):
[lt or '' for lt in [lt or '' for lt in
filters['analytic_tags']]) + ' Analytic: ' + ', '.join( filters['analytic_tags']]) + ' Analytic: ' + ', '.join(
[at or '' for at in [at or '' for at in
filters['analytics']]) + ' Target Moves : ' + filters.get('target_move'), filters['analytics']]) + ' Target Moves : ' + filters.get(
'target_move'),
date_head) date_head)
sheet.write('A8', 'Code', sub_heading) sheet.write('A8', 'Code', sub_heading)
sheet.write('B8', 'Amount', sub_heading) sheet.write('B8', 'Amount', sub_heading)
sheet.write('C8', 'Date', sub_heading) sheet.write('C8', 'Date', sub_heading)
@ -653,7 +679,6 @@ class GeneralView(models.TransientModel):
sheet.set_column(8, 7, 26) sheet.set_column(8, 7, 26)
sheet.set_column(8, 8, 15) sheet.set_column(8, 8, 15)
sheet.set_column(8, 9, 15) sheet.set_column(8, 9, 15)
for rec_data in report_data_main: for rec_data in report_data_main:
row += 1 row += 1
@ -668,20 +693,20 @@ class GeneralView(models.TransientModel):
sheet.write(row + 1, col + 7, rec_data['debit'], txt) sheet.write(row + 1, col + 7, rec_data['debit'], txt)
sheet.write(row + 1, col + 8, rec_data['credit'], txt) sheet.write(row + 1, col + 8, rec_data['credit'], txt)
sheet.write(row + 1, col + 9, rec_data['balance'], txt) sheet.write(row + 1, col + 9, rec_data['balance'], txt)
for line_data in rec_data['move_lines']: if rec_data.get('move_lines'):
row += 1 for line_data in rec_data['move_lines']:
sheet.write(row + 1, col, '', txt) row += 1
sheet.write(row + 1, col + 1, '', txt) sheet.write(row + 1, col, '', txt)
sheet.write(row + 1, col + 2, line_data.get('ldate'), txt) sheet.write(row + 1, col + 1, '', txt)
sheet.write(row + 1, col + 3, line_data.get('lcode'), txt) sheet.write(row + 1, col + 2, line_data.get('ldate'), txt)
sheet.write(row + 1, col + 4, line_data.get('partner_name'), txt) sheet.write(row + 1, col + 3, line_data.get('lcode'), txt)
sheet.write(row + 1, col + 5, line_data.get('move_name'), txt) sheet.write(row + 1, col + 4, line_data.get('partner_name'),
sheet.write(row + 1, col + 6, line_data.get('lname'), txt) txt)
sheet.write(row + 1, col + 7, line_data.get('debit'), txt) sheet.write(row + 1, col + 5, line_data.get('move_name'), txt)
sheet.write(row + 1, col + 8, line_data.get('credit'), txt) sheet.write(row + 1, col + 6, line_data.get('lname'), txt)
sheet.write(row + 1, col + 9, line_data.get('balance'), txt) sheet.write(row + 1, col + 7, line_data.get('debit'), txt)
sheet.write(row + 1, col + 8, line_data.get('credit'), txt)
sheet.write(row + 1, col + 9, line_data.get('balance'), txt)
workbook.close() workbook.close()
output.seek(0) output.seek(0)

100
dynamic_accounts_report/wizard/partner_leadger.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import time import time
from odoo import fields, models, api, _ from odoo import fields, models, api, _
@ -35,8 +56,10 @@ class PartnerView(models.TransientModel):
('unreconciled', 'Unreconciled Only')], ('unreconciled', 'Unreconciled Only')],
string='Reconcile Type', default='unreconciled') string='Reconcile Type', default='unreconciled')
account_type_ids = fields.Many2many('account.account.type',string='Account Type', account_type_ids = fields.Many2many('account.account.type',
domain=[('type', 'in', ('receivable', 'payable'))]) string='Account Type',
domain=[('type', 'in',
('receivable', 'payable'))])
@api.model @api.model
def view_report(self, option): def view_report(self, option):
@ -55,11 +78,11 @@ class PartnerView(models.TransientModel):
if r.date_from: if r.date_from:
data.update({ data.update({
'date_from':r.date_from, 'date_from': r.date_from,
}) })
if r.date_to: if r.date_to:
data.update({ data.update({
'date_to':r.date_to, 'date_to': r.date_to,
}) })
filters = self.get_filter(option) filters = self.get_filter(option)
@ -83,11 +106,13 @@ class PartnerView(models.TransientModel):
filters = {} filters = {}
if data.get('journal_ids'): if data.get('journal_ids'):
filters['journals'] = self.env['account.journal'].browse(data.get('journal_ids')).mapped('code') filters['journals'] = self.env['account.journal'].browse(
data.get('journal_ids')).mapped('code')
else: else:
filters['journals'] = ['All'] filters['journals'] = ['All']
if data.get('account_ids', []): if data.get('account_ids', []):
filters['accounts'] = self.env['account.account'].browse(data.get('account_ids', [])).mapped('code') filters['accounts'] = self.env['account.account'].browse(
data.get('account_ids', [])).mapped('code')
else: else:
filters['accounts'] = ['All Payable and Receivable'] filters['accounts'] = ['All Payable and Receivable']
if data.get('target_move'): if data.get('target_move'):
@ -113,7 +138,8 @@ class PartnerView(models.TransientModel):
filters['reconciled'] = 'Unreconciled' filters['reconciled'] = 'Unreconciled'
if data.get('account_type', []): if data.get('account_type', []):
filters['account_type'] = self.env['account.account.type'].browse(data.get('account_type', [])).mapped('name') filters['account_type'] = self.env['account.account.type'].browse(
data.get('account_type', [])).mapped('name')
else: else:
filters['account_type'] = ['Receivable and Payable'] filters['account_type'] = ['Receivable and Payable']
@ -134,16 +160,18 @@ class PartnerView(models.TransientModel):
default_filters = {} default_filters = {}
company_id = self.env.companies.ids company_id = self.env.companies.ids
company_domain = [('company_id', 'in', company_id)] company_domain = [('company_id', 'in', company_id)]
journal_ids = r.journal_ids if r.journal_ids else self.env['account.journal'].search(company_domain, order="company_id, name") journal_ids = r.journal_ids if r.journal_ids else self.env[
accounts_ids = self.account_ids if self.account_ids else self.env['account.account'].search(company_domain, order="company_id, name") 'account.journal'].search(company_domain, order="company_id, name")
accounts_ids = self.account_ids if self.account_ids else self.env[
'account.account'].search(company_domain, order="company_id, name")
partner = r.partner_ids if r.partner_ids else self.env[ partner = r.partner_ids if r.partner_ids else self.env[
'res.partner'].search([]) 'res.partner'].search([])
categories = self.partner_category_ids if self.partner_category_ids \ categories = self.partner_category_ids if self.partner_category_ids \
else self.env['res.partner.category'].search([]) else self.env['res.partner.category'].search([])
account_types = r.account_type_ids if r.account_type_ids \ account_types = r.account_type_ids if r.account_type_ids \
else self.env['account.account.type'].search([('type', 'in', ('receivable', 'payable'))]) else self.env['account.account.type'].search(
[('type', 'in', ('receivable', 'payable'))])
journals = [] journals = []
o_company = False o_company = False
@ -162,8 +190,6 @@ class PartnerView(models.TransientModel):
o_company = j.company_id o_company = j.company_id
accounts.append((j.id, j.name)) accounts.append((j.id, j.name))
filter_dict = { filter_dict = {
'journal_ids': r.journal_ids.ids, 'journal_ids': r.journal_ids.ids,
'account_ids': r.account_ids.ids, 'account_ids': r.account_ids.ids,
@ -192,11 +218,13 @@ class PartnerView(models.TransientModel):
display_account = data['display_account'] display_account = data['display_account']
init_balance = True init_balance = True
company_id = self.env.companies.ids company_id = self.env.companies.ids
accounts = self.env['account.account'].search([('user_type_id.type', 'in', ('receivable', 'payable')), accounts = self.env['account.account'].search(
('company_id', 'in', company_id)]) [('user_type_id.type', 'in', ('receivable', 'payable')),
('company_id', 'in', company_id)])
if data['account_type']: if data['account_type']:
accounts = self.env['account.account'].search( accounts = self.env['account.account'].search(
[('user_type_id.id', 'in', data['account_type'].ids),('company_id', 'in', company_id)]) [('user_type_id.id', 'in', data['account_type'].ids),
('company_id', 'in', company_id)])
partners = self.env['res.partner'].search([]) partners = self.env['res.partner'].search([])
@ -205,17 +233,18 @@ class PartnerView(models.TransientModel):
[('category_id', 'in', data['partner_tags'].ids)]) [('category_id', 'in', data['partner_tags'].ids)])
if not accounts: if not accounts:
raise UserError(_("No Accounts Found! Please Add One")) raise UserError(_("No Accounts Found! Please Add One"))
partner_res = self._get_partners(partners,accounts, init_balance, display_account, data) partner_res = self._get_partners(partners, accounts, init_balance,
display_account, data)
debit_total = 0 debit_total = 0
debit_total = sum(x['debit'] for x in partner_res) debit_total = sum(x['debit'] for x in partner_res)
credit_total = sum(x['credit'] for x in partner_res) credit_total = sum(x['credit'] for x in partner_res)
debit_balance = round(debit_total,2) - round(credit_total,2) debit_balance = round(debit_total, 2) - round(credit_total, 2)
return { return {
'doc_ids': self.ids, 'doc_ids': self.ids,
'debit_total': debit_total, 'debit_total': debit_total,
'credit_total': credit_total, 'credit_total': credit_total,
'debit_balance':debit_balance, 'debit_balance': debit_balance,
'docs': docs, 'docs': docs,
'time': time, 'time': time,
'Partners': partner_res, 'Partners': partner_res,
@ -235,7 +264,8 @@ class PartnerView(models.TransientModel):
if not vals.get('journal_ids'): if not vals.get('journal_ids'):
vals.update({'journal_ids': [(5,)]}) vals.update({'journal_ids': [(5,)]})
if vals.get('account_ids'): if vals.get('account_ids'):
vals.update({'account_ids': [(4, j) for j in vals.get('account_ids')]}) vals.update(
{'account_ids': [(4, j) for j in vals.get('account_ids')]})
if not vals.get('account_ids'): if not vals.get('account_ids'):
vals.update({'account_ids': [(5,)]}) vals.update({'account_ids': [(5,)]})
if vals.get('partner_ids'): if vals.get('partner_ids'):
@ -251,14 +281,16 @@ class PartnerView(models.TransientModel):
if vals.get('account_type-ids'): if vals.get('account_type-ids'):
vals.update( vals.update(
{'account_type_ids': [(4, j) for j in vals.get('account_type_ids')]}) {'account_type_ids': [(4, j) for j in
vals.get('account_type_ids')]})
if not vals.get('account_type_ids'): if not vals.get('account_type_ids'):
vals.update({'account_type_ids': [(5,)]}) vals.update({'account_type_ids': [(5,)]})
res = super(PartnerView, self).write(vals) res = super(PartnerView, self).write(vals)
return res return res
def _get_partners(self, partners, accounts, init_balance, display_account, data): def _get_partners(self, partners, accounts, init_balance, display_account,
data):
cr = self.env.cr cr = self.env.cr
move_line = self.env['account.move.line'] move_line = self.env['account.move.line']
@ -270,7 +302,8 @@ class PartnerView(models.TransientModel):
if where_clause.strip(): if where_clause.strip():
wheres.append(where_clause.strip()) wheres.append(where_clause.strip())
final_filters = " AND ".join(wheres) final_filters = " AND ".join(wheres)
final_filters = final_filters.replace('account_move_line__move_id', 'm').replace( final_filters = final_filters.replace('account_move_line__move_id',
'm').replace(
'account_move_line', 'l') 'account_move_line', 'l')
new_final_filter = final_filters new_final_filter = final_filters
if data['target_move'] == 'posted': if data['target_move'] == 'posted':
@ -283,10 +316,12 @@ class PartnerView(models.TransientModel):
new_final_filter += " AND l.date <= '%s'" % data.get('date_to') new_final_filter += " AND l.date <= '%s'" % data.get('date_to')
if data['journals']: if data['journals']:
new_final_filter += ' AND j.id IN %s' % str(tuple(data['journals'].ids) + tuple([0])) new_final_filter += ' AND j.id IN %s' % str(
tuple(data['journals'].ids) + tuple([0]))
if data.get('accounts'): if data.get('accounts'):
WHERE = "WHERE l.account_id IN %s" % str(tuple(data.get('accounts').ids) + tuple([0])) WHERE = "WHERE l.account_id IN %s" % str(
tuple(data.get('accounts').ids) + tuple([0]))
else: else:
WHERE = "WHERE l.account_id IN %s" WHERE = "WHERE l.account_id IN %s"
@ -311,23 +346,28 @@ class PartnerView(models.TransientModel):
LEFT JOIN res_partner p ON (l.partner_id=p.id)\ LEFT JOIN res_partner p ON (l.partner_id=p.id)\
JOIN account_journal j ON (l.journal_id=j.id)\ JOIN account_journal j ON (l.journal_id=j.id)\
JOIN account_account acc ON (l.account_id = acc.id) ''' JOIN account_account acc ON (l.account_id = acc.id) '''
+ WHERE + new_final_filter + ''' GROUP BY l.id, m.id, l.account_id, l.date, j.code, l.currency_id, l.amount_currency, l.ref, l.name, m.name, c.symbol, c.position, p.name ORDER BY l.date''' ) + WHERE + new_final_filter + ''' GROUP BY l.id, m.id, l.account_id, l.date, j.code, l.currency_id, l.amount_currency, l.ref, l.name, m.name, c.symbol, c.position, p.name ORDER BY l.date''')
if data.get('accounts'): if data.get('accounts'):
params = tuple(where_params) params = tuple(where_params)
else: else:
params = (tuple(accounts.ids),) + tuple(where_params) params = (tuple(accounts.ids),) + tuple(where_params)
cr.execute(sql, params) cr.execute(sql, params)
account_list = {x.id: {'name': x.name, 'code': x.code} for x in accounts} account_list = {x.id: {'name': x.name, 'code': x.code} for x in
accounts}
for row in cr.dictfetchall(): for row in cr.dictfetchall():
balance = 0 balance = 0
if row['partner_id'] in move_lines: if row['partner_id'] in move_lines:
for line in move_lines.get(row['partner_id']): for line in move_lines.get(row['partner_id']):
balance += round(line['debit'],2) - round(line['credit'],2) balance += round(line['debit'], 2) - round(line['credit'],
2)
row['balance'] += (round(balance, 2)) row['balance'] += (round(balance, 2))
row['m_id'] = row['account_id'] row['m_id'] = row['account_id']
row['account_name'] = account_list[row['account_id']]['name'] + "(" +account_list[row['account_id']]['code'] + ")" row['account_name'] = account_list[row['account_id']][
'name'] + "(" + \
account_list[row['account_id']][
'code'] + ")"
move_lines[row.pop('partner_id')].append(row) move_lines[row.pop('partner_id')].append(row)
partner_res = [] partner_res = []
@ -394,7 +434,7 @@ class PartnerView(models.TransientModel):
'Target Moves: ' + filters.get('target_move'), 'Target Moves: ' + filters.get('target_move'),
date_head) date_head)
sheet.merge_range('C4:D4', 'Account Type: ' + ', ' .join( sheet.merge_range('C4:D4', 'Account Type: ' + ', '.join(
[lt or '' for lt in [lt or '' for lt in
filters['account_type']]), filters['account_type']]),
date_head) date_head)

21
dynamic_accounts_report/wizard/trial_balance.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
import time import time
from odoo import fields, models, api, _ from odoo import fields, models, api, _

Loading…
Cancel
Save