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: Kevin Baptiste <kba@odoo.com>
36 lines
1.7 KiB
Python
36 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class FleetVehicleAssignationLog(models.Model):
|
|
_inherit = 'fleet.vehicle.assignation.log'
|
|
|
|
driver_employee_id = fields.Many2one('hr.employee', string='Driver (Employee)', compute='_compute_driver_employee_id', store=True, readonly=False)
|
|
attachment_number = fields.Integer('Number of Attachments', compute='_compute_attachment_number')
|
|
|
|
@api.depends('driver_id')
|
|
def _compute_driver_employee_id(self):
|
|
employees = self.env['hr.employee'].search([('address_home_id', 'in', self.driver_id.ids)])
|
|
|
|
for log in self:
|
|
employee = employees.filtered(lambda e: e.address_home_id.id == log.driver_id.id)
|
|
log.driver_employee_id = employee and employee[0] or False
|
|
|
|
def _compute_attachment_number(self):
|
|
attachment_data = self.env['ir.attachment']._read_group([
|
|
('res_model', '=', 'fleet.vehicle.assignation.log'),
|
|
('res_id', 'in', self.ids)], ['res_id'], ['res_id'])
|
|
attachment = dict((data['res_id'], data['res_id_count']) for data in attachment_data)
|
|
for doc in self:
|
|
doc.attachment_number = attachment.get(doc.id, 0)
|
|
|
|
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
|