Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
90 Представления

Hello, I have added the field analytic_distribution (journal item) to a report and need to know how to show the name rather than the code via a computed field. Any help appreciated.


For example the field shows:

Can anyone tell me the code I need to add to a computed field called "x_studio_analytic_distribution"

Аватар
Отменить

FYI. The Related Field definition will return the Analytic Distribution of just the first (by ID) Journal Item. What happens when there are multiple lines with distributions or when the first line doesn't have one?

Лучший ответ

Hi,

Please refer to the code:

import json


for record in self:

    names = []

    for line in record.line_ids:

        if line.analytic_distribution:

            data = json.loads(line.analytic_distribution)

            for analytic_id in data.keys():

                analytic = record.env['account.analytic.account'].browse(int(analytic_id))

                if analytic.exists():

                    names.append(analytic.name)

    record['x_studio_analytic_distribution'] = ', '.join(names)


Hope it helps.

Аватар
Отменить
Лучший ответ

@api.depends('analytic_distribution')

    def _compute_x_studio_analytic_distribution(self):

        for line in self:

            if line.analytic_distribution:

                analytic_ids = list(line.analytic_distribution.keys())

                names = self.env['account.analytic.account'].browse(analytic_ids).mapped('name')

                line.x_studio_analytic_distribution = ', '.join(names)

            else:

                line.x_studio_analytic_distribution = ''

Аватар
Отменить