You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.4 KiB

  1. /* Copyright 2013 Therp BV (<http://therp.nl>).
  2. * Copyright 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
  3. * Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
  4. * Copyright 2017 Sodexis <dev@sodexis.com>
  5. * Copyright 2018 Camptocamp SA
  6. * Copyright 2019 Alexandre Díaz <alexandre.diaz@tecnativa.com>
  7. * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
  8. odoo.define('web_tree_many2one_clickable.many2one_clickable', function (require) {
  9. 'use strict';
  10. var ListRenderer = require('web.ListRenderer');
  11. var ListFieldMany2One = require('web.relational_fields').ListFieldMany2One;
  12. ListRenderer.include({
  13. _renderBodyCell: function (record, node, colIndex, options) {
  14. if (!node.attrs.widget && node.attrs.name &&
  15. this.state.fields[node.attrs.name] &&
  16. this.state.fields[node.attrs.name].type === 'many2one') {
  17. // No explicit widget provided on a many2one field,
  18. // force `many2one` widget
  19. node.attrs.widget = 'many2one';
  20. }
  21. return this._super(record, node, colIndex, options);
  22. },
  23. });
  24. ListFieldMany2One.include({
  25. _renderReadonly: function () {
  26. this._super.apply(this, arguments);
  27. var self = this;
  28. if (!this.noOpen && this.value) {
  29. // Replace '<a>' element
  30. this.$el.removeClass('o_form_uri');
  31. this.$el = $('<span/>', {
  32. html: this.$el.html(),
  33. class: this.$el.attr('class') + ' o_field_text',
  34. name: this.$el.attr('name'),
  35. });
  36. // Append button
  37. var $a = $('<a/>', {
  38. href: '#',
  39. class: 'o_form_uri btn btn-sm btn-secondary' +
  40. ' fa fa-angle-double-right',
  41. }).on('click', function (ev) {
  42. ev.preventDefault();
  43. ev.stopPropagation();
  44. self.do_action({
  45. type: 'ir.actions.act_window',
  46. res_model: self.field.relation,
  47. res_id: self.value.res_id,
  48. views: [[false, 'form']],
  49. target: 'target',
  50. });
  51. });
  52. this.$el.append($a);
  53. }
  54. },
  55. });
  56. });