diff options
| author | qdp-odoo <qdp@odoo.com> | 2017-12-21 17:28:14 +0100 |
|---|---|---|
| committer | qdp-odoo <qdp@odoo.com> | 2017-12-21 17:28:14 +0100 |
| commit | 552f5a40ba81e018cb30ad6a4e5414f00f2f9994 (patch) | |
| tree | 3cc3be451b553b1bd263883bf56565318a1e24fb /addons | |
| parent | b1402c6ad51af7e76302605e6892684dcb6cd52c (diff) | |
[IMP] hr_expense: Add expenses shortcut on accounting dashboard.
Was PR #19108. Was task 36063
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/hr_expense/__manifest__.py | 1 | ||||
| -rw-r--r-- | addons/hr_expense/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/hr_expense/models/account_journal_dashboard.py | 46 | ||||
| -rw-r--r-- | addons/hr_expense/views/account_journal_dashboard.xml | 24 | ||||
| -rw-r--r-- | addons/hr_expense/views/hr_expense_views.xml | 2 |
5 files changed, 74 insertions, 0 deletions
diff --git a/addons/hr_expense/__manifest__.py b/addons/hr_expense/__manifest__.py index 942385d3615..d67cc4ee6a2 100644 --- a/addons/hr_expense/__manifest__.py +++ b/addons/hr_expense/__manifest__.py @@ -38,6 +38,7 @@ This module also uses analytic accounting and is compatible with the invoice on 'security/ir_rule.xml', 'report/report_expense_sheet.xml', 'views/hr_dashboard.xml', + 'views/account_journal_dashboard.xml', 'views/hr_expense.xml', 'views/res_config_settings_views.xml', ], diff --git a/addons/hr_expense/models/__init__.py b/addons/hr_expense/models/__init__.py index ef38791009f..c600bfe5848 100644 --- a/addons/hr_expense/models/__init__.py +++ b/addons/hr_expense/models/__init__.py @@ -5,3 +5,4 @@ from . import hr_department from . import hr_expense from . import product_template from . import res_config_settings +from . import account_journal_dashboard diff --git a/addons/hr_expense/models/account_journal_dashboard.py b/addons/hr_expense/models/account_journal_dashboard.py new file mode 100644 index 00000000000..809d0ac6197 --- /dev/null +++ b/addons/hr_expense/models/account_journal_dashboard.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models +from odoo.tools.misc import formatLang + + +class AccountJournal(models.Model): + _inherit = "account.journal" + + def _get_expenses_to_pay_query(self): + """ + Returns a tuple containing as it's first element the SQL query used to + gather the expenses in reported state data, and the arguments + dictionary to use to run it as it's second. + """ + query = """SELECT total_amount as amount_total, currency_id AS currency + FROM hr_expense_sheet + WHERE state IN ('approve', 'post') + and journal_id = %(journal_id)s""" + return (query, {'journal_id': self.id}) + + @api.multi + def get_journal_dashboard_datas(self): + res = super(AccountJournal, self).get_journal_dashboard_datas() + #add the number and sum of expenses to pay to the json defining the accounting dashboard data + (query, query_args) = self._get_expenses_to_pay_query() + self.env.cr.execute(query, query_args) + query_results_to_pay = self.env.cr.dictfetchall() + (number_to_pay, sum_to_pay) = self._count_results_and_sum_amounts(query_results_to_pay, self.company_id.currency_id) + res['number_expenses_to_pay'] = number_to_pay + res['sum_expenses_to_pay'] = formatLang(self.env, sum_to_pay or 0.0, currency_obj=self.currency_id or self.company_id.currency_id) + return res + + @api.multi + def open_expenses_action(self): + [action] = self.env.ref('hr_expense.action_hr_expense_sheet_all_all').read() + action['context'] = { + 'search_default_approved': 1, + 'search_default_to_post': 1, + 'search_default_journal_id': self.id, + 'default_journal_id': self.id, + } + action['view_mode'] = 'tree,form' + action['views'] = [(k,v) for k,v in action['views'] if v in ['tree', 'form']] + return action diff --git a/addons/hr_expense/views/account_journal_dashboard.xml b/addons/hr_expense/views/account_journal_dashboard.xml new file mode 100644 index 00000000000..31cafa2478b --- /dev/null +++ b/addons/hr_expense/views/account_journal_dashboard.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + + <record id="account_journal_dashboard_kanban_view_inherit_hr_expense" 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="//t[@id='account.JournalBodySalePurchase']//div[hasclass('o_kanban_primary_right')]" position="inside"> + <div class="row"> + <div class="col-xs-8"> + <a type="object" t-if="journal_type == 'purchase'" name="open_expenses_action"> + <t t-esc="dashboard.number_expenses_to_pay"/> Expense Reports to Process + </a> + </div> + <div class="col-xs-4 text-right"> + <span t-if="journal_type == 'purchase'"><t t-esc="dashboard.sum_expenses_to_pay"/></span> + </div> + </div> + </xpath> + </field> + </record> + +</odoo> diff --git a/addons/hr_expense/views/hr_expense_views.xml b/addons/hr_expense/views/hr_expense_views.xml index d3b8d74f00e..4b25a5470f6 100644 --- a/addons/hr_expense/views/hr_expense_views.xml +++ b/addons/hr_expense/views/hr_expense_views.xml @@ -537,8 +537,10 @@ <field name="name" string="Expenses"/> <field name="accounting_date"/> <field name="state"/> + <separator /> <field name="employee_id"/> <field name="department_id" string="Department"/> + <field name="journal_id"/> <separator /> <filter domain="[('state', '=', 'submit')]" string="To Approve" name="submitted" help="Confirmed Expenses"/> <filter domain="[('state', '=', 'approve')]" string="To Post" name="to_post" help="Approved Expenses"/> |
