Skip to Content
Menu
This question has been flagged
748 Views

Hello,

I try to do something very simple i think, but impossible to make it works.

I've got a new model "equipment", link to a product.template with a m2o

I added 2 others models :

software (for ie: S1,S2,S3,S4)

For an product.template, i can set the list of software installed on it

(for ie :P1 have the followings software : S1 and S2)

For each software, i set the list of all versions

(for ie :

S1 : v1, v2 and v3

S2 : vA, vB

S3 : vers1, vers2, vers3

S4 : v1.0, v1.1, v1.2)


I added a one2many field in the form of my equipment with 2 columns : software_id and version_id in order to know wich softwares with wich versions are installed on this equipment.


In this o2m, i can select one or several software but only installed on the product concerned by this equipement (For that, i added a domain on the field software_id)

(for ie : if my equipment is linked to the product P1, i can choose between S1 and S2

I added 2 lines, one for S1 and one for S2)

Now, on the second column, i want to select only a possible version of the software selected on the same line

Also, for the line 1 and the software S1, i could select only V1,V2 or V3

and for the line 2 and the software S2, i could select only vA or vB


And my problem is that this 2nd column doesn't works.

I added a context but it seems that it is not taking into account!?


Here the code of my different class :


class Logiciel(models.Model):
_description = 'Logiciel'
_name = 's.logiciel'
_rec_name = 's_logiciel'

s_logiciel = fields.Char()
s_tab_version = fields.One2many('s\.logiciel\.version','s_logiciel_id'\)
\ \ \ \
\ \ \ \
class\ VersionLogiciel\(models\.Model\):
\ \ \ \ _description\ =\ 'Version\ logiciel'
\ \ \ \ _name\ =\ 's\.logiciel\.version'
\ \ \ \ _rec_name\ =\ 's_version_soft'
\
\ \ \ \ s_logiciel_id\ =\ fields\.Many2one\('s\.logiciel'\)
\ \ \ \ s_version_soft\ =\ fields\.Char\(\)

class\ Article\(models\.Model\):
\ \ \ \ _inherit\ =\ 'product\.template'
\ \ \ \
\ \ \ \ s_tab_logiciels\ =\ fields\.One2many\('s\.article\.logiciel',\ 's_product_id'\)
\ \ \ \
\ \ \ \
class\ ArticleLogiciel\(models\.Model\):
\ \ \ \ _name\ =\ 's\.article\.logiciel'
\ \ \ \ _description\ =\ 'Logiciels\ de\ cet\ article'
\ \ \ \ _rec_name\ =\ 's_logiciel_id'
\ \ \ \
\ \ \ \ s_product_id\ =\ fields\.Many2one\('product\.product',\ string="Article"\)
\ \ \ \ s_logiciel_id\ =\ fields\.Many2one\('s\.logiciel',\ string="Logiciel"\)


class\ EquipementLogiciel\(models\.Model\):
\ \ \ \ _name\ =\ 's\.equipement\.logiciel'
\ \ \ \ _description\ =\ 'Logiciels\ de\ cet\ équipement'
\ \ \ \ _rec_name\ =\ 's_equipement_id'
\ \ \ \
\ \ \ \ s_equipement_id\ =\ fields\.Many2one\('s\.equipement',\ string="Equipement"\)
\ \ \ \ s_product_id_related\ =\ fields\.Many2one\(related='s_equipement_id\.s_product_id'\)
\ \ \ \ s_logiciel_product_id\ =\ fields\.Many2one\('s\.article\.logiciel',\ domain="\[\('s_product_id',\ '=',\ s_product_id_related\)\]"\)
\ \ \ \ s_version_encours\ =\ fields\.Many2one\('s.logiciel.version')

(note : for the xml code of the o2m below, i removed the < because i've got problem to display it but of course it is ok in my real code)
field name="s_tab_logiciel_equipement" widget="one2many">
tree string="Logiciels" editable="bottom">
field name="s_product_id_related" invisible="1"/>
field name="s_logiciel_product_id" string="Logiciels installés" options="{'no_create_edit': True, 'no_create': True}"/>
field name="s_version_encours" options="{'no_create_edit': True}" context="{'s_logiciel_id': s_logiciel_product_id}"/>
/tree>
/field>


Hope that is clear enough and that someone could help me because i passed hours on this problem without any result!!

Thank you if you read till the end :)

Avatar
Discard