コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
88 ビュー

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 = ''

アバター
破棄