Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
8753 Lượt xem

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)
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
9
thg 2 16
8978
2
thg 2 22
5655
3
thg 6 19
5352
1
thg 7 18
3823
2
thg 9 15
4706