How to make button in tree view clickable?

Question:

I have tree view added in wizard. I made wizard window wider due to higher number of fields.
I have added button to tree view according to these guides:
https://www.odoo.com/es_ES/forum/ayuda-1/adding-buttons-to-one2many-list-tree-view-as-one-column-182263

https://www.youtube.com/watch?v=JsnsaSnH8-U

Simplified form view

<record model="ir.ui.view" id="vendor_connector_purchase_wizard_form">
        <field name="name">vendor.connector.purchase.wizard.form</field>
        <field name="model">vendor.connector.purchase.wizard</field>
        <field name="arch" type="xml">
            <form string="Vendor Connector Purchase Helper">
                <script>
                    $(document).ready(function(){
                        $('.modal-dialog').css({'max-width': '50%'});
                        $('.modal-content').css({'max-width': '100%'});
                    });
                </script>
                <group string="Purchase Order Helper Lines">
                    <field name="purchase_order_state" invisible="1" readonly="1"/>
                    <field name="purchase_order_helper_line_ids" mode="tree" nolabel="1" style="width:105%;">
                        <tree string="Purchase Order Lines" create="0" delete="0" editable="bottom">
                            <!-- Other fields removed for simplification -->
                            <field name="price_subtotal" widget="monetary" string="Subtotal"/>
                            <!-- BUTTON IS HERE -->
                            <button name="button_use_candidate" type="object" string="Use Candidate" confirm="Are you sure?" class="btn-success"/>
                        </tree>
                    </field>
                </group>

                <!-- Second group was removed for simplification -->
                <footer>
                    <button name="action_done" string="Done" type="object" class="btn-primary" confirm="Are you Sure?"/>
                    <button string="Cancel" special="cancel" class="btn-secondary" />
                </footer>
            </form>
        </field>
    </record>

enter image description here

Result after clicking the button. Python method was never called.
enter image description here
Both wizard model and wizard lines model have 1,1,1,1 access rights.
Please help.

EDIT:
Button method:

def button_use_candidate(self):
    print("button test")

Call of the wizard:

def action_vendor_connector_purchase_wizard(self):
    self.ensure_one()
    action = self.env["ir.actions.actions"]._for_xml_id(
        "vendor_eshop_connector.vendor_connector_purchase_wizard_wizard_action"
    )
    action["context"] = dict(self.env.context)
    action["context"].update(
        active_id=self.id,
        active_ids=self.ids,
    )
    return action
Asked By: xixo222

||

Answers:

If you check the JavaScript _renderButton function, you will find that Odoo disables the button when the record is not saved:

$button.prop('disabled', true);

Or displays the following message when the warn option is passed through options

Please click on the "save" button first

You can find an example in the manufacturing Order Components list view

Answered By: Kenly

The reason why the button didn’t work, was that there were missing values in form. Specifically link to the main wizard from the wizard lines, because I was creating wizard lines inside the main wizard´s default_get method and main wizard didn’t exist yet.

Solution: Create wizard record beforehand and manually create wizard lines.

def action_open_wizard(self):
    self.ensure_one()
    wizard = self.env["vendor.connector.purchase.wizard"].create({"purchase_order_id": self.id})
    create_vals_list = []

    for line in self.order_line:
        create_line_vals = {
            "purchase_order_line_id": line.id,
            "product_qty": line.product_qty,
            "price_unit": line.price_unit,
            "substitute_parent_id": wizard.id, # Main wizard link
        }
        create_vals_list.append((0, False, create_line_vals))
    wizard.write({"purchase_order_helper_line_ids": create_vals_list})

    return {
        "name": "Test Wizard",
        "type": "ir.actions.act_window",
        "res_model": "vendor.connector.purchase.wizard",
        "view_mode": "form",
        "res_id": wizard.id,
        "target": "new",
    }
Answered By: xixo222