Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
3165 Lượt xem
I am trying to call an action server from a menu, but it is not working for me, it is in Odoo 15

model="ir.actions.server" id="df_action_remove_draf_orders">
name="name">Remove Draf Orders
name="model_id" ref="model_df_maintenance_work_order"/>
name="type">ir.actions.server
name="state">code
name="code">
if records:
action = model.action_remove_draf_orders()

#--Function  PY

def action_remove_draf_orders(self):
for record in self:
if record.state == 'draf':
record.unlink()


id="menu_maintenance_remove_order" name="Remove orders in draft state"
parent="maintenance.menu_maintenance_configuration" action="df_action_remove_draf_orders"
groups="maintenance.group_equipment_manager" sequence="6"/>

                
Ảnh đại diện
Huỷ bỏ

I think your code would work in a list view button. It check if there are records then for each reacord if state='draft' it would remove it. To use it, put a button on the header of the list view, select the records to work on and click the button.

Since you want to call it from a menu which I believe will not have a set of records. I think you should change your code:
ir.action code: action=model.action_remove_draft_orders()
action_remove_draft_order:
records=self.env['df.maintanance_work_order'].search([('state','==','draft')])
for record in records:
record.unlink()

Câu trả lời hay nhất

To call an action server from a menu in Odoo, you can use the following code:

id="menu_maintenance_remove_order" name="Remove orders in draft state"
          parent="maintenance.menu_maintenance_configuration"
          action="df_action_remove_draf_orders"
          groups="maintenance.group_equipment_manager" sequence="6"/>

model="ir.actions.server" id="df_action_remove_draf_orders">
    name="name">Remove Draf Orders
    name="model_id" ref="model_df_maintenance_work_order"/>
    name="type">ir.actions.server
    name="state">code
    name="code">
         if records:
            action = model.action_remove_draf_orders()
    

In the code above, the df_action_remove_draf_orders action is called when the user clicks on the menu_maintenance_remove_order menu item. The action server calls the action_remove_draf_orders method on the df_maintenance_work_order model, which removes all draft orders.

You may need to adjust the code to match your specific use case, such as the model and method names, and the conditions for removing draft orders.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

You can Try like this.

<odoo>


    <record id="test_contacts" model="ir.actions.server">


        <field name="name">Contacts</field>


        <field name="type">ir.actions.server</field>


        <field name="model_id" ref="model_res_partner"/>


        <field name="binding_model_id" ref="model_res_partner"/>


        <field name="sequence">0</field>


        <field name="state">code</field>


        <field name="code">action = model.action_done()</field>


    </record>


    <record id="module_name.menu_record_id" model="ir.ui.menu">


        <field name="action" ref="custom_module.test_contacts"/>


    </record>


</odoo>

class ResPartnerInherit(models.Model):
_inherit = 'res.partner'

@api.model
def action_done(self):
for record in self:
if record.state == 'draft':
record.unlink()

Regards

Ảnh đại diện
Huỷ bỏ