5

Through clicking a button the user should create a new order from given values and be directly redirected to the form view of the newly created order. Following method is called through the button:

@api.one
def method_name(self):
    [...]       
    vals = [...]
    new_order = self.env['sale.order'].create(vals)
    self.write({ 'state': 'review', })
    return {
        'type': 'ir.actions.act_window',
        'name': 'sale.view_order_form',
        'res_model': 'sale.order',
        'res_id': new_order.id,
        'view_type': 'form',
        'view_mode': 'form',
        'target' : 'self',
    }

Sadly nothing happens and I have no clue, what to try next. I tried to change the target to new or current or the name but nothing changes. Both without success.

Edit: see my comment on Carlos' answer.

4

1 に答える 1

7

objectボタンからモデルのメソッドを実行するには、xml ビューでボタンを次のようなタイプとして定義する必要があります。

<button name="method_name" string="My Button" type="object"/>

次に、model何かを実行した後に別のビューにリダイレクトする場合は、新しいアクションを返す必要があります。

@api.multi
def method_name(self):
    .......
    return {
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'my.model',
        'target': 'current',
        'res_id': the_resource_id,
        'type': 'ir.actions.act_window'
    }
于 2016-06-06T10:50:28.177 に答える