Reputation: 43391
I'm trying to override the Deliver
button from the Delivery Orders view (i.e. stock.picking.out
) and the one in the related wizard (i.e. stock.partial.picking
).
To do that I've created a custom module: compose_delivery_order.
as a gist
<data>
<!-- override: stock/wizard/stock_partial_picking_view.xml -->
<record id="stock_partial_picking_delivery_form" model="ir.ui.view">
<field name="name">compose_delivery_order.stock_partial_picking_delivery_form</field>
<field name="model">stock.partial.picking</field>
<field name="priority" eval="15"/>
<field name="inherit_id" ref="stock.stock_partial_picking_form"/>
<field name="arch" type="xml">
<xpath expr="/form/footer//button[@name='do_partial']" position="replace">
<button
name="do_partial"
string="picking delivery"
type="object"
class="oe_highlight"
/>
</xpath>
</field>
</record>
<!-- override: sale_stock/sale_stock_view.xml -->
<record id="view_delivery_form" model="ir.ui.view">
<field name="name">stock.picking.out.form</field>
<field name="model">stock.picking.out</field>
<field name="inherit_id" ref="stock.view_picking_out_form"/>
<field name="view_id" ref="stock_partial_picking_delivery_form"/>
<field name="arch" type="xml">
<xpath expr="/form/header//button[@name='action_process']" position="replace">
<button name="action_process" states="assigned" string="[Deliver]" type="object"
class="oe_highlight"/>
</xpath>
</field>
</record>
</data>
The button on stock.picking.out
is correctly replace, but the one in stock.partial.picking
is not. When I check the Manage Views info I got:
So my view is detected but not selected as the default one it seems.
How can I force the use of my view?
Upvotes: 1
Views: 223
Reputation: 43391
After a long search, try and test I finally discover that the button for the given view was overridden in python code.
So to modify the button, I had to override the method in my module
# override: stock/wizard/stock_partial_picking.py
class stock_partial_picking(osv.osv_memory):
_inherit = 'stock.partial.picking'
_rec_name = 'picking_id'
_description = "Partial Picking Processing Wizard"
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
# override of fields_view_get in order to change the label of the process button and the separator accordingly to the shipping type
if context is None:
context = {}
res = super(stock_partial_picking, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type,
context=context, toolbar=toolbar, submenu=submenu)
type = context.get('default_type', False)
if type:
doc = etree.XML(res['arch'])
for node in doc.xpath("//button[@name='do_partial']"):
if type == 'in':
node.set('string', _('_Receive'))
elif type == 'out':
node.set('string', _('[_Deliver]'))
for node in doc.xpath("//separator[@name='product_separator']"):
if type == 'in':
node.set('string', _('Receive Products'))
elif type == 'out':
node.set('string', _('Deliver Products'))
res['arch'] = etree.tostring(doc)
return res
Upvotes: 1
Reputation: 91
There are 2 ways of referencing views in Odoo :
- if a view is requested by (model, type), the view with the right model and type, mode=primary and the lowest priority is matched
- when a view is requested by id, if its mode is not primary its closest parent with mode primary is matched
If your view is requested by priority then try setting priority to a lower value.
Upvotes: 2