Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
128 Lượt xem

I’m trying to create a Server Action to update the Analytic Distribution field on Journal Items.

I used the Mass Edit Records action type and added the Analytic Distribution (Journal Item) field, but when I select journal items from the list view and run the action, nothing happens.

Here are my settings:

  • Model:)
  • Action Type: Mass Edit Records
  • Field: Analytic Distribution (Journal Item)
  • No domain applied

Am I missing something? Should I use Execute Code instead of Mass Edit Records to set a value for Analytic Distribution? If so, could someone share an example code snippet?

Thanks in advance!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

steps:

1. Settings->Technical->Action->Server actions

2. Model: Journal Item

Type: Execute code

Code:

analytic_account = env.ref("analytic.analytic_partners_camp_to_camp")


for rec in records:

  if not rec.analytic_distribution:

      rec.write({

          'analytic_distribution': {analytic_account.id: 15}

      })

Example:

Result:



Hope it helps



Ảnh đại diện
Huỷ bỏ