Browse Source

Sep 30 : [FIX] Bug Fixed 'dynamic_accounts_report'

pull/284/head
AjmalCybro 2 years ago
parent
commit
9351703181
  1. 2
      dynamic_accounts_report/__manifest__.py
  2. 5
      dynamic_accounts_report/doc/RELEASE_NOTES.md
  3. 1
      dynamic_accounts_report/report/ageing.py
  4. 5
      dynamic_accounts_report/report/ageing.xml
  5. 1
      dynamic_accounts_report/report/cash_flow_report.py
  6. 31
      dynamic_accounts_report/report/cash_flow_report.xml
  7. 1
      dynamic_accounts_report/report/daybook.py
  8. 41
      dynamic_accounts_report/report/financial_report_template.xml
  9. 1
      dynamic_accounts_report/report/general_ledger.py
  10. 8
      dynamic_accounts_report/report/general_ledger.xml
  11. 1
      dynamic_accounts_report/report/trial_balance.py
  12. 1
      dynamic_accounts_report/report/trial_balance.xml
  13. 28
      dynamic_accounts_report/static/src/js/cash_flow.js
  14. 2
      dynamic_accounts_report/static/src/js/daybook.js
  15. 3
      dynamic_accounts_report/static/src/js/general_ledger.js
  16. 72
      dynamic_accounts_report/static/src/xml/cash_flow_view.xml
  17. 5
      dynamic_accounts_report/wizard/ageing.py
  18. 28
      dynamic_accounts_report/wizard/balance_sheet.py
  19. 235
      dynamic_accounts_report/wizard/cash_flow.py
  20. 41
      dynamic_accounts_report/wizard/general_ledger.py
  21. 6
      dynamic_accounts_report/wizard/partner_leadger.py

2
dynamic_accounts_report/__manifest__.py

