Admaja
Admaja

Reputation: 69

How to change default form view in stock.picking model?

I need a little help here, so odoo has a default form view in the stock.picking model. where the form is used for outgoing, internal, and incoming type picking. so I've created several different views for those types, but there are some cases if I open the form via a many2one link it leads to the default form view, so how do I change the default form view. I've tried using the fields_view_get function but it doesn't work because it can't get the id from stock.picking. here's the fields_view_get function I've created in stock.picking model:

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
    if view_type == 'form':
        if self.picking_type_id.code == "outgoing":
            view_id = self.env.ref('gg_warehouse.wh_os_outgoing_form').id
        if self.picking_type_id.code == "incoming":
            view_id = self.env.ref('gg_warehouse.wh_os_incoming_form').id
        if self.picking_type_id.code == "internal":
            view_id = self.env.ref('gg_warehouse.wh_os_transfer_form').id
    return super(StockPickingInherit2, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)

actually I've managed to open a new form from fields.Many2one using context {'form_view_ref': 'my_module.new_custom_form_view'}, but if the page is refreshed it will return to the default odoo view. so that's why i want to just replace the default view of odoo.

Upvotes: 0

Views: 687

Answers (2)

Kenly
Kenly

Reputation: 26748

The view with the lowest priority will be used when a view is requested

client programs can request views by id, or by (model, type). For the latter, all the views for the right type and model will be searched, and the one with the lowest priority number will be returned (it is the “default view”).

You can use the priority field to make your custom view the default view.

The default stock picking form view priority is set to 12, to make yours the default view, set the priority value to a number less than 12

Example:

<record id="view_picking_form" model="ir.ui.view">
<field name="name">stock.picking.form</field>
<field name="model">stock.picking</field>
<field eval="11" name="priority"/>
<field name="arch" type="xml">

</field>
</record>

Note

In fields_view_get function, self is an empty recordset which mean that you can't use field values.

self.picking_type_id.code will be evaluated to False and all the conditions will be False, Odoo will not set the view_id

Upvotes: 1

Boubaker
Boubaker

Reputation: 429

The idea is that you simply have to replace the old ID with the new one I mean, if you use the same ID, Odoo will replace the old one and replace it with the new one For example : add a new record with same id form :

view_picking_form

<record id="view_picking_form" model="ir.ui.view">
            <field name="name">stock.picking.form</field>
            <field name="model">stock.picking</field>
            <field eval="12" name="priority"/>
            <field name="arch" type="xml">

.......
</record>

Upvotes: 0

Related Questions