Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
4430 Widoki

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)


Awatar
Odrzuć
Autor Najlepsza odpowiedź

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


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
wrz 24
635
0
maj 24
26
1
kwi 24
3878
0
mar 24
1031
0
mar 24
1203