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. 7
      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. 32
      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. 275
      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 -*-
#############################################################################
#
# 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 wizard

9
dynamic_accounts_report/__manifest__.py

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

20
dynamic_accounts_report/controllers/__init__.py

@ -1,3 +1,23 @@
# -*- 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

32
dynamic_accounts_report/controllers/controllers.py

@ -1,4 +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 json
from odoo import http
@ -8,8 +28,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, token, 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, token, report_data,
report_name, dfr_data, **kw):
uid = request.session.uid
report_obj = request.env[model].with_user(uid)
@ -21,10 +43,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:

7
dynamic_accounts_report/doc/RELEASE_NOTES.md

@ -45,4 +45,9 @@
#### 16.04.2022
#### Version 14.0.1.2.7
#### 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 general_ledger
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, _

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, _
@ -9,8 +30,9 @@ class GeneralLedger(models.AbstractModel):
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'],
'company': self.env.company,
})
data.update(
{'account_data': data.get('report_data')['report_lines'],
'Filters': data.get('report_data')['filters'],
'company': self.env.company,
})
return data

32
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, _
@ -10,8 +31,9 @@ class DayBook(models.AbstractModel):
if self.env.context.get('daybook_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,
})
return data
data.update(
{'account_data': data.get('report_data')['report_lines'],
'Filters': data.get('report_data')['filters'],
'company': self.env.company,
})
return data

20
dynamic_accounts_report/report/financial_reports.py

