This question has been flagged
1 Reply
2299 Views

My models are

class LmcPhone(models.Model):

     _name = 'lmc.phone'     

     service_id = fields.Many2one('lmc.service', required=True, string="Service")

     lmc_job_id = fields.Many2one('lmc.job', string="Job", domain=[('id', '=', 'service_id.job_ids')])


class LmcService(models.Model):

    _name = 'lmc.service'   

    name = fields.Char(string="Service")

    job_ids = fields.One2many('lmc.job', 'service_id', string="Job")

    

class LmcJob(models.Model):

    _name = 'lmc.job'

    name = fields.Char(string="Job")

    service_id = fields.Many2one('lmc.service')

notes

I set the domain in lmc_job_id field.I know it is not true.Please How help me how to set the correct domain here.Thanks in advance

Avatar
Discard
Best Answer

Hi,

a few comments for the future:

  •  in your domain you compare id and a list. In such a case instead of '=' you should use the operator 'in'

  • the right leaf should not be place inside '',  if it is dynamic

Thus, the correct  domain should be similar to [('id','in',service_id.job_ids.ids)]

Do not forget to place service_id on an xml form view for LmcPhone. Otherwise, it would not work. 


Update: the simpliest domain is <field name="lmc_job_id" domain="[('service_id', '=', service_id)]"/>


Avatar
Discard
Author

Thanks for the comment.

in my python code i use

lmc_job_id = fields.Many2one('lmc.job', string="Job", domain=[('id','in', 'service_id.job_ids.ids')])

and my xml views

<field name="service_id" widget="selection"/>

<field name="lmc_job_id" domain="[('id', 'in', 'service_id.job_ids.ids')]"/>

but an error occured in selecting job from the lmc.phone model

error is raise ValueError("Invalid domain term %r" % (leaf,))

ValueError: Invalid domain term (u'id', u'in', u'service_id.job_ids.ids')

is any thong wrong in my code?

'service_id.job_ids.ids': there should be no quote marks.

Just domain=[('id','in', service_id.job_ids.ids)])

Author

i use like that domain=[('id','in', service_id.job_ids.ids)])

but a run time error is occured.

RuntimeError: maximum recursion depth exceeded while calling a Python object.

I don't no how happend like this.

Please: try to remove it from Python, and leave it only in xml

Author

I remove it from python.but i still got another error.

Uncaught Error: AttributeError: object has no attribute 'job_ids'.

Hello, let's do it simplier: <field name="lmc_job_id" domain="[('service_id', '=', service_id)]"/>. It would definetely work. I updated the answer. Please accept if it works

Author

Thank you so much for wonderful answer. Thanks It Libertas