Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
2341 Näkymät

Hello, 


I add two buttons I want when the status is active the inactive button appear and vise versa and also color green row with active and red for inactive.

Here is my model and my view however I can see the both button when I add new line also I want if status isn't set to not to see both the button.


  • class ProjectCollaborator(models.Model):
    _name = 'project.collaborator'

    employee_id = fields.Many2one('hr.employee', string='Employee')
    status = fields.Selection([('active', 'Active'), ('inactive', 'Inactive')], string='Status')
    project_id = fields.Many2one('project.project', string='Project')


    button_activate_visible = fields.Boolean(compute='_compute_button_visibility')
    button_deactivate_visible = fields.Boolean(compute='_compute_button_visibility')


    def _compute_button_visibility(self):
    for record in self:
    record.button_activate_visible = record.status == 'inactive'
    record.button_deactivate_visible = record.status == 'active'


    def button_activate(self):
    self.write({'status': 'active'})


    def button_deactivate(self):
    self.write({'status': 'inactive'})












    Thank you in advance for any help
Avatar
Hylkää
Paras vastaus

you can try 


@api.model
def button_activate(self):
​self.write({'status': 'active'})
Avatar
Hylkää
Paras vastaus

in xml view, you can add invisible to hide/show button and using class btn-danger and btn-primacy to set background color for them.

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
heinäk. 25
424
0
marrask. 24
1208
0
lokak. 24
1437
1
lokak. 24
2091
0
lokak. 24
1246