Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
29610 มุมมอง

Hello! How to set a custom or default values on a m2m tag widget?

for example:

In a tax types field, there are 3 types, "income", "value" and "excise"

i want that 3 to be the default value and there is no edit or create.


please help thanks! 

อวตาร
ละทิ้ง

Hello! thank you for fast reply. Sorry noob here but I don't understand what does def get_taxes do. Can you explain it to me please? and i want my field to like a combo box but in a m2m tag form/widget

get_taxes method will be called when you are creating a record. This method will return the IDs of those taxes which are of given type.

คำตอบที่ดีที่สุด

Hello Nissan,

You can call a method in default and can set the taxes by searching the records.

Ex:

@api.model
def get_taxes(self):
return self.env['my.tax.tax'].search([('type', 'in', ['income', 'value', 'excise'])]).ids

my_taxes = fields.Many2many(default=get_taxes, ...)

Hope this help you.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ต.ค. 21
5088
many2many_tags drag to change position แก้ไขแล้ว
1
เม.ย. 17
6170
Many2many domain filter not working แก้ไขแล้ว
1
ม.ค. 22
5652
1
ม.ค. 22
10524
Adding Many2many field to Odoo Reports แก้ไขแล้ว
2
มิ.ย. 25
6228