我试图覆盖“投递订单”视图中的Deliver
按钮(即stock.picking.out
)和相关向导中的stock.partial.picking
按钮。(<{p} >
为此,我创建了一个自定义模块: compose_delivery_order 。
<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>
stock.picking.out
上的按钮已正确替换,但stock.partial.picking
中的按钮未正确替换。当我查看管理视图信息时,我得到了:
所以我的视图被检测到但未被选为默认视图。
如何强制使用我的观点?
答案 0 :(得分:2)
在Odoo中有两种引用视图的方法:
- 如果(model,type)请求视图,则视图右侧 模型和类型,mode = primary和最低优先级匹配
- 当id请求视图时,如果其模式不是主要的 最接近父母与模式主要匹配
醇>
如果优先请求您的视图,请尝试将优先级设置为较低的值。
答案 1 :(得分:1)
经过长时间的搜索,尝试测试我终于发现给定视图的按钮在python代码中被覆盖。
因此,要修改按钮,我必须覆盖模块中的方法
# 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