定义的action不执行
-
已经忙了几个小时了,实在找不到原因,求助大家。
原意是在出货View里面把“全部处理”去掉,改成分批处理,定义的方法是“action_partial_process”。但是Button始终不触发事件。不知道哪里出了问题。
view.xml代码如下:
<!-- 入出库Form中去掉全部处理、设为可用功能,增加分批发货功能 -->
<record id="view_move_form_x_sale" model="ir.ui.view">
<field name="name">stock.move.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//button[@name='action_done']" position="replace">
<button name="action_done" invisible="1"/>
</xpath>
<xpath expr="//button[@name='force_assign']" position="replace">
<button name="force_assign" invisible="1"/>
</xpath>
[color=red] <button name="%(stock.action_partial_move_server)d" position="replace">
<button name="action_partial_process" string="入出库操作" type="action" states="assigned,confirmed" class="oe_highlight"/>
</button>
[/color]
<!--
<xpath expr="//button[@name='Process Partially']" position="replace">
<button name="action_partial_process" string="入出库操作" type="action" states="assigned,confirmed" class="oe_highlight"/>
</xpath>
-->
</data>
</field>
</record>
py里面的代码如下
class stock_move(osv.osv):
_name = 'stock.move'
_inherit = 'stock.move'
log_create = True
def test(self, cr, uid, ids, context=None):
raise osv.except_osv(('Warning!'), '123456')
return True
[color=red] def action_partial_process(self, cr, uid, ids, context=None):
if context is None: context = {}
logging.log(10, "12345")
context.update({
'active_model': self.name,
'active_ids': ids,
'active_id': len(ids) and ids[0] or False
})
return {
'name':("Products to Process"),
'view_mode': 'form',
'view_id': False,
'view_type': 'form',
'res_model': 'stock.partial.move',
'type': 'ir.actions.act_window',
'nodestroy': True,
'target': 'new',
'domain': '[]',
'context': context
} [/color]
def do_partial(self, cr, uid, ids, partial_datas, context=None):
"""
@param partial_datas : Dictionary containing details of partial picking
like partner_id, partner_id, delivery_date,
delivery moves with product_id, product_qty, uom
@return: Dictionary of values
"""
picking_obj = self.pool.get('stock.picking')
delivery_date = partial_datas['delivery_date']
res = super(stock_move,self).do_partial(cr, uid, ids, partial_datas, context)
self.write(cr, uid, res, {'date': delivery_date})
for move in self.browse(cr, uid, res, context=context):
picking_obj.write(cr, uid, [move.picking_id.id], {'date_done': delivery_date})
return res
_columns = {
'date_expected': fields.date('计划日期', required=False),
'date': fields.date('实际日期', required=False),
}
_defaults = {
'date': lambda *a: time.strftime('%Y-%m-%d'),
}