[IMP] hr_expense: add upload button on expenses kanban view

Purpose of the task is to improve the mobile user experience of
the Expenses app by adding the upload button to the Expenses
kanban view.

Task ID: 2152155

closes odoo/odoo#41839

Closes: #41839
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Barad Mahendra
2019-12-31 04:36:00 +00:00
parent 40d2f95a8d
commit 5af891c490
5 changed files with 35 additions and 5 deletions
+2 -2
View File
@@ -163,7 +163,7 @@ class HrExpense(models.Model):
if self.product_id and self.product_uom_id.category_id != self.product_id.uom_id.category_id:
raise UserError(_('Selected Unit of Measure does not belong to the same category as the product Unit of Measure.'))
def create_expense_from_attachments(self, attachment_ids=None):
def create_expense_from_attachments(self, attachment_ids=None, view_type='tree'):
''' Create the expenses from files.
:return: An action redirecting to hr.expense tree/form view.
'''
@@ -200,7 +200,7 @@ class HrExpense(models.Model):
'domain': [('id', 'in', expenses.ids)],
'res_model': 'hr.expense',
'type': 'ir.actions.act_window',
'views': [[False, "tree"], [False, "form"]],
'views': [[False, view_type], [False, "form"]],
}
# ----------------------------------------
@@ -1,8 +1,10 @@
odoo.define('hr_expense.expenses.tree', function (require) {
"use strict";
var DocumentUploadMixin = require('hr_expense.documents.upload.mixin');
var KanbanController = require('web.KanbanController');
var KanbanView = require('web.KanbanView');
var ListController = require('web.ListController');
var ListView = require('web.ListView');
var DocumentUploadMixin = require('hr_expense.documents.upload.mixin');
var viewRegistry = require('web.view_registry');
var ExpensesListController = ListController.extend(DocumentUploadMixin, {
@@ -19,5 +21,20 @@ odoo.define('hr_expense.expenses.tree', function (require) {
}),
});
var ExpensesKanbanController = KanbanController.extend(DocumentUploadMixin, {
buttons_template: 'ExpensesKanbanView.buttons',
events: _.extend({}, KanbanController.prototype.events, {
'click .o_button_upload_expense': '_onUpload',
'change .o_expense_documents_upload .o_form_binary_form': '_onAddAttachment',
}),
});
var ExpensesKanbanView = KanbanView.extend({
config: _.extend({}, KanbanView.prototype.config, {
Controller: ExpensesKanbanController,
}),
});
viewRegistry.add('hr_expense_tree', ExpensesListView);
viewRegistry.add('hr_expense_kanban', ExpensesKanbanView);
});
@@ -46,7 +46,7 @@ var DocumentUploadMixin = {
return this._rpc({
model: 'hr.expense',
method: 'create_expense_from_attachments',
args: ["", attachent_ids],
args: ["", attachent_ids, this.viewType],
context: this.initialState.context,
}).then(function(result) {
self.do_action(result);
@@ -25,4 +25,17 @@
</button>
</t>
</t>
<t t-extend="KanbanView.buttons" t-name="ExpensesKanbanView.buttons">
<t t-jquery="button" t-operation="after">
<t t-js="ctx">
if (window.odoo._modules.indexOf("base_import") >= 0) {
r.push(context.engine.tools.call(context, 'ImportView.import_button', dict));
};
</t>
<button type="button" class="btn btn-secondary o_button_upload_expense">
Upload
</button>
</t>
</t>
</templates>
+1 -1
View File
@@ -158,7 +158,7 @@
<field name="name">hr.expense.kanban</field>
<field name="model">hr.expense</field>
<field name="arch" type="xml">
<kanban class="o_kanban_mobile">
<kanban class="o_kanban_mobile" js_class="hr_expense_kanban">
<field name="name"/>
<field name="employee_id"/>
<field name="total_amount"/>