How do i make and attache action to button

久未见 提交于 2019-12-11 05:59:51

问题


Hello I have created a button on my Odoo 10 form "SET geprint" now i want to attach an action to the button. If i press the button the value of the boolean geprint must change to 1. How can I make this possible?

If possible i would also like to create that button in the list view to update multiple records. Thx for your help

I tried your code but i am getting the following error now (name field to update is x_geprint) button code :


回答1:


You can do it via following methods.

  1. Create object type of button in form view. you can give button type="object", after that when you click on button then system will call python method In which you can write your code.

ex:

<button name="validate" string="Validate" type="object" states="draft" class="oe_highlight"/> 

@api.multi
def validate(self):
    self.write({})
    return True
  1. For the list view you need to create new wizard, In which you can select number of records from list view and in list view Action select your wizard name item.

Ex:

from openerp import models, fields, api, _

class test(models.TransientModel):
    _name = 'test.test'


<act_window name="Name String" res_model="wizard.model"
    src_model="source.model" view_mode="form" view_type="form"
    target="new" multi="False" 
    id="your_id"
    view_id="view_id"           
    context="{}"/>

In source model Action menu you can select wizard link and In the wizard you will get active_ids in context.

active_ids means all list-view selected records, based on that you can do it any operations with selective records.

This may help you.




回答2:


Make a server action (settings - > technical - > Server actions)

After that search for the action number in your link please see image (my number is 638)

Then go to the form where you want to add the button. In my example its stock.move

Go into edit formview and add the following code

<button name="638" string=" Set geprint" type="action" />


来源:https://stackoverflow.com/questions/43556087/how-do-i-make-and-attache-action-to-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!