콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
5025 화면

I was searching the web for quite a while and could not find the proper code syntax to solve the problem. Here is the business case and solution:

Business Case:

A company is organizing Dance Events (makes contracts with dance groups and festival locations). The festival visitors and selling tickets for the festivals are not relevant! This is done by someone else.
They want to keep track in the contacts (res.partner) who participated in the past in what dance festival to make use of that for future events. For this a new many2many field has been created "x_studio_festival_ids"
Relationship / Structure in contacts (res.partner) is the following:
  -  one contact for the COMPANY participating in festivals (this is the related company, which has child_ids, see below)
     - child_ids: multiple other contacts (individuals), which are related to the contact above 


Requirements:

As responsible event manager I want to 

  • get a list of all contacts (company & individuals) with participation in the actual festival to see company name and the related individuals with their roles (Job Title) and contact details to have a full list of all relevant persons of the current festival.
  • be able, when I prepare a future festival to filter for companies, who participated in the past in festivals and to see the relevant individuals working in those companies with their contact details.
  • the solution must be an automated action 
  • the contact can have multiple participations in the past and it should work in the same way as the contacts tags provided in odoo standard but in a separate field (--> new many2many field)


아바타
취소
작성자 베스트 답변

SOLUTION:

  • new many2many field (x_studio_festival_ids) in res.partner
  • When the record is created or the field is updated, then the content is copied to the child_ids contacts into the same field.

New Automated action:

Trigger: on creation & update

Trigger field:  x_studio_festival_ids

Action to do: execute Phyton code

code:

ids = []
for x_id in record.x_studio_festival_ids:
        ids.append(x_id.id)

for child_id in record.child_ids:
        rec = env['res.partner'].search([('id', '=', child_id.id)])
        rec.write({"x_studio_festival_ids": [(6, 0, ids)]})




---------------------------------------------

see also:

https://www.odoo.com/de_DE/forum/hilfe-1/many2many-write-replaces-all-existing-records-in-the-set-by-the-ids-148267


https://www.odoo.com/documentation/15.0/developer/reference/backend/orm.html#odoo.fields.Command


https://www.odoo.com/documentation/15.0/developer/reference/backend/orm.html#odoo.models.Model.write


https://www.youtube.com/watch?v=De0EWlz-kro


아바타
취소
관련 게시물 답글 화면 활동
0
9월 24
1233
0
5월 24
26
1
4월 24
4604
0
3월 24
1543
0
3월 24
1617