-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] account_accountant_ux: restore Balance in GL
restore Balance in GL data on account journal dashboard
- Loading branch information
Showing
4 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
account_accountant_ux/views/account_journal_dashboard_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |