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

Hello community, I'm new here developing modules for odoo.

I'm creating a module that allows you to classificate purchases by projects (using their analyitic account; they are related).

I want that when u select the project, ALL PURCHASE LINES get their analytic account from the project, but i don't know how to do it.

I leave my code here and if someone helps me I would be eternally grateful!!


from odoo import fields, models, api


class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
_inherit = 'purchase.order.line'

analytic_account_id = fields.Many2one(
string='Project', comodel_name='account.analytic.account')

@api.onchange('analytic_account_id')
def _onchange_analytic_account_id(self):
account.analytic.account.account_analytic_id = analytic_account_id



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

Try something like:

@api.onchange('analytic_account_id')
def _onchange_analytic_account_id(self):
for order in self:
analytic_id = order.analytic_account_id
for line in order.order_line:
line.account_analytic_id = analytic_id
Ảnh đại diện
Huỷ bỏ
Tác giả

I missed to add api in the import line. But that worked, thank you!

Câu trả lời hay nhất

good

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 16
4824
3
thg 11 15
7419
2
thg 12 23
2916
1
thg 3 25
7285
0
thg 12 18
13