@ -22,7 +22,7 @@
{ {
'name': 'Dynamic Financial Reports V16', 'name': 'Dynamic Financial Reports V16',
'version': '16.0.1.0.7', 'version': '16.0.1.0.8',
'category': 'Accounting', 'category': 'Accounting',
'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

5
dynamic_accounts_report/doc/RELEASE_NOTES.md

@ -25,7 +25,8 @@
#### BUGFIX #### BUGFIX
- Report Bug Fix: The issues with the analytic filter in the general ledger, partner ledger, and profit and loss statement have been fixed, and the problem with language while printing reports has also been addressed. - Report Bug Fix: The issues with the analytic filter in the general ledger, partner ledger, and profit and loss statement have been fixed, and the problem with language while printing reports has also been addressed.
#### 08.09.2023 #### 18.09.2023
#### Version 16.0.1.0.7 #### Version 16.0.1.0.7
#### BUGFIX #### BUGFIX
- Report Bug Fix: Problem with language while printing profit and loss report fixed. - Report Bug Fix: Problem with language while printing profit and loss report fixed.
- Report Bug Fix: Problem with language while opening cash flow statement.

1
dynamic_accounts_report/report/ageing.py

@ -27,7 +27,6 @@ class PartnerAgeing(models.AbstractModel):
@api.model @api.model
def _get_report_values(self,docids, data=None): def _get_report_values(self,docids, data=None):
print(data)
if self.env.context.get('ageing_pdf_report'): if self.env.context.get('ageing_pdf_report'):
if data.get('report_data'): if data.get('report_data'):
data.update( data.update(

5
dynamic_accounts_report/report/ageing.xml

@ -42,8 +42,6 @@
</t> </t>
</div> </div>
</div> </div>
<br></br> <br></br>
<table class="table table-sm table-reports"> <table class="table table-sm table-reports">
<thead> <thead>
@ -97,7 +95,8 @@
<td><span t-esc="line['move']"/></td> <td><span t-esc="line['move']"/></td>
<td><span t-esc="line['date']"/></td> <td><span t-esc="line['date']"/></td>
<td><span t-esc="line['jrnl']"/></td> <td><span t-esc="line['jrnl']"/></td>
<td><span t-esc="line['acc_code']"/></td> <td><span t-esc="line['acc_code'] + line['acc_name']"/>
</td>
<td class="text-right"> <td class="text-right">
<span t-if="line.get('period6')" <span t-if="line.get('period6')"
t-esc="line['amount']" t-esc="line['amount']"

1
dynamic_accounts_report/report/cash_flow_report.py

@ -27,7 +27,6 @@ class GeneralLedger(models.AbstractModel):
@api.model @api.model
def _get_report_values(self,docids, data=None): def _get_report_values(self,docids, data=None):
if self.env.context.get('trial_pdf_report'): if 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({'account_data': data.get('report_data')['report_lines'],

31
dynamic_accounts_report/report/cash_flow_report.xml

@ -1,31 +1,23 @@
<odoo> <odoo>
<template id="dynamic_accounts_report.cash_flow"> <template id="dynamic_accounts_report.cash_flow">
<t t-call="web.html_container"> <t t-call="web.html_container">
<t t-call="web.internal_layout"> <t t-call="web.internal_layout">
<div style="font-size:12px" class="col-4"> <div style="font-size:12px" class="col-4">
<b>Report Date :</b> <b>Report Date :</b>
<span t-esc="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d %H:%M')"/> <span t-esc="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d %H:%M')"/>
<span t-esc='today'/> <span t-esc='today'/>
<br/> <br/>
<span t-esc='logged_users'/> <span t-esc='logged_users'/>
</div> </div>
<div class="page"> <div class="page">
<h4 style="padding-left:10px !important">Cash Flow statements</h4> <h4 style="padding-left:10px !important">Cash Flow statements</h4>
<div style="width:90%;margin:1px auto;font-size:12px" class="row mt32 mb32"> <div style="width:90%;margin:1px auto;font-size:12px" class="row mt32 mb32">
<div class="col-3"> <div class="col-3">
<strong>Target move:</strong> <strong>Target move:</strong>
<li> <li>
<t t-esc="Filters['target_move']"/> <t t-esc="Filters['target_move']"/>
</li> </li>
</div> </div>
<div class="col-3"> <div class="col-3">
<t t-if="Filters.get('levels')"> <t t-if="Filters.get('levels')">
<strong>Level :</strong> <strong>Level :</strong>
@ -33,11 +25,8 @@
<t t-esc="Filters['levels']"/> <t t-esc="Filters['levels']"/>
</li> </li>
</t> </t>
</div> </div>
<div class="col-4"> <div class="col-4">
<p> <p>
<t t-if="Filters.get('date_from')"> <t t-if="Filters.get('date_from')">
<strong>Date from :</strong> <strong>Date from :</strong>
@ -91,7 +80,7 @@
<tr style="font-size:13px" t-if="Filters['levels' ] == 'consolidated'"> <tr style="font-size:13px" t-if="Filters['levels' ] == 'consolidated'">
<td> <td>
<span t-esc="fetch['name']"/> <span t-esc="fetch['account']"/>
</td> </td>
<td class="text-right"> <td class="text-right">
<span t-esc="fetch['total_debit']" <span t-esc="fetch['total_debit']"
@ -110,13 +99,12 @@
</td> </td>
</tr> </tr>
</tbody> </tbody>
<tbody style="font-size:12px" t-if="Filters['levels' ] == 'detailed' " t-foreach="account_data['journal_res']" t-as="res"> <tbody style="font-size:12px" t-if="Filters['levels' ] == 'detailed' " t-foreach="account_data['journal_res']" t-as="res">
<tr t-if="fet['id'] == res['id']" t-foreach="account_data['fetched_data']" t-as="fet"> <tr t-if="fet['id'] == res['id']" t-foreach="account_data['fetched_data']" t-as="fet">
<td> <td>
<strong> <strong>
<span t-esc="fet['code']"/> <span t-esc="fet['code']"/>
<span t-esc="fet['name']"/> <span t-esc="fet['account']"/>
</strong> </strong>
</td> </td>
<td class="text-right"> <td class="text-right">
@ -142,7 +130,7 @@
</td> </td>
<tr t-foreach="res['journal_lines']" t-as="mov"> <tr t-foreach="res['journal_lines']" t-as="mov">
<td style="padding-left:50px !important" class="text-left"> <td style="padding-left:50px !important" class="text-left">
<span t-esc="mov['name']"/> <span t-esc="mov['new_name']"/>
</td> </td>
<td class="text-right"> <td class="text-right">
<span t-esc="mov['total_debit']" <span t-esc="mov['total_debit']"
@ -162,12 +150,12 @@
</tr> </tr>
</tr> </tr>
</tbody> </tbody>
<tbody style="font-size:12px" t-if="Filters['levels' ] == 'very' or Filters['levels' ] ==false " t-foreach="account_data['account_res']" t-as="res"> <tbody style="font-size:12px" t-if="Filters['levels'] == 'very' or Filters['levels' ] ==false " t-foreach="account_data['account_res']" t-as="res">
<tr t-if="fet['id'] == res['id']" t-foreach="account_data['fetched_data']" t-as="fet"> <tr t-if="fet['id'] == res['id']" t-foreach="account_data['fetched_data']" t-as="fet">
<td> <td>
<strong> <strong>
<span t-esc="fet['code']"/> <span t-esc="fet['code']"/>
<span t-esc="fet['name']"/> <span t-esc="fet['account']"/>
</strong> </strong>
</td> </td>
<td class="text-right"> <td class="text-right">
@ -191,8 +179,6 @@
'display_currency': res_company.currency_id}"/> 'display_currency': res_company.currency_id}"/>
</strong> </strong>
</td> </td>
<tr t-if="line['account_name'] == res['account']" <tr t-if="line['account_name'] == res['account']"
t-foreach="res['journal_lines']" t-as="line"> t-foreach="res['journal_lines']" t-as="line">
<td style="padding-left:20px !important" class="text-left"> <td style="padding-left:20px !important" class="text-left">
@ -246,13 +232,6 @@
</t> </t>
</t> </t>
</template> </template>
<record id="action_print_cash_flow" model="ir.actions.report"> <record id="action_print_cash_flow" model="ir.actions.report">
<field name="name">cash_flow</field> <field name="name">cash_flow</field>
<field name="model">account.cash.flow</field> <field name="model">account.cash.flow</field>

1
dynamic_accounts_report/report/daybook.py

@ -27,7 +27,6 @@ class DayBook(models.AbstractModel):
@api.model @api.model
def _get_report_values(self,docids, data=None): def _get_report_values(self,docids, data=None):
if self.env.context.get('daybook_pdf_report'): if self.env.context.get('daybook_pdf_report'):
if data.get('report_data'): if data.get('report_data'):

41
dynamic_accounts_report/report/financial_report_template.xml

@ -64,14 +64,14 @@
</t> </t>
</div> </div>
<!-- <div class="col-2">--> <!-- <div class="col-2">-->
<!-- <strong>Analytic Tag:</strong>--> <!-- <strong>Analytic Tag:</strong>-->
<!-- <t t-foreach="Filters['analytic_tags']" t-as="ps">--> <!-- <t t-foreach="Filters['analytic_tags']" t-as="ps">-->
<!-- <li>--> <!-- <li>-->
<!-- <t t-esc="ps"/>--> <!-- <t t-esc="ps"/>-->
<!-- </li>--> <!-- </li>-->
<!-- </t>--> <!-- </t>-->
<!-- </div>--> <!-- </div>-->
<div class="col-3"> <div class="col-3">
<strong>Target move:</strong> <strong>Target move:</strong>
@ -90,7 +90,7 @@
<th></th> <th></th>
<th class="text-right">Debit</th> <th class="text-right">Debit</th>
<th class="text-right">Credit</th> <th class="text-right">Credit</th>
<th class="text-right">Balance001</th> <th class="text-right">Balance</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -117,17 +117,18 @@
t-value="request.env.context.get('lang')"/> t-value="request.env.context.get('lang')"/>
<t t-esc="line['code']"/> <t t-esc="line['code']"/>
- -
<t t-if="language != 'en_US'"> <t t-esc="line['new_name']"/>
<t t-if="line['name'][lang] and lang != 'en_US'"> <!-- <t t-if="language != 'en_US'">-->
<t t-esc="line['name'][lang]"/> <!-- <t t-if="line['name'][lang] and lang != 'en_US'">-->
</t> <!-- <t t-esc="line['name'][lang]"/>-->
<t t-elif="line['name']['en_US']"> <!-- </t>-->
<t t-esc="line['name']['en_US']"/> <!-- <t t-elif="line['name']['en_US']">-->
</t> <!-- <t t-esc="line['name']['en_US']"/>-->
</t> <!-- </t>-->
<t t-else=""> <!-- </t>-->
<t t-esc="line['name']"/> <!-- <t t-else="">-->
</t> <!-- <t t-esc="line['name']"/>-->
<!-- </t>-->
</span> </span>
</td> </td>
<td class="text-right"> <td class="text-right">

1
dynamic_accounts_report/report/general_ledger.py

@ -27,7 +27,6 @@ class GeneralLedger(models.AbstractModel):
@api.model @api.model
def _get_report_values(self, docids, data=None): def _get_report_values(self, docids, data=None):
print('_get_report_values........',data)
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( data.update(

8
dynamic_accounts_report/report/general_ledger.xml

@ -10,20 +10,14 @@
<div class="oe_structure"/> <div class="oe_structure"/>
<h3 style="text-align:centre;left:50%;"><span t-esc="Filters.get('company_name')"/>: <t t-esc="title"/> <h3 style="text-align:centre;left:50%;"><span t-esc="Filters.get('company_name')"/>: <t t-esc="title"/>
</h3> </h3>
<span t-if="Filters.get('date_from')"> <span t-if="Filters.get('date_from')">
<strong> From:</strong> <strong> From:</strong>
<t t-esc="Filters['date_from']"/> <t t-esc="Filters['date_from']"/>
</span> </span>
<span t-if="Filters.get('date_to')"> <span t-if="Filters.get('date_to')">
<strong>To:</strong> <strong>To:</strong>
<t t-esc="Filters['date_to']"/> <t t-esc="Filters['date_to']"/>
</span> </span>
<div> <div>
<div style="width:100%;"> <div style="width:100%;">
<div style="text-align:centre;" class="row"> <div style="text-align:centre;" class="row">
@ -96,7 +90,7 @@
<td colspan="6"> <td colspan="6">
<span style="color: white;" t-esc="'..'"/> <span style="color: white;" t-esc="'..'"/>
<span t-esc="account['code']"/> <span t-esc="account['code']"/>
<span t-esc="account['name']"/> <span t-esc="account['new_name']"/>
</td> </td>
<td class="text-right"> <td class="text-right">
<span t-esc="account['debit']" t-options="{'widget': 'monetary', 'display_currency': env.company.currency_id}"/> <span t-esc="account['debit']" t-options="{'widget': 'monetary', 'display_currency': env.company.currency_id}"/>

1
dynamic_accounts_report/report/trial_balance.py

@ -28,7 +28,6 @@ class TrialBalance(models.AbstractModel):
@api.model @api.model
def _get_report_values(self,docids, data=None): def _get_report_values(self,docids, data=None):
if self.env.context.get('trial_pdf_report'): if 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' data.update({'account_data': data.get('report_data'
)['report_lines'], )['report_lines'],

1
dynamic_accounts_report/report/trial_balance.xml

@ -79,7 +79,6 @@
</td> </td>
<t t-if="Filters.get('date_from')"> <t t-if="Filters.get('date_from')">
<t t-if="line['Init_balance']"> <t t-if="line['Init_balance']">
<td class="mon_fld"> <td class="mon_fld">
<t t-out="line['Init_balance']['debit']" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/> <t t-out="line['Init_balance']['debit']" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td> </td>

28
dynamic_accounts_report/static/src/js/cash_flow.js

@ -9,7 +9,7 @@ odoo.define('dynamic_cash_flow_statements.cash_flow', function(require) {
var QWeb = core.qweb; var QWeb = core.qweb;
var _t = core._t; var _t = core._t;
var framework = require('web.framework'); var framework = require('web.framework');
var session = require('web.session');
var datepicker = require('web.datepicker'); var datepicker = require('web.datepicker');
var time = require('web.time'); var time = require('web.time');
@ -75,7 +75,6 @@ odoo.define('dynamic_cash_flow_statements.cash_flow', function(require) {
widgetParent: 'body', widgetParent: 'body',
allowInputToggle: true, allowInputToggle: true,
}; };
$calendarInputGroup.datetimepicker(calendarOptions); $calendarInputGroup.datetimepicker(calendarOptions);
}, },
@ -98,33 +97,20 @@ odoo.define('dynamic_cash_flow_statements.cash_flow', function(require) {
rep_lines.total_debit = self.format_currency(datas['currency'], rep_lines.total_debit); rep_lines.total_debit = self.format_currency(datas['currency'], rep_lines.total_debit);
rep_lines.total_credit = self.format_currency(datas['currency'], rep_lines.total_credit); rep_lines.total_credit = self.format_currency(datas['currency'], rep_lines.total_credit);
rep_lines.balance = self.format_currency(datas['currency'], rep_lines.balance); rep_lines.balance = self.format_currency(datas['currency'], rep_lines.balance);
}); });
}); });
_.each(datas['account_res'], function(journal_lines) { _.each(datas['account_res'], function(journal_lines) {
_.each(journal_lines['journal_lines'], function(rep_lines) { _.each(journal_lines['journal_lines'], function(rep_lines) {
rep_lines.total_debit = self.format_currency(datas['currency'], rep_lines.total_debit); rep_lines.total_debit = self.format_currency(datas['currency'], rep_lines.total_debit);
rep_lines.total_credit = self.format_currency(datas['currency'], rep_lines.total_credit); rep_lines.total_credit = self.format_currency(datas['currency'], rep_lines.total_credit);
rep_lines.total_balance = self.format_currency(datas['currency'], rep_lines.total_balance); rep_lines.total_balance = self.format_currency(datas['currency'], rep_lines.total_balance);
}); });
_.each(journal_lines['move_lines'], function(move_lines) { _.each(journal_lines['move_lines'], function(move_lines) {
move_lines.total_debit = self.format_currency(datas['currency'], move_lines.total_debit); move_lines.total_debit = self.format_currency(datas['currency'], move_lines.total_debit);
move_lines.total_credit = self.format_currency(datas['currency'], move_lines.total_credit); move_lines.total_credit = self.format_currency(datas['currency'], move_lines.total_credit);
move_lines.balance = self.format_currency(datas['currency'], move_lines.balance); move_lines.balance = self.format_currency(datas['currency'], move_lines.balance);
}); });
}); });
if (datas['levels'] == 'detailed') { if (datas['levels'] == 'detailed') {
$(event.currentTarget).next('tr').find('td ul').after( $(event.currentTarget).next('tr').find('td ul').after(
QWeb.render('SubSectionCF', { QWeb.render('SubSectionCF', {
@ -155,7 +141,6 @@ odoo.define('dynamic_cash_flow_statements.cash_flow', function(require) {
} }
}, },
load_data: function(initial_render = true) { load_data: function(initial_render = true) {
var self = this; var self = this;
self.$(".categ").empty(); self.$(".categ").empty();
@ -168,16 +153,10 @@ odoo.define('dynamic_cash_flow_statements.cash_flow', function(require) {
[this.wizard_id] [this.wizard_id]
], ],
}).then(function(datas) { }).then(function(datas) {
_.each(datas['fetched_data'], function(rep_lines) { _.each(datas['fetched_data'], function(rep_lines) {
rep_lines.total_debit = self.format_currency(datas['currency'], rep_lines.total_debit); rep_lines.total_debit = self.format_currency(datas['currency'], rep_lines.total_debit);
rep_lines.total_credit = self.format_currency(datas['currency'], rep_lines.total_credit); rep_lines.total_credit = self.format_currency(datas['currency'], rep_lines.total_credit);
rep_lines.total_balance = self.format_currency(datas['currency'], rep_lines.total_balance); rep_lines.total_balance = self.format_currency(datas['currency'], rep_lines.total_balance);
}); });
if (initial_render) { if (initial_render) {
self.$('.filter_view_tb').html(QWeb.render('CashFilterView', { self.$('.filter_view_tb').html(QWeb.render('CashFilterView', {
@ -196,7 +175,7 @@ odoo.define('dynamic_cash_flow_statements.cash_flow', function(require) {
var child = []; var child = [];
self.$('.table_view_tb').html(QWeb.render('CashTable', { self.$('.table_view_tb').html(QWeb.render('CashTable', {
lang: session.bundle_params.lang,
account_data: datas['fetched_data'], account_data: datas['fetched_data'],
level: datas['levels'], level: datas['levels'],
currency: datas['currency'], currency: datas['currency'],
@ -235,11 +214,8 @@ odoo.define('dynamic_cash_flow_statements.cash_flow', function(require) {
domain: [ domain: [
['account_ids', '=', account_id] ['account_ids', '=', account_id]
], ],
} }
return this.do_action(action); return this.do_action(action);
}, },
print_pdf: function(e) { print_pdf: function(e) {
e.preventDefault(); e.preventDefault();

2
dynamic_accounts_report/static/src/js/daybook.js

@ -296,7 +296,6 @@ odoo.define('dynamic_partner_daybook.daybook', function(require) {
}, },
view_acc_move: function(event) { view_acc_move: function(event) {
event.preventDefault(); event.preventDefault();
var self = this; var self = this;
var context = {}; var context = {};
@ -325,7 +324,6 @@ odoo.define('dynamic_partner_daybook.daybook', function(require) {
limit: 1, limit: 1,
}) })
.then(function(record) { .then(function(record) {
if (record.length > 0) { if (record.length > 0) {
show_acc_move('account.move', record[0].id); show_acc_move('account.move', record[0].id);
} else { } else {

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

@ -279,7 +279,6 @@ odoo.define('dynamic_accounts_report.general_ledger', function(require) {
// }); // });
for (var i = 0; i < data['report_lines'].length; i++) { for (var i = 0; i < data['report_lines'].length; i++) {
if (account_id == data['report_lines'][i]['id']) { if (account_id == data['report_lines'][i]['id']) {
$(event.currentTarget).next('tr').find('td').remove(); $(event.currentTarget).next('tr').find('td').remove();
$(event.currentTarget).next('tr').after( $(event.currentTarget).next('tr').after(
@ -291,7 +290,7 @@ odoo.define('dynamic_accounts_report.general_ledger', function(require) {
})) }))
$(event.currentTarget).next('tr').find('td ul li:first a').css({ $(event.currentTarget).next('tr').find('td ul li:first a').css({
'background-color': '#00ede8', 'background-color': '#fcba03',
'font-weight': 'bold', 'font-weight': 'bold',
}); });
} }

72
dynamic_accounts_report/static/src/xml/cash_flow_view.xml

@ -47,30 +47,39 @@
<t t-esc="account['month_part']"/> <t t-esc="account['month_part']"/>
</t> </t>
<t t-esc="account['code']"/> <t t-esc="account['code']"/>
<t t-esc="account['name']"/> <t t-if="account['name'][lang] and lang != 'en_US'">
<t t-esc="account['name'][lang]" />
</t>
<t t-elif="account['name']['en_US']">
<t t-esc="account['name']['en_US']" />
</t>
<t t-else="">
<t t-esc="account['name']" />
</t>
<!-- <t t-esc="account['name']"/>-->
</span> </span>
</td> </td>
<t t-if="currency[1] == 'before'"> <t t-if="currency[1] == 'before'">
<td class="cf_fld"> <td class="cf_fld">
<t t-esc="currency[0]"/> <t t-raw="account['total_debit']"/> <t t-esc="currency[0]"/> <t t-esc="account['total_debit']"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-esc="currency[0]"/> <t t-raw="account['total_credit']"/> <t t-esc="currency[0]"/> <t t-esc="account['total_credit']"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-esc="currency[0]"/> <t t-raw="account['total_balance']"/> <t t-esc="currency[0]"/> <t t-esc="account['total_balance']"/>
</td> </td>
</t> </t>
<t t-else=""> <t t-else="">
<td class="cf_fld"> <td class="cf_fld">
<t t-raw="account['total_debit']"/><t t-esc="currency[0]"/> <t t-esc="account['total_debit']"/><t t-esc="currency[0]"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-raw="account['total_credit']"/><t t-esc="currency[0]"/> <t t-esc="account['total_credit']"/><t t-esc="currency[0]"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-raw="account['total_balance']"/><t t-esc="currency[0]"/> <t t-esc="account['total_balance']"/><t t-esc="currency[0]"/>
</td> </td>
</t> </t>
</tr> </tr>
@ -89,31 +98,40 @@
<t t-esc="account['month_part']"/> <t t-esc="account['month_part']"/>
</t> </t>
<t t-esc="account['code']"/> <t t-esc="account['code']"/>
<t t-if="account['name']">
<t t-esc="account['name']"/> <t t-if="account['name'][lang] and lang != 'en_US'">
<t t-esc="account['name'][lang]" />
</t>
<t t-elif="account['name']['en_US']">
<t t-esc="account['name']['en_US']" />
</t>
<t t-else="">
<t t-esc="account['name']" />
</t>
</t>
</span> </span>
</td> </td>
<t t-if="currency[1] == 'before'"> <t t-if="currency[1] == 'before'">
<td class="cf_fld"> <td class="cf_fld">
<t t-esc="currency[0]"/> <t t-raw="account['total_debit']"/> <t t-esc="currency[0]"/> <t t-esc="account['total_debit']"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-esc="currency[0]"/> <t t-raw="account['total_credit']"/> <t t-esc="currency[0]"/> <t t-esc="account['total_credit']"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-esc="currency[0]"/> <t t-raw="account['total_balance']"/> <t t-esc="currency[0]"/> <t t-esc="account['total_balance']"/>
</td> </td>
</t> </t>
<t t-else=""> <t t-else="">
<td class="cf_fld"> <td class="cf_fld">
<t t-raw="account['total_debit']"/><t t-esc="currency[0]"/> <t t-esc="account['total_debit']"/><t t-esc="currency[0]"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-raw="account['total_credit']"/><t t-esc="currency[0]"/> <t t-esc="account['total_credit']"/><t t-esc="currency[0]"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-raw="account['total_balance']"/><t t-esc="currency[0]"/> <t t-esc="account['total_balance']"/><t t-esc="currency[0]"/>
</td> </td>
</t> </t>
</tr> </tr>
@ -255,24 +273,24 @@ Level:
</td> </td>
<t t-if="currency[1] == 'before'"> <t t-if="currency[1] == 'before'">
<td class="cf_fld"> <td class="cf_fld">
<t t-esc="currency[0]"/><t t-raw="account_line.total_debit"/> <t t-esc="currency[0]"/><t t-esc="account_line.total_debit"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-esc="currency[0]"/><t t-raw="account_line.total_credit"/> <t t-esc="currency[0]"/><t t-esc="account_line.total_credit"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-esc="currency[0]"/><t t-raw="account_line.balance"/> <t t-esc="currency[0]"/><t t-esc="account_line.balance"/>
</td> </td>
</t> </t>
<t t-else=""> <t t-else="">
<td class="cf_fld"> <td class="cf_fld">
<t t-raw="account_line.total_debit"/><t t-esc="currency[0]"/> <t t-esc="account_line.total_debit"/><t t-esc="currency[0]"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-raw="account_line.total_credit"/><t t-esc="currency[0]"/> <t t-esc="account_line.total_credit"/><t t-esc="currency[0]"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-raw="account_line.balance"/><t t-esc="currency[0]"/> <t t-esc="account_line.balance"/><t t-esc="currency[0]"/>
</td> </td>
</t> </t>
</tr> </tr>
@ -318,15 +336,15 @@ Level:
<t t-if="currency[1] == 'before'"> <t t-if="currency[1] == 'before'">
<td class="cf_fld"> <td class="cf_fld">
<t t-esc="currency[0]"/> <t t-esc="currency[0]"/>
<t t-raw="account_line.total_debit"/> <t t-esc="account_line.total_debit"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-esc="currency[0]"/> <t t-esc="currency[0]"/>
<t t-raw="account_line.total_credit"/> <t t-esc="account_line.total_credit"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-esc="currency[0]"/> <t t-esc="currency[0]"/>
<t t-raw="account_line.balance"/> <t t-esc="account_line.balance"/>
</td> </td>
</t> </t>
<t t-else=""> <t t-else="">
@ -336,12 +354,12 @@ Level:
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-raw="account_line.total_credit"/> <t t-esc="account_line.total_credit"/>
<t t-esc="currency[0]"/> <t t-esc="currency[0]"/>
</td> </td>
<td class="cf_fld"> <td class="cf_fld">
<t t-raw="account_line.balance"/> <t t-esc="account_line.balance"/>
<t t-esc="currency[0]"/> <t t-esc="currency[0]"/>
</td> </td>
</t> </t>
@ -361,4 +379,4 @@ Level:
</div> </div>
</t> </t>
</templates> </templates>

5
dynamic_accounts_report/wizard/ageing.py

@ -158,7 +158,6 @@ class AgeingView(models.TransientModel):
'docs': docs, 'docs': docs,
'time': time, 'time': time,
'Partners': account_res, 'Partners': account_res,
} }
@api.model @api.model
@ -182,7 +181,6 @@ class AgeingView(models.TransientModel):
'partner_category_ids')]}) 'partner_category_ids')]})
if not vals.get('partner_category_ids'): if not vals.get('partner_category_ids'):
vals.update({'partner_category_ids': [(5,)]}) vals.update({'partner_category_ids': [(5,)]})
res = super(AgeingView, self).write(vals) res = super(AgeingView, self).write(vals)
return res return res
@ -536,7 +534,6 @@ class AgeingView(models.TransientModel):
return currency_array return currency_array
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()
filters = json.loads(data) filters = json.loads(data)
@ -630,7 +627,7 @@ class AgeingView(models.TransientModel):
sheet.write(row, col, line_data.get('move'), txt) sheet.write(row, col, line_data.get('move'), txt)
sheet.write(row, col + 1, line_data.get('date'), txt) sheet.write(row, col + 1, line_data.get('date'), txt)
sheet.write(row, col + 2, line_data.get('jrnl'), txt) sheet.write(row, col + 2, line_data.get('jrnl'), txt)
sheet.write(row, col + 3, line_data.get('acc_code'), txt) sheet.write(row, col + 3, f'({line_data.get("acc_code")}){line_data.get("acc_name")}', txt)
if line_data.get('period6'): if line_data.get('period6'):
sheet.write(row, col + 4, line_data.get('amount'), txt) sheet.write(row, col + 4, line_data.get('amount'), txt)
else: else:

28
dynamic_accounts_report/wizard/balance_sheet.py

@ -114,7 +114,6 @@ class BalanceSheetView(models.TransientModel):
'report_lines'] 'report_lines']
move_line_accounts = [] move_line_accounts = []
move_lines_dict = {} move_lines_dict = {}
for rec in records['Accounts']: for rec in records['Accounts']:
move_line_accounts.append(rec['id']) move_line_accounts.append(rec['id'])
move_lines_dict[rec['id']] = {} move_lines_dict[rec['id']] = {}
@ -226,6 +225,15 @@ class BalanceSheetView(models.TransientModel):
rec['credit']) + " " + symbol rec['credit']) + " " + symbol
rec['m_balance'] = "{:,.2f}".format( rec['m_balance'] = "{:,.2f}".format(
rec['balance']) + " " + symbol rec['balance']) + " " + symbol
user = self.env.user
user_language = user.lang
for item in records['Accounts']:
if isinstance(item['name'], dict):
item['new_name'] = item['name'][
user_language] if user_language in item['name'] else \
item['name']['en_US']
else:
item['new_name'] = item['name']
return { return {
'name': tag, 'name': tag,
'type': 'ir.actions.client', 'type': 'ir.actions.client',
@ -369,6 +377,22 @@ class BalanceSheetView(models.TransientModel):
raise UserError(_("No Accounts Found! Please Add One")) raise UserError(_("No Accounts Found! Please Add One"))
account_res = self._get_accounts(accounts, init_balance, account_res = self._get_accounts(accounts, init_balance,
display_account, data) display_account, data)
current_lang = self.env.user.lang
list_ac = []
default_lg = self.env['ir.http']._get_default_lang()
for rec in account_res:
list_ac.append(rec['account_id'])
if rec.get('name', None):
localized_name = rec['name']
if localized_name:
rec['name'] = localized_name
else:
# If the translation for the current language is not available, use a default language or handle it as needed.
rec['name'] = rec['name'].get(default_lg,
'') # Replace 'en_US' with your desired default language.
else:
# Handle the case where 'name' is not present in the dictionary.
rec['name'] = '' # You can use an
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)
@ -457,7 +481,7 @@ class BalanceSheetView(models.TransientModel):
# if data['analytic_tags']: # if data['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]))
# current_lang = self.env.user.lang
# 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, 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.debit),0),2) AS debit,

235
dynamic_accounts_report/wizard/cash_flow.py

@ -22,9 +22,11 @@
from datetime import datetime from datetime import datetime
from odoo import models, api, fields from odoo import models, api, fields
FETCH_RANGE = 2000 FETCH_RANGE = 2000
import io import io
import json import json
try: try:
from odoo.tools.misc import xlsxwriter from odoo.tools.misc import xlsxwriter
except ImportError: except ImportError:
@ -36,7 +38,7 @@ class AccountCasgFlow(models.TransientModel):
_name = "account.cash.flow" _name = "account.cash.flow"
_inherit = "account.report" _inherit = "account.report"
date_from = fields.Date(string="Start Date", default=str(year)+'-01-01') date_from = fields.Date(string="Start Date", default=str(year) + '-01-01')
date_to = fields.Date(string="End Date", default=fields.Date.today) date_to = fields.Date(string="End Date", default=fields.Date.today)
today = fields.Date(string="Report Date", default=fields.Date.today) today = fields.Date(string="Report Date", default=fields.Date.today)
levels = fields.Selection([('summary', 'Summary'), levels = fields.Selection([('summary', 'Summary'),
@ -77,6 +79,25 @@ class AccountCasgFlow(models.TransientModel):
journal_res = report_lines['journal_res'] journal_res = report_lines['journal_res']
levels = report_lines['levels'] levels = report_lines['levels']
currency = self._get_currency() currency = self._get_currency()
user = self.env.user
user_language = user.lang
for data in fetched_data:
if filters['levels'] != 'summary':
language_name = data.get('name')
if isinstance(language_name, dict):
data['account'] = language_name[
user_language] if user_language in language_name else \
language_name['en_US']
else:
data['account'] = data.get('name')
for rec in journal_res:
for item in rec.get('journal_lines'):
if isinstance(item['name'], dict):
item['new_name'] = item['name'][
user_language] if user_language in item['name'] else \
item['name']['en_US']
else:
item['new_name'] = data.get('name')
return { return {
'name': "Cash Flow Statements", 'name': "Cash Flow Statements",
'type': 'ir.actions.client', 'type': 'ir.actions.client',
@ -143,7 +164,7 @@ class AccountCasgFlow(models.TransientModel):
filter_dict.update(default_filters) filter_dict.update(default_filters)
return filter_dict return filter_dict
def _get_report_values(self, data,option): def _get_report_values(self, data, option):
cr = self.env.cr cr = self.env.cr
data = self.get_filter(option) data = self.get_filter(option)
company_id = self.env.company company_id = self.env.company
@ -158,8 +179,10 @@ class AccountCasgFlow(models.TransientModel):
account_type_id = 'asset_cash' account_type_id = 'asset_cash'
model = self.env.context.get('active_model') model = self.env.context.get('active_model')
if data.get('levels') == 'summary': if data.get('levels') == 'summary':
state = """ AND am.state = 'posted' """ if data.get('target_move') == 'Posted' else '' state = """ AND am.state = 'posted' """ if data.get(
state2 = ' AND aml.company_id IN %s' % str(tuple(self.env.companies.ids) + tuple([0])) 'target_move') == 'Posted' else ''
state2 = ' AND aml.company_id IN %s' % str(
tuple(self.env.companies.ids) + tuple([0]))
query3 = """SELECT to_char(am.date, 'Month') as month_part, query3 = """SELECT to_char(am.date, 'Month') as month_part,
extract(YEAR from am.date) as year_part, extract(YEAR from am.date) as year_part,
sum(aml.debit) AS total_debit, sum(aml.credit) AS sum(aml.debit) AS total_debit, sum(aml.credit) AS
@ -171,7 +194,7 @@ class AccountCasgFlow(models.TransientModel):
WHERE am.date BETWEEN '""" + str( WHERE am.date BETWEEN '""" + str(
data.get('date_from')) + """' and '""" + str( data.get('date_from')) + """' and '""" + str(
data.get('date_to')) + """' AND aa.account_type='""" + str( data.get('date_to')) + """' AND aa.account_type='""" + str(
account_type_id) + """' """ + state + state2 +""") am account_type_id) + """' """ + state + state2 + """) am
LEFT JOIN account_move_line aml ON aml.move_id = am.id LEFT JOIN account_move_line aml ON aml.move_id = am.id
LEFT JOIN account_account aa ON aa.id = aml.account_id LEFT JOIN account_account aa ON aa.id = aml.account_id
GROUP BY month_part,year_part""" GROUP BY month_part,year_part"""
@ -183,7 +206,8 @@ class AccountCasgFlow(models.TransientModel):
state = """AND am.state = 'posted' """ if data.get( state = """AND am.state = 'posted' """ if data.get(
'target_move') == 'Posted' else """AND am.state in ('draft','posted') """ 'target_move') == 'Posted' else """AND am.state in ('draft','posted') """
state2 = ' AND aml.company_id IN %s' % str(tuple(self.env.companies.ids) + tuple([0])) state2 = ' AND aml.company_id IN %s' % str(
tuple(self.env.companies.ids) + tuple([0]))
sql = """SELECT DISTINCT aa.id, aa.name,aa.code, sum(aml.debit) AS total_debit, sql = """SELECT DISTINCT aa.id, aa.name,aa.code, sum(aml.debit) AS total_debit,
sum(aml.credit) AS total_credit,sum(aml.balance) AS total_balance sum(aml.credit) AS total_credit,sum(aml.balance) AS total_balance
FROM (SELECT am.* FROM account_move as am FROM (SELECT am.* FROM account_move as am
@ -192,7 +216,7 @@ class AccountCasgFlow(models.TransientModel):
WHERE am.date BETWEEN '""" + str( WHERE am.date BETWEEN '""" + str(
data.get('date_from')) + """' and '""" + str( data.get('date_from')) + """' and '""" + str(
data.get('date_to')) + """' AND aa.account_type='""" + str( data.get('date_to')) + """' AND aa.account_type='""" + str(
account_type_id) + """' """ + state + state2 +""") am account_type_id) + """' """ + state + state2 + """) am
LEFT JOIN account_move_line aml ON aml.move_id = am.id LEFT JOIN account_move_line aml ON aml.move_id = am.id
LEFT JOIN account_account aa ON aa.id = aml.account_id LEFT JOIN account_account aa ON aa.id = aml.account_id
GROUP BY aa.name, aa.code,aa.id""" GROUP BY aa.name, aa.code,aa.id"""
@ -204,7 +228,8 @@ class AccountCasgFlow(models.TransientModel):
state = """AND am.state = 'posted' """ if data.get( state = """AND am.state = 'posted' """ if data.get(
'target_move') == 'Posted' else """AND am.state in ('draft','posted') """ 'target_move') == 'Posted' else """AND am.state in ('draft','posted') """
state2 = ' AND aml.company_id IN %s' % str(tuple(self.env.companies.ids) + tuple([0])) state2 = ' AND aml.company_id IN %s' % str(
tuple(self.env.companies.ids) + tuple([0]))
sql = """SELECT DISTINCT aa.id, aa.name,aa.code, sum(aml.debit) AS total_debit, sql = """SELECT DISTINCT aa.id, aa.name,aa.code, sum(aml.debit) AS total_debit,
sum(aml.credit) AS total_credit,sum(aml.balance) AS total_balance sum(aml.credit) AS total_credit,sum(aml.balance) AS total_balance
FROM (SELECT am.* FROM account_move as am FROM (SELECT am.* FROM account_move as am
@ -225,7 +250,8 @@ class AccountCasgFlow(models.TransientModel):
state = """AND am.state = 'posted' """ if data.get( state = """AND am.state = 'posted' """ if data.get(
'target_move') == 'Posted' else """AND am.state in ('draft','posted') """ 'target_move') == 'Posted' else """AND am.state in ('draft','posted') """
state2 = ' AND aml.company_id IN %s' % str(tuple(self.env.companies.ids) + tuple([0])) state2 = ' AND aml.company_id IN %s' % str(
tuple(self.env.companies.ids) + tuple([0]))
sql = """SELECT DISTINCT aa.id, aa.name,aa.code, sum(aml.debit) AS total_debit, sql = """SELECT DISTINCT aa.id, aa.name,aa.code, sum(aml.debit) AS total_debit,
sum(aml.credit) AS total_credit,sum(aml.balance) AS total_balance sum(aml.credit) AS total_credit,sum(aml.balance) AS total_balance
FROM (SELECT am.* FROM account_move as am FROM (SELECT am.* FROM account_move as am
@ -247,7 +273,8 @@ class AccountCasgFlow(models.TransientModel):
state = """AND am.state = 'posted' """ if data.get( state = """AND am.state = 'posted' """ if data.get(
'target_move') == 'Posted' else """AND am.state in ('draft','posted') """ 'target_move') == 'Posted' else """AND am.state in ('draft','posted') """
state2 = ' AND aml.company_id IN %s' % str(tuple(self.env.companies.ids) + tuple([0])) state2 = ' AND aml.company_id IN %s' % str(
tuple(self.env.companies.ids) + tuple([0]))
sql = """SELECT DISTINCT aa.id, aa.name,aa.code, sum(aml.debit) AS total_debit, sql = """SELECT DISTINCT aa.id, aa.name,aa.code, sum(aml.debit) AS total_debit,
sum(aml.credit) AS total_credit,sum(aml.balance) AS total_balance sum(aml.credit) AS total_credit,sum(aml.balance) AS total_balance
FROM (SELECT am.* FROM account_move as am FROM (SELECT am.* FROM account_move as am
@ -265,24 +292,29 @@ class AccountCasgFlow(models.TransientModel):
fetched_data = cr.dictfetchall() fetched_data = cr.dictfetchall()
elif data.get('levels') == 'consolidated': elif data.get('levels') == 'consolidated':
state = """ AND am.state = 'posted' """ if data.get('target_move') == 'Posted' else '' state = """ AND am.state = 'posted' """ if data.get(
state2 = ' AND aml.company_id IN %s' % str(tuple(self.env.companies.ids) + tuple([0])) 'target_move') == 'Posted' else ''
query2 = """SELECT aat.name, sum(aml.debit) AS total_debit, sum(aml.credit) AS total_credit, state2 = ' AND aml.company_id IN %s' % str(
tuple(self.env.companies.ids) + tuple([0]))
query2 = """SELECT aa.name, sum(aml.debit) AS total_debit, sum(aml.credit) AS total_credit,
sum(aml.balance) AS total_balance FROM ( SELECT am.id, am.state FROM account_move as am sum(aml.balance) AS total_balance FROM ( SELECT am.id, am.state FROM account_move as am
LEFT JOIN account_move_line aml ON aml.move_id = am.id LEFT JOIN account_move_line aml ON aml.move_id = am.id
LEFT JOIN account_account aa ON aa.id = aml.account_id LEFT JOIN account_account aa ON aa.id = aml.account_id
WHERE am.date BETWEEN '""" + str(data.get('date_from')) + """' and '""" + str( WHERE am.date BETWEEN '""" + str(
data.get('date_from')) + """' and '""" + str(
data.get('date_to')) + """' AND aa.account_type='""" + str( data.get('date_to')) + """' AND aa.account_type='""" + str(
account_type_id) + """' """ + state + state2 + """) am account_type_id) + """' """ + state + state2 + """) am
LEFT JOIN account_move_line aml ON aml.move_id = am.id LEFT JOIN account_move_line aml ON aml.move_id = am.id
LEFT JOIN account_account aa ON aa.id = aml.account_id LEFT JOIN account_account aa ON aa.id = aml.account_id
GROUP BY aat.name""" GROUP BY aa.name"""
cr = self._cr cr = self._cr
cr.execute(query2) cr.execute(query2)
fetched_data = cr.dictfetchall() fetched_data = cr.dictfetchall()
elif data.get('levels') == 'detailed': elif data.get('levels') == 'detailed':
state = """AND am.state = 'posted' """ if data.get('target_move') == 'Posted' else """AND am.state in ('draft','posted') """ state = """AND am.state = 'posted' """ if data.get(
state2 = ' AND aml.company_id IN %s' % str(tuple(self.env.companies.ids) + tuple([0])) 'target_move') == 'Posted' else """AND am.state in ('draft','posted') """
state2 = ' AND aml.company_id IN %s' % str(
tuple(self.env.companies.ids) + tuple([0]))
query1 = """SELECT aa.id,aa.name,aa.code, sum(aml.debit) AS total_debit, sum(aml.credit) AS total_credit, query1 = """SELECT aa.id,aa.name,aa.code, sum(aml.debit) AS total_debit, sum(aml.credit) AS total_credit,
sum(aml.balance) AS total_balance FROM (SELECT am.id, am.state FROM account_move as am sum(aml.balance) AS total_balance FROM (SELECT am.id, am.state FROM account_move as am
LEFT JOIN account_move_line aml ON aml.move_id = am.id LEFT JOIN account_move_line aml ON aml.move_id = am.id
@ -304,8 +336,10 @@ class AccountCasgFlow(models.TransientModel):
else: else:
account_type_id = 'asset_cash' account_type_id = 'asset_cash'
state = """AND am.state = 'posted' """ if data.get('target_move') == 'Posted' else """AND am.state in ('draft','posted') """ state = """AND am.state = 'posted' """ if data.get(
state2 = ' AND aml.company_id IN %s' % str(tuple(self.env.companies.ids) + tuple([0])) 'target_move') == 'Posted' else """AND am.state in ('draft','posted') """
state2 = ' AND aml.company_id IN %s' % str(
tuple(self.env.companies.ids) + tuple([0]))
# filter = " AND aml.parent_state in ('draft','posted')" # filter = " AND aml.parent_state in ('draft','posted')"
sql = """SELECT DISTINCT aa.id, aa.name,aa.code, sum(aml.debit) AS total_debit, sql = """SELECT DISTINCT aa.id, aa.name,aa.code, sum(aml.debit) AS total_debit,
sum(aml.credit) AS total_credit,sum(aml.balance) AS total_balance sum(aml.credit) AS total_credit,sum(aml.balance) AS total_balance
@ -315,7 +349,7 @@ class AccountCasgFlow(models.TransientModel):
WHERE am.date BETWEEN '""" + str( WHERE am.date BETWEEN '""" + str(
data.get('date_from')) + """' and '""" + str( data.get('date_from')) + """' and '""" + str(
data.get('date_to')) + """' AND aa.account_type='""" + str( data.get('date_to')) + """' AND aa.account_type='""" + str(
account_type_id) + """' """ + state + state2 +""") am account_type_id) + """' """ + state + state2 + """) am
LEFT JOIN account_move_line aml ON aml.move_id = am.id LEFT JOIN account_move_line aml ON aml.move_id = am.id
LEFT JOIN account_account aa ON aa.id = aml.account_id LEFT JOIN account_account aa ON aa.id = aml.account_id
GROUP BY aa.name, aa.code,aa.id""" GROUP BY aa.name, aa.code,aa.id"""
@ -329,7 +363,6 @@ class AccountCasgFlow(models.TransientModel):
journals = self.get_journal_lines(account, data) journals = self.get_journal_lines(account, data)
if journals: if journals:
journal_res.append(journals) journal_res.append(journals)
return { return {
'date_from': data.get('date_from'), 'date_from': data.get('date_from'),
'date_to': data.get('date_to'), 'date_to': data.get('date_to'),
@ -347,8 +380,10 @@ class AccountCasgFlow(models.TransientModel):
def _get_lines(self, account, data): def _get_lines(self, account, data):
account_type_id = 'asset_cash' account_type_id = 'asset_cash'
state = """AND am.state = 'posted' """ if data.get('target_move') == 'Posted' else """AND am.state in ('draft','posted') """ state = """AND am.state = 'posted' """ if data.get(
state2 = ' AND aml.company_id IN %s' % str(tuple(self.env.companies.ids) + tuple([0])) 'target_move') == 'Posted' else """AND am.state in ('draft','posted') """
state2 = ' AND aml.company_id IN %s' % str(
tuple(self.env.companies.ids) + tuple([0]))
query = """SELECT aml.account_id,aj.id as j_id,aj.name,am.id, am.name as move_name, sum(aml.debit) AS total_debit, query = """SELECT aml.account_id,aj.id as j_id,aj.name,am.id, am.name as move_name, sum(aml.debit) AS total_debit,
sum(aml.credit) AS total_credit, COALESCE(SUM(aml.debit - aml.credit),0) AS balance FROM (SELECT am.* FROM account_move as am sum(aml.credit) AS total_credit, COALESCE(SUM(aml.debit - aml.credit),0) AS balance FROM (SELECT am.* FROM account_move as am
LEFT JOIN account_move_line aml ON aml.move_id = am.id LEFT JOIN account_move_line aml ON aml.move_id = am.id
@ -394,12 +429,14 @@ class AccountCasgFlow(models.TransientModel):
'journal_lines': fetch_data, 'journal_lines': fetch_data,
} }
def get_journal_lines(self, account, data, offset=0,
def get_journal_lines(self, account, data, offset=0, fetch_range=FETCH_RANGE): fetch_range=FETCH_RANGE):
account_type_id = 'asset_cash' account_type_id = 'asset_cash'
offset_count = offset * fetch_range offset_count = offset * fetch_range
state = """AND am.state = 'posted' """ if data.get('target_move') == 'Posted' else """AND am.state in ('draft','posted') """ state = """AND am.state = 'posted' """ if data.get(
state2 = ' AND aml.company_id IN %s' % str(tuple(self.env.companies.ids) + tuple([0])) 'target_move') == 'Posted' else """AND am.state in ('draft','posted') """
state2 = ' AND aml.company_id IN %s' % str(
tuple(self.env.companies.ids) + tuple([0]))
sql2 = """SELECT aa.name as account_name, aj.name, sum(aml.debit) AS total_debit, sql2 = """SELECT aa.name as account_name, aj.name, sum(aml.debit) AS total_debit,
sum(aml.credit) AS total_credit, COALESCE(SUM(aml.debit - aml.credit),0) AS balance FROM (SELECT am.* FROM account_move as am sum(aml.credit) AS total_credit, COALESCE(SUM(aml.debit - aml.credit),0) AS balance FROM (SELECT am.* FROM account_move as am
LEFT JOIN account_move_line aml ON aml.move_id = am.id LEFT JOIN account_move_line aml ON aml.move_id = am.id
@ -425,9 +462,6 @@ class AccountCasgFlow(models.TransientModel):
'offset': offset_count, 'offset': offset_count,
} }
@api.model @api.model
def create(self, vals): def create(self, vals):
vals['target_move'] = 'posted' vals['target_move'] = 'posted'
@ -443,7 +477,8 @@ class AccountCasgFlow(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,)]})
@ -465,6 +500,8 @@ class AccountCasgFlow(models.TransientModel):
return currency_array return currency_array
def get_dynamic_xlsx_report(self, data, response, report_data, dfr_data): def get_dynamic_xlsx_report(self, data, response, report_data, dfr_data):
user = self.env.user
user_language = user.lang
report_main_data = json.loads(dfr_data) report_main_data = json.loads(dfr_data)
data = json.loads(data) data = json.loads(data)
report_data = report_main_data.get('report_lines') report_data = report_main_data.get('report_lines')
@ -477,8 +514,8 @@ class AccountCasgFlow(models.TransientModel):
# account_type_id = self.env.ref('account.data_account_type_liquidity').id # account_type_id = self.env.ref('account.data_account_type_liquidity').id
currency_symbol = self.env.company.currency_id.symbol currency_symbol = self.env.company.currency_id.symbol
logged_users = self.env['res.company']._company_default_get(
logged_users = self.env['res.company']._company_default_get('account.account') 'account.account')
sheet = workbook.add_worksheet() sheet = workbook.add_worksheet()
bold = workbook.add_format({'align': 'center', bold = workbook.add_format({'align': 'center',
'bold': True, 'bold': True,
@ -541,38 +578,84 @@ class AccountCasgFlow(models.TransientModel):
for i_rec in fetched_data_list: for i_rec in fetched_data_list:
if data['levels'] == 'summary': if data['levels'] == 'summary':
sheet.write(row_num + 1, col_num, str(i_rec['month_part']) + str(int(i_rec['year_part'])), txt_left) sheet.write(row_num + 1, col_num,
sheet.write(row_num + 1, col_num + 1, str(i_rec['total_debit']) + str(currency_symbol), amount) str(i_rec['month_part']) + str(
sheet.write(row_num + 1, col_num + 2, str(i_rec['total_credit']) + str(currency_symbol), amount) int(i_rec['year_part'])), txt_left)
sheet.write(row_num + 1, col_num + 1,
str(i_rec['total_debit']) + str(currency_symbol),
amount)
sheet.write(row_num + 1, col_num + 2,
str(i_rec['total_credit']) + str(currency_symbol),
amount)
sheet.write(row_num + 1, col_num + 3, sheet.write(row_num + 1, col_num + 3,
str(i_rec['total_debit'] - i_rec['total_credit']) + str(currency_symbol), str(i_rec['total_debit'] - i_rec[
'total_credit']) + str(currency_symbol),
amount) amount)
row_num = row_num + 1 row_num = row_num + 1
elif data['levels'] == 'consolidated': elif data['levels'] == 'consolidated':
sheet.write(row_num + 1, col_num, i_rec['name'], txt_left) langs = i_rec['name']
sheet.write(row_num + 1, col_num + 1, str(i_rec['total_debit']) + str(currency_symbol), amount) if isinstance(langs, dict):
sheet.write(row_num + 1, col_num + 2, str(i_rec['total_credit']) + str(currency_symbol), amount) language = user_language if user_language in langs else 'en_US'
sheet.write(row_num + 1, col_num, i_rec['name'][language],
txt_left)
else:
sheet.write(row_num + 1, col_num, i_rec['name'],
txt_left)
sheet.write(row_num + 1, col_num + 1,
str(i_rec['total_debit']) + str(currency_symbol),
amount)
sheet.write(row_num + 1, col_num + 2,
str(i_rec['total_credit']) + str(currency_symbol),
amount)
sheet.write(row_num + 1, col_num + 3, sheet.write(row_num + 1, col_num + 3,
str(i_rec['total_debit'] - i_rec['total_credit']) + str(currency_symbol), str(i_rec['total_debit'] - i_rec[
'total_credit']) + str(currency_symbol),
amount) amount)
row_num = row_num + 1 row_num = row_num + 1
for j_rec in journal_res_list: for j_rec in journal_res_list:
if data['levels'] == 'detailed': if data['levels'] == 'detailed':
for k in fetched_data_list: for k in fetched_data_list:
language_two = user_language if user_language in k[
'name'] else 'en_US'
if k['id'] == j_rec['id']: if k['id'] == j_rec['id']:
sheet.write(row_num + 1, col_num, str(k['code']) + str(k['name']), txt_bold) if isinstance(k['name'], dict):
sheet.write(row_num + 1, col_num + 1, str(k['total_debit']) + str(currency_symbol), amount_bold) sheet.write(row_num + 1, col_num,
sheet.write(row_num + 1, col_num + 2, str(k['total_credit']) + str(currency_symbol), amount_bold) str(k['code']) + str(
k['name'][language_two]), txt_bold)
else:
sheet.write(row_num + 1, col_num,
str(k['code']) + str(
k['name']), txt_bold)
sheet.write(row_num + 1, col_num + 1,
str(k['total_debit']) + str(
currency_symbol), amount_bold)
sheet.write(row_num + 1, col_num + 2,
str(k['total_credit']) + str(
currency_symbol), amount_bold)
sheet.write(row_num + 1, col_num + 3, sheet.write(row_num + 1, col_num + 3,
str(k['total_debit'] - k['total_credit']) + str(currency_symbol), amount_bold) str(k['total_debit'] - k[
'total_credit']) + str(currency_symbol),
amount_bold)
row_num = row_num + 1 row_num = row_num + 1
for l_jrec in j_rec['journal_lines']: for l_jrec in j_rec['journal_lines']:
sheet.write(row_num + 1, col_num, l_jrec['name'], txt_left) language_one = user_language if user_language in l_jrec[
sheet.write(row_num + 1, col_num + 1, str(l_jrec['total_debit']) + str(currency_symbol), amount) 'name'] else 'en_US'
sheet.write(row_num + 1, col_num + 2, str(l_jrec['total_credit']) + str(currency_symbol), amount) if isinstance(l_jrec['name'], dict):
sheet.write(row_num + 1, col_num,
l_jrec['name'][language_one], txt_left)
else:
sheet.write(row_num + 1, col_num,
l_jrec['name'], txt_left)
sheet.write(row_num + 1, col_num + 1,
str(l_jrec['total_debit']) + str(
currency_symbol), amount)
sheet.write(row_num + 1, col_num + 2,
str(l_jrec['total_credit']) + str(
currency_symbol), amount)
sheet.write(row_num + 1, col_num + 3, sheet.write(row_num + 1, col_num + 3,
str(l_jrec['total_debit'] - l_jrec['total_credit']) + str(currency_symbol), str(l_jrec['total_debit'] - l_jrec[
'total_credit']) + str(currency_symbol),
amount) amount)
row_num = row_num + 1 row_num = row_num + 1
@ -580,32 +663,60 @@ class AccountCasgFlow(models.TransientModel):
if data['levels'] == 'very': if data['levels'] == 'very':
for k in fetched_data_list: for k in fetched_data_list:
if k['id'] == j_rec['id']: if k['id'] == j_rec['id']:
sheet.write(row_num + 1, col_num, str(k['code']) + str(k['name']), txt_bold) all_lang = k['name']
sheet.write(row_num + 1, col_num + 1, str(k['total_debit']) + str(currency_symbol), amount_bold) language_four = user_language if user_language in all_lang else 'en_US'
sheet.write(row_num + 1, col_num + 2, str(k['total_credit']) + str(currency_symbol), amount_bold) if isinstance(all_lang, dict):
sheet.write(row_num + 1, col_num,
str(k['code']) + str(
k['name'][language_four]), txt_bold)
else:
sheet.write(row_num + 1, col_num,
str(k['code']) + str(
k['name']), txt_bold)
sheet.write(row_num + 1, col_num + 1,
str(k['total_debit']) + str(
currency_symbol), amount_bold)
sheet.write(row_num + 1, col_num + 2,
str(k['total_credit']) + str(
currency_symbol), amount_bold)
sheet.write(row_num + 1, col_num + 3, sheet.write(row_num + 1, col_num + 3,
str(k['total_debit'] - k['total_credit']) + str(currency_symbol), amount_bold) str(k['total_debit'] - k[
'total_credit']) + str(currency_symbol),
amount_bold)
row_num = row_num + 1 row_num = row_num + 1
for l_jrec in j_rec['journal_lines']: for l_jrec in j_rec['journal_lines']:
if l_jrec['account_name'] == j_rec['account']: if l_jrec['account_name'] == j_rec['account']:
sheet.write(row_num + 1, col_num, l_jrec['name'], txt_left) sheet.write(row_num + 1, col_num, l_jrec['name'],
sheet.write(row_num + 1, col_num + 1, str(l_jrec['total_debit']) + str(currency_symbol), amount) txt_left)
sheet.write(row_num + 1, col_num + 2, str(l_jrec['total_credit']) + str(currency_symbol), amount) sheet.write(row_num + 1, col_num + 1,
str(l_jrec['total_debit']) + str(
currency_symbol), amount)
sheet.write(row_num + 1, col_num + 2,
str(l_jrec['total_credit']) + str(
currency_symbol), amount)
sheet.write(row_num + 1, col_num + 3, sheet.write(row_num + 1, col_num + 3,
str(l_jrec['total_debit'] - l_jrec['total_credit']) + str(currency_symbol), str(l_jrec['total_debit'] - l_jrec[
'total_credit']) + str(currency_symbol),
amount) amount)
row_num = row_num + 1 row_num = row_num + 1
for m_rec in j_rec['move_lines']: for m_rec in j_rec['move_lines']:
if m_rec['name'] == l_jrec['name']: if m_rec['name'] == l_jrec['name']:
sheet.write(row_num + 1, col_num, m_rec['move_name'], txt_center) sheet.write(row_num + 1, col_num,
sheet.write(row_num + 1, col_num + 1, str(m_rec['total_debit']) + str(currency_symbol), amount) m_rec['move_name'], txt_center)
sheet.write(row_num + 1, col_num + 2, str(m_rec['total_credit']) + str(currency_symbol), amount) sheet.write(row_num + 1, col_num + 1,
str(m_rec['total_debit']) + str(
currency_symbol), amount)
sheet.write(row_num + 1, col_num + 2,
str(m_rec['total_credit']) + str(
currency_symbol), amount)
sheet.write(row_num + 1, col_num + 3, sheet.write(row_num + 1, col_num + 3,
str(m_rec['total_debit'] - m_rec['total_credit']) + str(currency_symbol), str(m_rec['total_debit'] - m_rec[
'total_credit']) + str(
currency_symbol),
amount) amount)
row_num = row_num + 1 row_num = row_num + 1
workbook.close() workbook.close()
output.seek(0) output.seek(0)
response.stream.write(output.read()) response.stream.write(output.read())
output.close() output.close()

41
dynamic_accounts_report/wizard/general_ledger.py

@ -107,6 +107,20 @@ class GeneralView(models.TransientModel):
filters = self.get_filter(option) filters = self.get_filter(option)
records = self._get_report_value(data) records = self._get_report_value(data)
currency = self._get_currency() currency = self._get_currency()
default_lg = self.env['ir.http']._get_default_lang().code
user = self.env.user
user_language = user.lang
for item in records['Accounts']:
if isinstance(item['name'], dict):
item['new_name'] = item['name'][
user_language] if user_language in item['name'] else \
item['name']['en_US']
else:
item['new_name']=item['name']
# if user_language in item['name']:
# item['new_name'] = item['name'][user_language]
# else:
# item['new_name'] = item['name'][default_lg]
return { return {
'name': title, 'name': title,
'type': 'ir.actions.client', 'type': 'ir.actions.client',
@ -230,9 +244,23 @@ class GeneralView(models.TransientModel):
raise UserError(_("No Accounts Found! Please Add One")) raise UserError(_("No Accounts Found! Please Add One"))
account_res = self._get_accounts(accounts, init_balance, account_res = self._get_accounts(accounts, init_balance,
display_account, data) display_account, data)
current_lang = self.env.user.lang
list_ac = [] list_ac = []
default_lg = self.env['ir.http']._get_default_lang()
for rec in account_res: for rec in account_res:
list_ac.append(rec['account_id']) list_ac.append(rec['account_id'])
if rec.get('name', None):
localized_name = rec['name']
if localized_name:
rec['name'] = localized_name
else:
# If the translation for the current language is not available, use a default language or handle it as needed.
rec['name'] = rec['name'].get(default_lg, '') # Replace 'en_US' with your desired default language.
else:
# Handle the case where 'name' is not present in the dictionary.
rec['name'] = '' # You can use an
title = "General Ledger" title = "General Ledger"
account_line = self.get_accounts_line(list_ac, title)['report_lines'] account_line = self.get_accounts_line(list_ac, title)['report_lines']
acc_line_list = [] acc_line_list = []
@ -289,7 +317,6 @@ class GeneralView(models.TransientModel):
vals.update({'account_tag_ids': [(5,)]}) vals.update({'account_tag_ids': [(5,)]})
# Analytic filter # Analytic filter
if vals.get('analytic_ids'): if vals.get('analytic_ids'):
# print("lllllllllllllll",vals['analytic_ids'])
vals.update({'analytic_ids': [(6, 0, vals.get('analytic_ids'))]}) vals.update({'analytic_ids': [(6, 0, vals.get('analytic_ids'))]})
if vals.get('analytic_ids') == []: if vals.get('analytic_ids') == []:
vals.update({'analytic_ids': [(5,)]}) vals.update({'analytic_ids': [(5,)]})
@ -328,9 +355,7 @@ class GeneralView(models.TransientModel):
tuple(data.get('accounts').ids) + tuple([0])) 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'):
# print("Analytic account filter woking in GL")
WHERE += ' AND an.id IN %s' % str( WHERE += ' AND an.id IN %s' % str(
tuple(data.get('analytics').ids) + tuple([0])) tuple(data.get('analytics').ids) + tuple([0]))
if data['account_tags']: if data['account_tags']:
@ -397,7 +422,6 @@ class GeneralView(models.TransientModel):
tuple(data.get('analytics').ids) + tuple([0])) tuple(data.get('analytics').ids) + tuple([0]))
if data.get('account_tags'): if data.get('account_tags'):
WHERE += ' AND act.id IN %s' % str(tuple(data.get('account_tags').ids)+ tuple([0])) WHERE += ' AND act.id IN %s' % str(tuple(data.get('account_tags').ids)+ tuple([0]))
print('genrl ledger where !!!',WHERE)
# Get move lines base on sql query and Calculate the total balance # Get move lines base on sql query and Calculate the total balance
# of move lines # of move lines
@ -561,6 +585,8 @@ class GeneralView(models.TransientModel):
} }
def get_dynamic_xlsx_report(self, data, response, report_data, dfr_data): def get_dynamic_xlsx_report(self, data, response, report_data, dfr_data):
user = self.env.user
user_language = user.lang
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)
@ -620,9 +646,14 @@ class GeneralView(models.TransientModel):
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:
language = user_language if user_language in rec_data[
'name'] else 'en_US'
row += 1 row += 1
sheet.write(row + 1, col, rec_data['code'], txt) sheet.write(row + 1, col, rec_data['code'], txt)
sheet.write(row + 1, col + 1, rec_data['name'], txt) if isinstance(rec_data['name'], dict):
sheet.write(row + 1, col + 1, rec_data['name'][language], txt)
else:
sheet.write(row + 1, col + 1, rec_data['name'], txt)
sheet.write(row + 1, col + 2, '', txt) sheet.write(row + 1, col + 2, '', txt)
sheet.write(row + 1, col + 3, '', txt) sheet.write(row + 1, col + 3, '', txt)
sheet.write(row + 1, col + 4, '', txt) sheet.write(row + 1, col + 4, '', txt)

6
dynamic_accounts_report/wizard/partner_leadger.py

@ -281,7 +281,6 @@ class PartnerView(models.TransientModel):
vals.update({'partner_category_ids': [(5,)]}) vals.update({'partner_category_ids': [(5,)]})
# Account Type filter # Account Type filter
# if vals.get('account_type'): # if vals.get('account_type'):
# print('vals.get account_type..........',vals.get('account_type'))
# vals.update( # vals.update(
# {'account_type': [(6, 0, vals.get('account_type'))]}) # {'account_type': [(6, 0, vals.get('account_type'))]})
# if not vals.get('account_type'): # if not vals.get('account_type'):
@ -444,9 +443,8 @@ 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: ' +
[lt or '' for lt in filters['account_type'],
filters['account_type']]),
date_head) date_head)
sheet.merge_range('E3:F3', ' Partners: ' + ', '.join( sheet.merge_range('E3:F3', ' Partners: ' + ', '.join(
[lt or '' for lt in [lt or '' for lt in

Loading…
Cancel
Save