@ -1,4 +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, _

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, _
@ -10,11 +31,12 @@ class GeneralLedger(models.AbstractModel):
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'],
'company': self.env.company,
})
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'],
'company': self.env.company,
})
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, _

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, _

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
],
}).then(function(data) {
console.log(data,"de")
var action = {
'type': 'ir.actions.report',
'report_type': 'qweb-pdf',
@ -196,6 +197,7 @@ odoo.define('dynamic_cash_flow_statements.general_ledger', function (require) {
[self.wizard_id], action_title
],
}).then(function(data) {
console.log(data['report_lines'])
var action = {
'type': 'ir_actions_dynamic_xlsx_download',
'data': {
@ -265,6 +267,7 @@ odoo.define('dynamic_cash_flow_statements.general_ledger', function (require) {
event.preventDefault();
var self = this;
var account_id = $(event.currentTarget).data('account-id');
console.log(account_id,"acc")
var offset = 0;
var td = $(event.currentTarget).next('tr').find('td');
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]
],
}).then(function(data) {
console.log(data['report_lines'])
var action = {
'type': 'ir_actions_dynamic_xlsx_download',
'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 trial_balance
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
from datetime import datetime
@ -37,6 +58,7 @@ class AgeingView(models.TransientModel):
@api.model
def view_report(self, option):
print(self,option)
r = self.env['account.partner.ageing'].search([('id', '=', option[0])])
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
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
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
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
from datetime import date
from datetime import timedelta, datetime

275
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
from odoo import fields, models, api, _
import io
import json
from odoo.exceptions import AccessError, UserError, AccessDenied
try:
from odoo.tools.misc import xlsxwriter
except ImportError:
@ -22,12 +44,14 @@ class GeneralView(models.TransientModel):
"account.account",
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(
"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(
[('all', 'All'), ('movement', 'With movements'),
@ -46,24 +70,30 @@ class GeneralView(models.TransientModel):
r = self.env['account.general.ledger'].search([('id', '=', option[0])])
self = r
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
if r.journal_ids:
journals = r.journal_ids
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 r.journal_ids:
journals = r.journal_ids
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
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
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
r.write({
'titles': new_title,
@ -106,11 +136,13 @@ class GeneralView(models.TransientModel):
data = self.get_filter_data(option)
filters = {}
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:
filters['journals'] = ['All']
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:
filters['accounts'] = ['All']
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.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)
analytic_tags = r.analytic_tag_ids if r.analytic_tag_ids else self.env[
'account.analytic.tag'].search([])
journal_ids = r.journal_ids if r.journal_ids else self.env['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")
journal_ids = r.journal_ids if r.journal_ids else self.env[
'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")
journals = []
o_company = False
for j in journal_ids:
@ -178,8 +212,6 @@ class GeneralView(models.TransientModel):
o_company = j.company_id
accounts.append((j.id, j.name))
filter_dict = {
'journal_ids': r.journal_ids.ids,
'analytic_ids': r.analytic_ids.ids,
@ -196,14 +228,14 @@ class GeneralView(models.TransientModel):
'accounts_list': accounts,
'account_tag_list': [(a.id, a.name) for a in account_tags],
'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')),
}
filter_dict.update(default_filters)
return filter_dict
def _get_report_values(self, data):
docs = data['model']
display_account = data['display_account']
init_balance = True
@ -216,16 +248,33 @@ class GeneralView(models.TransientModel):
accounts = self.env['account.account'].search(company_domain)
if not accounts:
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 = sum(x['debit'] 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 {
'doc_ids': self.ids,
'debit_total': debit_total,
'credit_total': credit_total,
'debit_balance':debit_balance,
'debit_balance': debit_balance,
'docs': docs,
'time': time,
'Accounts': account_res,
@ -245,26 +294,29 @@ class GeneralView(models.TransientModel):
if vals.get('journal_ids') == []:
vals.update({'journal_ids': [(5,)]})
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') == []:
vals.update({'account_ids': [(5,)]})
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') == []:
vals.update({'account_tag_ids': [(5,)]})
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') == []:
vals.update({'analytic_ids': [(5,)]})
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') == []:
vals.update({'analytic_tag_ids': [(5,)]})
res = super(GeneralView, self).write(vals)
return res
def _get_accounts(self, accounts, init_balance, display_account, data):
cr = self.env.cr
MoveLine = self.env['account.move.line']
move_lines = {x: [] for x in accounts.ids}
@ -289,18 +341,20 @@ class GeneralView(models.TransientModel):
if data.get('date_from'):
new_filter += " AND l.date < '%s'" % data.get('date_from')
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'):
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:
WHERE = "WHERE l.account_id IN %s"
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'):
WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str(
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,\
'' AS move_name, '' AS mmove_id, '' AS currency_code,\
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_tag_account_move_line_rel anltag ON (anltag.account_move_line_id=l.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'):
params = tuple(init_where_params)
else:
@ -330,7 +384,8 @@ class GeneralView(models.TransientModel):
if where_clause.strip():
wheres.append(where_clause.strip())
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')
new_final_filter = final_filters
if data['target_move'] == 'posted':
@ -343,21 +398,23 @@ class GeneralView(models.TransientModel):
new_final_filter += " AND l.date <= '%s'" % data.get('date_to')
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'):
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:
WHERE = "WHERE l.account_id IN %s"
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'):
WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str(
tuple(data.get('analytic_tags').ids) + tuple([0]))
# 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\
JOIN account_move m ON (l.move_id=m.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)
cr.execute(sql, params)
account_res = cr.dictfetchall()
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
def _get_currency(self):
journal = self.env['account.journal'].browse(
@ -419,29 +444,36 @@ class GeneralView(models.TransientModel):
lang = 'en_US'
lang = lang.replace("_", '-')
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
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
if self.journal_ids:
journals = self.journal_ids
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 self.journal_ids:
journals = self.journal_ids
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':
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':
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:
accounts = self.env['account.account'].search([('id', '=', account_id)])
accounts = self.env['account.account'].search(
[('id', '=', account_id)])
else:
company_id = self.env.companies
company_domain = [('company_id', 'in', company_id.ids)]
@ -473,13 +505,16 @@ class GeneralView(models.TransientModel):
if self.date_from:
new_filter += " AND l.date < '%s'" % self.date_from
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:
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:
WHERE = "WHERE l.account_id IN %s"
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:
WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str(
tuple(self.analytic_tags.ids) + tuple([0]))
@ -513,7 +548,8 @@ class GeneralView(models.TransientModel):
if where_clause.strip():
wheres.append(where_clause.strip())
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')
new_final_filter = final_filters
if self.target_move == 'posted':
@ -526,13 +562,16 @@ class GeneralView(models.TransientModel):
new_final_filter += " AND l.date <= '%s'" % self.date_to
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:
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:
WHERE = "WHERE l.account_id IN %s"
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:
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)
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.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)
+ 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''')
params = tuple(where_params)
cr.execute(sql, params)
account_ress = cr.dictfetchall()
i=0
i = 0
# Calculate the debit, credit and balance for Accounts
account_res = []
for account in accounts:
@ -591,7 +612,7 @@ class GeneralView(models.TransientModel):
'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)
output = io.BytesIO()
name_data = json.loads(dfr_data)
@ -605,16 +626,21 @@ class GeneralView(models.TransientModel):
'border': 1,
'border_color': 'black'})
txt = workbook.add_format({'font_size': '10px', 'border': 1})
txt_l = workbook.add_format({'font_size': '10px', 'border': 1, 'bold': True})
sheet.merge_range('A2:J3', filters.get('company_name') + ':' + name_data.get('name'), head)
txt_l = workbook.add_format(
{'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,
'font_size': '10px'})
date_style = workbook.add_format({'align': 'center',
'font_size': '10px'})
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'):
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(
# [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
filters['analytic_tags']]) + ' Analytic: ' + ', '.join(
[at or '' for at in
filters['analytics']]) + ' Target Moves : ' + filters.get('target_move'),
filters['analytics']]) + ' Target Moves : ' + filters.get(
'target_move'),
date_head)
sheet.write('A8', 'Code', sub_heading)
sheet.write('B8', 'Amount', 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, 8, 15)
sheet.set_column(8, 9, 15)
for rec_data in report_data_main:
row += 1
@ -668,22 +693,22 @@ class GeneralView(models.TransientModel):
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 + 9, rec_data['balance'], txt)
for line_data in rec_data['move_lines']:
row += 1
sheet.write(row + 1, col, '', txt)
sheet.write(row + 1, col + 1, '', txt)
sheet.write(row + 1, col + 2, line_data.get('ldate'), txt)
sheet.write(row + 1, col + 3, line_data.get('lcode'), txt)
sheet.write(row + 1, col + 4, line_data.get('partner_name'), txt)
sheet.write(row + 1, col + 5, line_data.get('move_name'), txt)
sheet.write(row + 1, col + 6, line_data.get('lname'), 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)
if rec_data.get('move_lines'):
for line_data in rec_data['move_lines']:
row += 1
sheet.write(row + 1, col, '', txt)
sheet.write(row + 1, col + 1, '', txt)
sheet.write(row + 1, col + 2, line_data.get('ldate'), txt)
sheet.write(row + 1, col + 3, line_data.get('lcode'), txt)
sheet.write(row + 1, col + 4, line_data.get('partner_name'),
txt)
sheet.write(row + 1, col + 5, line_data.get('move_name'), txt)
sheet.write(row + 1, col + 6, line_data.get('lname'), 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()
output.seek(0)
response.stream.write(output.read())
output.close()
output.close()

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
from odoo import fields, models, api, _
@ -35,8 +56,10 @@ class PartnerView(models.TransientModel):
('unreconciled', 'Unreconciled Only')],
string='Reconcile Type', default='unreconciled')
account_type_ids = fields.Many2many('account.account.type',string='Account Type',
domain=[('type', 'in', ('receivable', 'payable'))])
account_type_ids = fields.Many2many('account.account.type',
string='Account Type',
domain=[('type', 'in',
('receivable', 'payable'))])
@api.model
def view_report(self, option):
@ -55,11 +78,11 @@ class PartnerView(models.TransientModel):
if r.date_from:
data.update({
'date_from':r.date_from,
'date_from': r.date_from,
})
if r.date_to:
data.update({
'date_to':r.date_to,
'date_to': r.date_to,
})
filters = self.get_filter(option)
@ -83,11 +106,13 @@ class PartnerView(models.TransientModel):
filters = {}
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:
filters['journals'] = ['All']
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:
filters['accounts'] = ['All Payable and Receivable']
if data.get('target_move'):
@ -113,7 +138,8 @@ class PartnerView(models.TransientModel):
filters['reconciled'] = 'Unreconciled'
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:
filters['account_type'] = ['Receivable and Payable']
@ -134,16 +160,18 @@ class PartnerView(models.TransientModel):
default_filters = {}
company_id = self.env.companies.ids
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")
accounts_ids = self.account_ids if self.account_ids else self.env['account.account'].search(company_domain, order="company_id, name")
journal_ids = r.journal_ids if r.journal_ids else self.env[
'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[
'res.partner'].search([])
categories = self.partner_category_ids if self.partner_category_ids \
else self.env['res.partner.category'].search([])
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 = []
o_company = False
@ -162,8 +190,6 @@ class PartnerView(models.TransientModel):
o_company = j.company_id
accounts.append((j.id, j.name))
filter_dict = {
'journal_ids': r.journal_ids.ids,
'account_ids': r.account_ids.ids,
@ -192,11 +218,13 @@ class PartnerView(models.TransientModel):
display_account = data['display_account']
init_balance = True
company_id = self.env.companies.ids
accounts = self.env['account.account'].search([('user_type_id.type', 'in', ('receivable', 'payable')),
('company_id', 'in', company_id)])
accounts = self.env['account.account'].search(
[('user_type_id.type', 'in', ('receivable', 'payable')),
('company_id', 'in', company_id)])
if data['account_type']:
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([])
@ -205,17 +233,18 @@ class PartnerView(models.TransientModel):
[('category_id', 'in', data['partner_tags'].ids)])
if not accounts:
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 = sum(x['debit'] 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 {
'doc_ids': self.ids,
'debit_total': debit_total,
'credit_total': credit_total,
'debit_balance':debit_balance,
'debit_balance': debit_balance,
'docs': docs,
'time': time,
'Partners': partner_res,
@ -235,7 +264,8 @@ class PartnerView(models.TransientModel):
if not vals.get('journal_ids'):
vals.update({'journal_ids': [(5,)]})
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'):
vals.update({'account_ids': [(5,)]})
if vals.get('partner_ids'):
@ -251,14 +281,16 @@ class PartnerView(models.TransientModel):
if vals.get('account_type-ids'):
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'):
vals.update({'account_type_ids': [(5,)]})
res = super(PartnerView, self).write(vals)
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
move_line = self.env['account.move.line']
@ -270,7 +302,8 @@ class PartnerView(models.TransientModel):
if where_clause.strip():
wheres.append(where_clause.strip())
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')
new_final_filter = final_filters
if data['target_move'] == 'posted':
@ -283,10 +316,12 @@ class PartnerView(models.TransientModel):
new_final_filter += " AND l.date <= '%s'" % data.get('date_to')
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'):
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:
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)\
JOIN account_journal j ON (l.journal_id=j.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'):
params = tuple(where_params)
else:
params = (tuple(accounts.ids),) + tuple(where_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():
balance = 0
if row['partner_id'] in move_lines:
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['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)
partner_res = []
@ -394,7 +434,7 @@ class PartnerView(models.TransientModel):
'Target Moves: ' + filters.get('target_move'),
date_head)
sheet.merge_range('C4:D4', 'Account Type: ' + ', ' .join(
sheet.merge_range('C4:D4', 'Account Type: ' + ', '.join(
[lt or '' for lt in
filters['account_type']]),
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
from odoo import fields, models, api, _

Loading…
Cancel
Save