Skip to Content
Menu
This question has been flagged
2 Replies
7620 Views

I am trying to move an ID to a transient model.

Using NEW API. If old api is required, I would like to understand where it is being used and why.

With this code I get the new tree view displayed, but no ID is moved to stock_picking_id in the transient model, why?


So I have the following button defined in stock picking view to launch a wizard:

# -*- coding: utf-8 -*-
from openerp import models, fields, api
class StockPicking(models.Model):
        _inherit = "stock.picking"
        @api.multi
        def view_tree_label_picking(self):
                return {
                        'type': 'ir.actions.act_window',
                        'name': 'view_tree_label_picking',
                        'view_type': 'tree',
                        'view_mode': 'tree',
                        'res_model': 'label.picking',
                        'context': {'stock_picking_id': self.id},
                        'target': 'new',
                }


Then I have the following class defined for the wizard,

how do I retrieve stock_picking_id assigned from the button code?


XML:

<?xml version="1.0" encoding="utf-8" ?>
<openerp>
        <data>
                <record id="view_tree_label_picking" model="ir.ui.view">
                        <field name="name">Labels Dispatch Items Tree</field>
                        <field name="model">label.picking</field>
                        <field name="arch" type="xml">
                                <tree>
                                        <field name="stock_picking_id"/>
                                </tree>
                        </field>
                </record>
        </data>
</openerp>



Transient Model:

# -*- coding: utf-8 -*-
from openerp import models, fields, api
class LabelPicking(models.TransientModel):
        _name = "label.picking"
        _inherit = "stock.picking"
        stock_picking_id = fields.Many2one('stock.picking', string='Stock Picking', 
                readonly=True,
                default=lambda self: self.env.id)
Avatar
Discard
Best Answer

Hi,

try this :

stock_picking_id = fields.Many2one('stock.picking', string='Stock Picking',readonly=True, default=lambda self: self.env['stock.picking'].browse(self._context.get('stock_picking_id', False)))

I didn't test it , but it should work like that. If not just post your feedback to really test it ...

Regards

Avatar
Discard
Best Answer

you can pass stock_picking_id directly in to the context like :

return {
                        'type': 'ir.actions.act_window',
                        'name': 'view_tree_label_picking',
                        'view_type': 'tree',
                        'view_mode': 'tree',
                        'res_model': 'label.picking',
                        'context': {'default_stock_picking_id': self.id},
                        'target': 'new',
                }

if not working then please remove the readonly from the transientModel field and upgrade the database and try it will work.
Avatar
Discard
Related Posts Replies Views Activity
9
Feb 16
7781
2
Feb 22
4286
3
Jun 19
4129
1
Jul 18
2958
2
Sep 15
3286