Skip to content

Commit

Permalink
[ADD] account_accountant_ux: restore Balance in GL
Browse files Browse the repository at this point in the history
restore Balance in GL data on account journal dashboard
  • Loading branch information
ica-adhoc committed Dec 14, 2023
1 parent 905a132 commit ff8a75c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion account_accountant_ux/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Accounting Accountant UX',
'version': "16.0.2.1.0",
'version': "16.0.2.2.0",
'category': 'Accounting',
'sequence': 14,
'summary': '',
Expand All @@ -40,6 +40,7 @@
'wizards/account_change_lock_date_views.xml',
'wizards/res_config_settings_views.xml',
'data/account_accountant_data.xml',
'views/account_journal_dashboard_view.xml',
],
'demo': [
],
Expand Down
1 change: 1 addition & 0 deletions account_accountant_ux/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from . import bank_rec_widget
from . import account_move_line
from . import account_move
from . import account_journal_dashboard
29 changes: 29 additions & 0 deletions account_accountant_ux/models/account_journal_dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from odoo import models, fields
from odoo.tools.misc import formatLang


class AccountJournal(models.Model):
_inherit = 'account.journal'

def _get_journal_dashboard_data_batched(self):
res = super(AccountJournal, self)._get_journal_dashboard_data_batched()
self._fill_journal_dashboard_general_balance(res)
return res

def _fill_journal_dashboard_general_balance(self, dashboard_data):
journals = self.filtered(lambda journal: journal.type in ['bank', 'cash'])
for journal in journals:
if journal.default_account_id:
amount_field = 'aml.balance' if (not self.currency_id or self.currency_id == self.company_id.currency_id) else 'aml.amount_currency'
query = """SELECT sum(%s) FROM account_move_line aml
LEFT JOIN account_move move ON aml.move_id = move.id
WHERE aml.account_id = %%s
AND move.date <= %%s AND move.state = 'posted';""" % (amount_field,)
self.env.cr.execute(query, (journal.default_account_id.id, fields.Date.context_today(self),))
query_results = self.env.cr.dictfetchall()
if query_results and query_results[0].get('sum') != None:
account_sum = query_results[0].get('sum')
currency = journal.currency_id or journal.company_id.currency_id
dashboard_data[journal.id].update({
'account_balance_general': formatLang(self.env, currency.round(account_sum) + 0.0, currency_obj=currency)
})
18 changes: 18 additions & 0 deletions account_accountant_ux/views/account_journal_dashboard_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="account_journal_dashboard_kanban_view" model="ir.ui.view">
<field name="name">account.journal.dashboard.kanban</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.account_journal_dashboard_kanban_view"/>
<field name="arch" type="xml">
<xpath expr="//div[@id='dashboard_bank_cash_right'][1]/div[1]" position="before">
<div class="row" t-if="dashboard.account_balance_general">
<a type="object" name="action_open_bank_balance_in_gl" class="col overflow-hidden text-start"><span title="Balance in Odoo">Balance in GL</span></a>
<div class="col-auto text-end">
<span class="o_kanban_monetary"><t t-esc="dashboard.account_balance_general"/></span>
</div>
</div>
</xpath>
</field>
</record>
</odoo>

0 comments on commit ff8a75c

Please sign in to comment.