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

I'm looking to relate projects with notes. I can currently choose a project in a note form. I'd like to be able to list all related notes in a project. I feel like this would be solved by creating a model method in my project.py but I'm not sure what how to connect the view to the model. Any help?

Here's my project view:



my project.py:


Any help or ideas are appreciated.

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

This should occur automatically if you change your notes field to be a one2many instead of many2one.

Then just add the following to your view which will show as the default list (tree):

<field name="notes"/>
Ảnh đại diện
Huỷ bỏ
Tác giả

This will be VERY helpful for me in the future but not exactly what I'm looking for now. I don't want to create a new note FROM the project itself. I'd like to only create notes in Note and list the notes in the project if that makes sense. So if I create a note "New Note" and choose "New Project" as its project, I'd like to be able to go to "New Project" and see "New Note" listed there.

Câu trả lời hay nhất

In addition to your comment you can prevent the user from creating or editing note from one2many in python or xml


<field name="notes" readonly="1" />   
in python
notes = fields.One2many(..., readonly=True); # if you put readonly here the field will be always readonly

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

I think you need to set default values of one2many in project model.

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

This only can happen if note.note has a m2o to project.

At first its a good tip follow Odoo guidelines, all fields One2many must be declared as follows: xxx_ids, all Many2one xxx_id

<field name="note_ids"/>   
in python
model note.note:
project_id = fields.Many2one('project.project',string='Project')
model project.project:
note_ids = fields.One2many('note.note','project_id',string='Notes')
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
7
thg 3 17
7137
2
thg 10 22
2334
1
thg 2 18
3513
1
thg 2 16
3682
1
thg 3 15
4343