Skip to content
Snippets Groups Projects
Commit 2981fdec authored by Leonardo Pavan Rocha's avatar Leonardo Pavan Rocha
Browse files

[IMP] hr_fleet: overwrite ir.attachment kanban view


In the assignation logs in hr_fleet, it is possible to access the list of
attachments and upload new files to a certain log. However, we currently
enter the form view for ir.attachment to create the record and many technical
fields are shown that are not necessary. This commit overwrites the kanban view
adding an upload button that will open the file upload dialog of the OS and
automatically add the uploaded files to that certain assignation log.

task-2742923

closes odoo/odoo#83755

Signed-off-by: default avatarKevin Baptiste <kba@odoo.com>
parent 299bb47a
Branches
Tags
No related merge requests found
......@@ -17,6 +17,14 @@
'demo': [
'data/hr_fleet_demo.xml',
],
'assets': {
'web.assets_backend': [
'hr_fleet/static/src/js/attachment_kanban.js',
],
'web.assets_qweb': [
'hr_fleet/static/src/xml/attachment_kanban.xml',
],
},
'auto_install': True,
'license': 'LGPL-3',
}
......@@ -29,6 +29,7 @@ class FleetVehicleAssignationLog(models.Model):
def action_get_attachment_view(self):
self.ensure_one()
res = self.env['ir.actions.act_window']._for_xml_id('base.action_attachment')
res['views'] = [[self.env.ref('hr_fleet.view_attachment_kanban_inherit_hr').id, 'kanban']]
res['domain'] = [('res_model', '=', 'fleet.vehicle.assignation.log'), ('res_id', 'in', self.ids)]
res['context'] = {'default_res_model': 'fleet.vehicle.assignation.log', 'default_res_id': self.id}
return res
/** @odoo-module */
import KanbanController from 'web.KanbanController';
import KanbanView from 'web.KanbanView';
import viewRegistry from 'web.view_registry';
import { qweb } from 'web.core';
import config from 'web.config'
const HRFleetKanbanController = KanbanController.extend({
buttons_template: 'HRFleetKanbanView.buttons',
events: _.extend({}, KanbanController.prototype.events, {
'click .o_button_upload_fleet_attachment': '_onUpload',
'change .o_fleet_documents_upload .o_form_binary_form': '_onAddAttachment',
}),
/**
* @override
*/
init: function () {
this._super.apply(this, arguments);
this.isMobile = config.device.isMobileDevice;
},
start: function () {
// define a unique uploadId and a callback method
this.fileUploadID = _.uniqueId('hr_fleet_document_upload');
$(window).on(this.fileUploadID, () => this.trigger_up('reload'));
return this._super.apply(this, arguments);
},
_onUpload: function (event) {
// If hidden upload form doesn't exist, create it
var $formContainer = this.$('.o_content').find('.o_fleet_documents_upload');
if (!$formContainer.length) {
$formContainer = $(qweb.render('HRFleet.DocumentsHiddenUploadForm', {widget: this}));
$formContainer.appendTo(this.$('.o_content'));
}
// Trigger the input to select a file
this.$('.o_fleet_documents_upload .o_input_file').click();
},
_onAddAttachment: function(ev) {
// Auto submit form once we've selected an attachment
const $input = $(ev.currentTarget).find('input.o_input_file');
if ($input.val() !== '') {
const $binaryForm = this.$('.o_fleet_documents_upload form.o_form_binary_form');
$binaryForm.submit();
}
}
});
const HRFleetKanbanView = KanbanView.extend({
config: _.extend({}, KanbanView.prototype.config, {
Controller: HRFleetKanbanController,
}),
})
viewRegistry.add('hr_fleet_kanban_view', HRFleetKanbanView);
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="HRFleet.DocumentsHiddenUploadForm">
<div class="d-none o_fleet_documents_upload">
<t t-call="HiddenInputFile">
<t t-set="multi_upload" t-value="true"/>
<t t-set="fileupload_id" t-value="widget.fileUploadID"/>
<t t-set="fileupload_action" t-translation="off">/web/binary/upload_attachment</t>
<input type="hidden" name="model" t-att-value="'fleet.vehicle.assignation.log'"/>
<input type="hidden" name="id" t-att-value="widget.initialState.context.active_id"/>
</t>
</div>
</t>
<t t-extend="KanbanView.buttons" t-name="HRFleetKanbanView.buttons">
<t t-jquery="button[t-attf-class*=o-kanban-button-new]" t-operation="replace">
<button type="button" t-att-class="'d-none d-md-block btn' + (!widget.isMobile ? ' btn-primary' : 'btn-secondary') + ' o_button_upload_fleet_attachment'">
Upload
</button>
</t>
</t>
</templates>
......@@ -82,4 +82,16 @@
</xpath>
</field>
</record>
<record id="view_attachment_kanban_inherit_hr" model="ir.ui.view">
<field name="name">ir.attachment.kanban.inherit.hr</field>
<field name="model">ir.attachment</field>
<field name="inherit_id" ref="mail.view_document_file_kanban"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//kanban" position="attributes">
<attribute name="js_class">hr_fleet_kanban_view</attribute>
</xpath>
</field>
</record>
</odoo>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment