Skip to Content
Menu
This question has been flagged
3 Replies
7957 Views

Hello All,

I want to get the value of a wizard in pivot value using context.

Here is a code.

PY of wizard :

class DataWizard(models.TransientModel):

_name = 'data.wizard'
_description = 'Data Wizard'

"""Define new fields"""
first_date = fields.Date("First Date", default=date.today())
name = fields.Char("Name")

def action_done(self):
ctx = self.env.context.copy()
ctx.update({'wizard_id': self.id})
return {
'name': 'Pivot Own Reports',
'type': 'ir.actions.act_window',
'res_model': 'get.wizard.data',
'view_type': 'form',
'view_mode': 'pivot',
'view_id': self.env.ref('my_own_pivot.action_get_wizard_data_pivot').id,
'target': 'main',
'context': ctx,
}
XML OF WIZARD:
<record id="view_data_wizard" model="ir.ui.view">
<field name="name">data.wizard.form</field>
<field name="model">data.wizard</field>
<field name="arch" type="xml">
    <form string="Data Wizard">
              <sheet>
<group>
    <field name="first_date"/>
    <field name="name"/>
</group>
              </sheet>
              <footer>
<button name="action_done" type="object" string="Done" class="oe_highlight"/>
or
<button name="cancel" string="Cancel" special="cancel" class="oe_link"/>
              </footer>
    </form>
</field>
</record>

<record id="action_data_wizard" model="ir.actions.act_window">
<field name="name">data Wizard</field>
<field name="res_model">data.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="view_id" ref="view_data_wizard"/>
</record>
</odoo>

PY of Pivot view :
class GetWizardData(models.Model):
_name = 'get.wizard.data'
_description = 'Get Wizard Data'
_auto = False

"""Define new fields"""
product_id = fields.Many2one('product.product', string='Product')
@api.model_cr
def init(self):
"""I need Context of Wizard HERE"""
tools.drop_view_if_exists(self._cr, 'get_wizard_data')
self._cr.execute("""
CREATE or replace VIEW get_wizard_data AS (
SELECT
acc_invoice.id as id,
acc_invoice.product_id as product_id
FROM account_invoice_line acc_invoice
)
""")

Please Help me out.

Thanks in Advance.

Riddhi

Avatar
Discard
Best Answer

try this way:

pass the context in action_done method:

def action_done(self):
    ctx = self.env.context.copy()
    ctx.update({'wizard_id': self.id})
    self.env['get.wizard.data'].with_context(ctx).init()
    return {
    'name': 'Pivot Own Reports',
    'type': 'ir.actions.act_window',
    'res_model': 'get.wizard.data',
    'view_type': 'form',
    'view_mode': 'pivot',
    'view_id': self.env.ref('my_own_pivot.action_get_wizard_data_pivot').id,
    'target': 'main',
    'context': ctx,
    }

get the context in init method:

@api.model_cr
def init(self):
     """I need Context of Wizard HERE"""
    if self.env.context.get('wizard_id', False):
    print("get Context of Wizard HERE", self.env.context.get('wizard_id'))

    tools.drop_view_if_exists(self._cr, 'get_wizard_data')    
    self._cr.execute("""
    CREATE or replace VIEW get_wizard_data AS (
    SELECT
    acc_invoice.id as id,
    acc_invoice.product_id as product_id
    FROM account_invoice_line acc_invoice
    )
    """)



Avatar
Discard
Author

Thanks, Divyesh for your quick help.

It is working :)

Best Answer

can you please tell me how to do same in odoo 8. I'll be really thankful, Actually I haven't enough karma for comments thats why i am answering...

Avatar
Discard
Related Posts Replies Views Activity
0
Aug 17
2241
0
Mar 15
3438
1
Feb 24
1261
1
Apr 21
11412
0
Jan 21
2141