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

I'm passing value from model A to model view trough context parameter in the xml view, but when I save the record created on model B the value passed through context isn't saved, here's my code:


Model A view.xml [extract]

<notebook>
    <page string="Etiquetas">
        <field name="tag_ids" context="{'feature_id':feature_id}"/>
    </page>
</notebook>

Model A 

from openerp import models,fields,api
from openerp.exceptions import ValidationError
class version(models.Model):
        _name           =   "version"
        _rec_name       =   "description"
        description     =   fields.Char(size=4,string="Descripción")
        feature_id      =   fields.Many2one('feature', string="Característica")
        father_feature_id   =   fields.Many2one(related="feature_id.father_id",store=True)
        tag_ids         =   fields.One2many('tag','version_id',string="Etiquetas", ondelete="cascade")


Model B

from openerp import models,fields,api
from openerp.osv.fields import related
class tag(models.Model):
        _name           =   "tag"
        _rec_name       =   "label"
        _order          =   "sequence"
        
        label           =   fields.Char(required=True,size=50,string="Etiqueta")
        version_id      =   fields.Many2one('version',required=True,string="Versión")
        feature_id      =   fields.Many2one('feature',string="Característica",store=True)
        alternative_id  =   fields.Many2one('alternative',required=True,string="Alternativa",domain="[('feature_id','=',feature_id)]")
        father_feature_rel     =   fields.Many2one(related="feature_id.father_id")
        father_id       =   fields.Many2one('tag',string="Padre",domain="[('feature_id','=',father_feature_rel)]")
        sequence        =   fields.Integer(default=0,string="Secuencia")

        

I've tried to filter using a related field in Model B but doesn't work because the context passed isn't saved into model.

Avatar
Discard
Author Best Answer

Solved my problem using this on form

<notebook>
    <page string="Etiquetas">
        <field name="tag_ids" context="{'default_feature_id':feature_id}"/>
    </page>
</notebook>

And removing the store attribute on the modelB.feature_id field because isn't a computed field, and will be stored and not recomputed when the field gets a value, in this case obtained by context.

Avatar
Discard
Related Posts Replies Views Activity
2
Jul 22
4923
2
Jul 21
5444
0
Jul 18
2270
1
May 18
7858
1
Jul 17
9626