1

I want to get id from url when i click the button.

enter image description here

This is URL, id is 69:

http://localhost:8069/web#id=69&cids=1&menu_id=385&action=507&model=inventory.menu&view_type=form

I need to get this id in many2one field.

This is my wizard py file:

from odoo import api,fields,models

class ReduceInventoryWizard(models.TransientModel):
    _name = "reduce.inventory.wizard"
    _description = "Reduce Inventory Wizard"

    inventory_ids = fields.Many2one('inventory.menu', string="Ürün Referans No: ", default=lambda self: self.env['inventory.menu'].search([('id', '=', 69)], limit=1))

As you can see, ('id', '=', 69) this is running but just one product. I want the information of that product to come automatically when I click the button in which product. enter image description here

I tried this one: ('id', '=', self.id). But is not working.

Enes Kara
  • 81
  • 6

1 Answers1

2

In this situation there should be active_id or better active_ids in Odoo's context.

So you just can set the default parameter to use a default method, which will either return a value or an empty recordset:

def default_my_many2one_field_id(self):
    active_ids = self.env.context.get("active_ids")
    if active_ids:
        return self.env["another.model"].browse(active_ids[0])
    return self.env["another.model"]

my_many2one_field_id = fields.Many2one(
    comodel_name="another.model", string="My M2o Field",
    default=default_my_many2one_field_id)
CZoellner
  • 13,553
  • 3
  • 25
  • 38