Skip to Content
Menu
This question has been flagged
1 Reply
21473 Views

I have one many2many functional field in product.pricelist. In this field, comodel is also product.pricelist.

revision_id = fields.Many2many(compute='_get_revision', comodel_name='product.pricelist', relation='product_pricelist_revision_rel', column1='pricelist_id', column2='parent_pricelist_id', string="Revision", store=True, readonly=True, copy=False)


This compute function returns the active and inactive records of pricelist. 


I gave many2many field in tree view. So many2many field appears in tree view. 


<xpath expr="//form/sheet/div/field[@name='item_ids']" position="after">

                <notebook>

                <page string="Revision">

                <field name="revision_id">

              <tree editable="bottom">

              <field name="name" string="Revision Name" readonly="1"/>

              <field name="version_no" string="Revision Version No" readonly="1"/>

   <button name="action_revoke" type="object" string="Revoke" context="{'current_id': active_id}"/>

              </tree>

                </field>

                </page>

                </notebook>

In this many2many tree view, If i click Revoke button, this line record should be change to active and current record should be change to inactive. 

So I need to get the id of current record and the line record.

If I click revoke button, this line record is the self in action_revoke. So I used active_id to get current record id. 


active_id = self.env.context.get('active_id')

rec = self.env['product.pricelist'].browse(int(active_id))


but, the active_id is None. So it gets error.


Then I passed active_id in xml through context in the button


<button name="action_revoke" type="object" string="Revoke" context="{'current_id': active_id}"/>


def action_revoke(self):

        active_id = self._context.get('current_id')

        print "activeee",active_id

        rec = self.env['product.pricelist'].browse(int(active_id))

        for record in self:

            pricelist_id = self.env['product.pricelist'].search([('name', '=', record.name), ('state', '=', 'approved'), ('active', '=', True)])[0]

            print "@@@@@@@@@", pricelist_id

            if pricelist_id:

                pricelist_id.active = False

                record.active = True 


This active_id also passes the many2many tree view line record id.

So how to get active_id in Odoo 10?

Avatar
Discard
Best Answer
active_id = self._context.get('current_id')
replace this line with
active_id = self._context('active_ids')


Avatar
Discard