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

I want to assign the tax_id from the product in the sale.order to my new field.

Here I have the screenshots:


Like in the screenshots I want to add the +8.0 UST directly in the tax field .

my code looks like this:

tax_line_ids = fields.Many2many('account.tax', string='Taxes', domain=['|', ('active', '=', False), ('active', '=', True)])



@api.onchange('order_line')
def _onchange_order_line(self):
for line in self.order_line:

if self.tax_line_ids.id == line.tax_id.id:
return 0
else:
self.tax_line_ids.id = line.tax_id.id


But I get an error when I try to do this: self.tax_line_ids.id = line.tax_id.id

It should add the new TAX to the new field "tax_line_ids"

I get this error:

line 22, in _onchange_order_line
    self.tax_line_ids.id = line.tax_id.id
  File "/odoo10/odoo10-server/odoo/fields.py", line 2439, in __set__
    raise TypeError("field 'id' cannot be assigned")
TypeError: field 'id' cannot be assigned

I want to thank you for the incoming help.

Thank you

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

The right way is:

@api.onchange('order_line')
def _onchange_order_line(self):
     self.ensure_one()
     _tax_line_ids = []
 for line in self.order_line:
    if self.tax_line_ids.id == line.tax_id.id:
    continue
    else:
             _tax_line_ids.append( line.tax_id )
     
     self.write({ 'tax_line_ids': [6, 0, _tax_line_ids ] })
Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

I tried this:


@api.onchange('order_line')
def _onchange_order_line(self):
for line in self.order_line:
self.write({'tax_line_ids': line.tax_id})

But it's still empty after all. Can someone help me?



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

Dear  wizardz,

Try to replace the last line on onchange  function to :

 

self.tax_line_ids = [(6,0,[line.tax_id.id])]

you can insert more than one tax by this syntax:

self.tax_line_ids = [(6,0,[1,2,3,...])]

I hope I helped you..

Ảnh đại diện
Huỷ bỏ
Tác giả

self.tax_line_ids.id = [(6, 0, [line.tax_id.id])]

File "/odoo10/odoo10-server/odoo/fields.py", line 2439, in __set__

raise TypeError("field 'id' cannot be assigned")

TypeError: field 'id' cannot be assigned

not working like this

Try it without .id in the left side

Tác giả

I tried this:

@api.onchange('order_line')

def _onchange_order_line(self):

for line in self.order_line:

self.tax_line_ids = [(6, 0, [line.tax_id.id])]

still not working and I don't know why...

Tác giả

Nothing is set to the tax_line_ids

Tác giả

your solution is not working!

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 25
3783
2
thg 8 24
6019
6
thg 12 22
9090
Canadian Tax Đã xử lý
1
thg 12 19
4349
1
thg 7 18
3836