3

I want to, If i click the button, delete the data and turn back the tree view. I can delete the data with unlink method. But I can not do redirect to tree view. How can I do it?

This is my Code:

    def action_delete(self):
        vals = {
            'ref_code': self.ref_code,
            'product_name': self.product_name,
            'product_description': self.product_description,
            'teslim_alan': self.teslim_alan,
            'teslim_eden': self.teslim_eden,
            'quantity': self.quantity,
            'price': self.price,
            'unit_price': self.unit_price,
            'warehouse_id': self.warehouse_id.id
        }
        self.env['scrap'].create(vals)
        super(InventoryMenu, self).unlink()

My current URl: 'http://localhost:8069/web#id=21&cids=1&menu_id=385&action=507&model=inventory.menu&view_type=form'

My tree view URL: 'http://localhost:8069/web#cids=1&menu_id=385&action=507&model=inventory.menu&view_type=list'

Enes Kara
  • 81
  • 6

2 Answers2

3

If this is actually server action you are calling. Then you have to return new action. You probably already have action for the inventory.menu

def action_delete(self):
    #code to delete
    
    action = self.env["ir.actions.actions"]._for_xml_id("your_module.your_action")
    return action
Paxmees
  • 1,540
  • 1
  • 15
  • 28
  • I did that but I'm getting this error="ValueError: External ID not found in the system: InventoryMenu.action_inventory_menu" – Enes Kara Jul 05 '22 at 10:13
  • activate debug mode. Go to your list view. Select `Edit Action` from the debug menu. You should see the full id in the `External ID` field – Paxmees Jul 05 '22 at 10:17
2
def action_delete(self):
    #code to delete
    
    action = {
        'type': 'ir.actions.act_window',
        'name': _("Inventory List"),
        'res_model': 'inventory.menu',
        'view_mode': 'tree', #list
        'res_id': 507, # this '507' is not a good, it may not work when you remove re-install
    }
    return action

Instead of 507 you need to have an action in your xml file like

<record id="action_inventory" model="ir.actions.act_window">
    <field name="name">Inventory Menu</field>
    <field name="res_model">inventory.menu</field>
    <field name="view_mode">kanban,tree,form</field>
</record>

After you have it, you should upgrdae your module and instead of 507 use self.env.ref('your_mdoule.action_inventory').id

Sami
  • 8,168
  • 9
  • 66
  • 99