En la versión 15 de Odoo, creé un código Js basado en el botón Aceptar y Denegar y creé un campo booleano en el modelo de usuarios res . El flujo de trabajo es: si el usuario hace clic en el botón Aceptar, el campo booleano se convierte en Verdadero y hace clic en el botón Rechazar, cambia al estado Falso. La funcionalidad está funcionando bien. Actualmente, el problema al que me enfrento es que ambos botones se muestran en el tiempo de actualización de la página. Cómo resolver esto ... En realidad, solo quiero mostrar un botón según la disponibilidad del usuario (basado en el campo booleano)
EN EL LADO XML:
<templates> <t t-extend="ListView.buttons" t-name="AttendenceMarkListView.buttons"> <t t-jquery="button.o_list_button_add" t-operation="after"> <!-- <t t-if="widget.isAvailable()">--> <button t-if="widget.modelName == 'helpdesk.ticket'" type="button" class="btn btn-secondary btn-secondary-new o_button_accept_ticket"> Accept </button> <button t-if="widget.modelName == 'helpdesk.ticket'" type="button" class="btn btn-secondary btn-secondary-new o_button_deny_ticket"> Deny </button> <!-- </t>--> </t> </t> </templates>y en el lado JS:
odoo.define('attendance.button.tree', function (require) { "use strict"; var core = require('web.core'); var ListController = require('web.ListController'); var ListView = require('web.ListView'); var viewRegistry = require('web.view_registry'); var rpc = require('web.rpc') var includeDict = { buttons_template: 'AttendenceMarkListView.buttons', renderButtons: function ($node) { this._super.apply(this, arguments); var self = this; this.$buttons.on('click', '.o_button_accept_ticket', this._onAcceptAttendance.bind(this)); this.$buttons.on('click', '.o_button_deny_ticket', this._onDeclineAttendance.bind(this)); }, _onAcceptAttendance: function(){ var self = this; this.$('.o_button_accept_ticket').hide(); this.$('.o_button_deny_ticket').show(); rpc.query({ model: 'helpdesk.ticket', method: 'user_accept_ticket', args: [], }, { shadow: true, }).then(function () { }); }, _onDeclineAttendance: function(){ var self = this; this.$('.o_button_deny_ticket').hide(); this.$('.o_button_accept_ticket').show(); rpc.query({ model: 'helpdesk.ticket', method: 'user_decline_ticket', args: [], }, { shadow: true, }).then(function () { }); }, }; ListController.include(includeDict); });Modelo :
<templates> <t t-extend="ListView.buttons" t-name="AttendenceMarkListView.buttons"> <t t-jquery="button.o_list_button_add" t-operation="after"> <button id="button_accept" t-if="widget.modelName == 'helpdesk.ticket'" type="button" class="btn btn-secondary btn-secondary-new o_button_accept_ticket"> Accept </button> <button id="button_reject" t-if="widget.modelName == 'helpdesk.ticket'" type="button" class="btn btn-secondary btn-secondary-new o_button_deny_ticket"> Deny </button> </t> </t> </templates> **Js Side:** odoo.define('attendance.button.tree', function (require) { "use strict"; var core = require('web.core'); var ListController = require('web.ListController'); var ListView = require('web.ListView'); var viewRegistry = require('web.view_registry'); var rpc = require('web.rpc') var includeDict = { buttons_template: 'AttendenceMarkListView.buttons', renderButtons: function ($node) { this._super.apply(this, arguments); var self = this; this.$buttons.on('click', '.o_button_accept_ticket', this._onAcceptAttendance.bind(this)); this.$buttons.on('click', '.o_button_deny_ticket', this._onDeclineAttendance.bind(this)); }, _onAcceptAttendance: function(){ var self = this; this.$('.o_button_accept_ticket').hide(); this.$('.o_button_deny_ticket').show(); return self._rpc({ model: 'helpdesk.ticket', method: 'user_accept_ticket', args: [], }).then(function (data) { }); }, _onDeclineAttendance: function(){ var self = this; this.$('.o_button_deny_ticket').hide(); this.$('.o_button_accept_ticket').show(); return self._rpc({ model: 'helpdesk.ticket', method: 'user_decline_ticket', args: [], }).then(function (data) { }); }, }; ListController.include(includeDict); });