Odoo: how to create a link in chatter to redirect to another form view

153 Views Asked by At

working for Approvals, i have created an Automation Rule which works fine to generate Internal Transfer records, please refer to my previous topic below:

Link to previous topic

now i want to add a link in Chatter to open Internal Transfer form view for newly created record, like odoo system does this for Inventory, for example.

enter image description here

how i can do this? please help.

regards

1

There are 1 best solutions below

5
On BEST ANSWER

The easiest way is to let odoo create the message on the desired record. You need both the origin record and the destination record. Models are irrelevant in this case, except for one condition: the model which will get the message needs the chatter (mail.thread mixin).

An example can be found in Odoo's invoice creation from sales order here

move.message_post_with_source(
    'mail.message_origin_link',
    render_values={'self': move, 'origin': move.line_ids.sale_line_ids.order_id},
    subtype_xmlid='mail.mt_note',
)

move is the created invoice. In this case origin will be retrieved by the line ids order line relation.

Odoo uses a default QWeb template to fill the body of the message. You can also define you're own and use it in message_post_with_source().

To conclude this answer in regards of your other linked question (with your own answer) it should look like this:

if record.request_status=='approved' and record.category_id.id in (8, 9, 13):
    new_stock_picking = env['stock.picking'].create({
        # picking data
    })
    for approval_line in record.product_line_ids: 
        # Create stock.move record
        move_data = {
            # move line data
        }
        stock_move = env['stock.move'].create(move_data)
    # add a message with link to new picking
    record.message_post_with_source(
        'mail.message_origin_link',
        render_values={'self': record, 'origin': new_stock_picking},
        subtype_xmlid='mail.mt_note',
    )

Because you're linking on the creating record (approval) to the created record (picking/transfer), the used QWeb template mail.message_origin_link probably is not the best fit.