Odoo Help

0

Move an ID to a transient model (second part)

By
E.M.
on 2/12/16, 6:22 AM 955 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)
0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
3168
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 2/13/16, 7:02 AM

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

0
Krupesh Laiya
On 2/13/16, 6:21 AM

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.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 2/12/16, 6:22 AM
Seen: 955 times
Last updated: 2/13/16, 7:02 AM