Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

[SOLVED] How to use oe_kanban_list_many2many style in OpenERP7?

By
Juan Formoso
on 10/15/14, 5:16 AM 761 views

I had a model (res.partner) with a many2many field property (courses). It showed the courses a partner had joined to. In the kanban view of partners, I used the class oe_kanban_list_many2many, and I could see below the partners' name a list of tags indicating the courses the partner had joined to.

But, the situation changed. I needed to store some additional information about the relationship between partners and courses (joining_date), so I had to change the kind of the field courses (from many2many to one2many), and create a new intermediate table with the properties partner_id(many2one), course_id (many2one), and joining_date.

So, in summary:

BEFORE

res.partner

_columns = { ... 'courses': fields.many2many('course', 'res_partner_course_rel', 'partner_id', 'course_id', 'Courses'), ... }

kanban view

<span class="oe_kanban_list_many2many"> <field name="courses"/> </span>

NOW

res.partner.course

_columns = { 'partner_id': fields.many2one('res.partner', 'Partner'), 'course_id': fields.many2one('course', 'Course'), 'date': fields.date('Joining Date'), }

res.partner

_columns = { ... 'courses': fields.one2many('res.partner.course', 'partner_id'), ... }

kanban view

<span class="oe_kanban_list_one2many"> <field name="courses"/> </span>

In the kanban, I want to keep seeing on tags the courses a partner has joined to, but instead of that, I am seeing (n records). For example, if the partner 'John' has joined to two courses, I see, below 'John',(2 records).

How can I show the courses as before?

0
Juan Formoso
On 10/15/14, 12:44 PM

Finally, I found a solution. May be is not the best, but works, and I hope it helps to anyone.

I declared a new field in res.partner, of type function:

'courses': fields.function(
            _get_courses,
            type='many2many',
            obj="course",
            method=True,
            string='Courses'),

Above this, I declared the function _get_courses, in which I make a SQL query to get all the courses a partner has joined. And the function returns a dictionary with this structure (let's show an example with ficticious data): {partner_id_1: [joined_course_id_1, joined_course_id_2,], partner_id_2: [joined_course_id_1,], partner_id_3: [joined_course_id_5, joined_course_id_8,],} ...

Then, in the XML kanban view, we show our new functional field inside the tags with class oe_kanban_list_many2many:

<span class="oe_kanban_list_many2many">
     <field name="courses"/>
</span>

And that's it, now I can see into tags every course a partner has joined.

0

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 10/15/14, 8:25 AM

I think presently you don't have such option, but you can achieve it by writing your own widget....

I was also looking for such option, but later my requiment changed, hence dropped the idea of continuing it further...

Do share the solution if you found one... :)

Ok, thank you, I'll do that.

Juan Formoso
on 10/15/14, 9:21 AM

Ey, after a long time racking my brains, I finally managed a way to do it! I am going to post the answer.

Juan Formoso
on 10/15/14, 12:30 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 10/15/14, 5:16 AM
Seen: 761 times
Last updated: 3/16/15, 8:10 AM