Odooers论坛

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Trying to automatically update analytic distribution in purchase order

形象
odoo
形象
丢弃
3 答案
0
形象
odoo
最佳答案

Ok, I've found my mistake.
analytic_distribution is a json

The right code is :

for record in records:
  analytic_account_id=record.x_studio_compte_analytique.id
  for line in record.order_line:
    line['analytic_distribution']={str(analytic_account_id): 100.0}
1 备注
形象
丢弃
形象
odoo
-

Hi Emmanuel,

I’ve set up the analytic distribution with the following structure:

Project

Department

Branch

Location

Now, I want to automate the analytic distribution such that whenever a record is created and a customer is selected on the sale order, the Location (point 4) in the distribution should be automatically populated.

I’ve written logic that fetches the location-related analytic account from the customer and adds it to the sale order’s analytic distribution. However, the issue is that it's currently being added under 1. Project instead of 4. Location.

Do you have any idea how we can specifically target the 4th column (Location) in the analytic distribution?

Thanks in advance!
Best regards,

0
形象
odoo
最佳答案

To automate analytic distribution in purchase orders, ensure you're using the correct syntax to update One2many fields. In your code, analytic_distribution should be written as a write operation on line, not dictionary-style assignment. Try this:

for record in records:
    tag_ids = [record.x_studio_compte_analytique.id]
    for line in record.order_line:
        line.write({'analytic_distribution': [(6, 0, tag_ids)]})

Also, make sure analytic_distribution is a Many2many field. This approach correctly assigns the analytic tag to each line. Test it on sample data to confirm it updates as expected.

形象
丢弃
0
形象
odoo
最佳答案
line['analytic_distribution']={str(analytic_account_id): 100.0, str(Location_account_id): 100.0, 128: 100.0 }

you can try to use above. it's working for me in the analytic distribution but creating 2 or 3 analytic items which i am trying to resolve.

形象
丢弃