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

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

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

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)]"/>


Ảnh đại diện
Huỷ bỏ
Tác giả

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)])

Tác giả

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

Tác giả

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

Tác giả

Thank you so much for wonderful answer. Thanks It Libertas

Bài viết liên quan Trả lời Lượt xem Hoạt động
10
thg 1 24
15877
6
thg 12 17
8945
5
thg 9 20
12870
1
thg 3 15
5343
2
thg 3 15
7595