Skip to Content
Odoo เมนู
  • ลงชื่อเข้าใช้
  • ทดลองใช้ฟรี
  • แอป
    การเงิน
    • ระบบบัญชี
    • ระบบการออกใบแจ้งหนี้
    • ระบบบัญชีรายจ่าย
    • ระบบการจัดการข้อมูลผ่านสเปรดชีต (BI)
    • เอกสาร
    • ระบบลงลายเซ็น
    การขาย
    • ลูกค้าสัมพันธ์
    • การขาย
    • POS ร้านค้า
    • POS ร้านอาหาร
    • ระบบสมัครสมาชิก
    • การเช่า
    การจัดการเว็บไซต์
    • เครื่องมือสร้างเว็บไซต์
    • ระบบการขายออนไลน์
    • บล็อก
    • ฟอรั่ม
    • ไลฟ์แชท
    • ระบบการอบรมออนไลน์
    ซัพพลายเชน
    • คลังสินค้า
    • ระบบการผลิต
    • PLM
    • ระบบการจัดซื้อ
    • การซ่อมบำรุง
    • ระบบจัดการคุณภาพ
    ทรัพยากรบุคคล
    • ข้อมูลพนักงาน
    • ระบบสรรหาบุคลากร
    • ระบบการลา
    • การประเมิน
    • ระบบการแนะนำพนักงาน
    • ระบบจัดการยานพาหนะ
    การตลาด
    • โซเชียลมาร์เก็ตติ้ง
    • การตลาดผ่านอีเมล
    • ระบบการตลาดผ่าน SMS
    • ระบบการจัดงานอีเวนต์
    • การตลาดแบบอัตโนมัติ
    • ระบบแบบสำรวจ
    การบริการ
    • โปรเจกต์
    • ระบบบันทึกเวลา
    • ระบบการจัดการบริการภาคสนาม
    • ระบบดูแลช่วยเหลือ
    • การวางแผน
    • การนัดหมาย
    ประสิทธิผล
    • ระบบแสดงความคิดเห็น
    • ระบบการอนุมัติ
    • ไอโอที
    • VoIP
    • คลังข้อมูล
    • WhatsApp
    แอปพลิเคชันของบุคคลที่สาม Odoo สตูดิโอ แพลตฟอร์มคลาวด์ของ Odoo
  • อุตสาหกรรม
    การค้าปลีก
    • ร้านขายหนังสือ
    • ร้านขายเสื้อผ้า
    • ร้านขายเฟอร์นิเจอร์
    • ร้านขายของชำ
    • ร้านขายฮาร์ดแวร์
    • ร้านขายของเล่น
    Food & Hospitality
    • บาร์และผับ
    • ร้านอาหาร
    • อาหารฟาสต์ฟู้ด
    • Guest House
    • ตัวแทนจำหน่ายเครื่องดื่ม
    • Hotel
    อสังหาริมทรัพย์
    • Real Estate Agency
    • บริษัทสถาปัตยกรรม
    • บริษัทรับเหมา
    • การจัดการอสังหาริมทรัพย์
    • การจัดสวน
    • สมาคมเจ้าของอสังหาริมทรัพย์
    ปรึกษา
    • สำนักงานบัญชี
    • Odoo พาร์ทเนอร์
    • เอเจนซี่การตลาด
    • สำนักงานกฎหมาย
    • บริการสรรหาบุคลากร
    • การตรวจสอบและการรับรอง
    ระบบการผลิต
    • Textile
    • เหล็ก
    • เฟอร์นิเจอร์
    • อาหาร
    • Brewery
    • ของขวัญขององค์กร
    สุขภาพ & ฟิตเนส
    • ชมรมกีฬา
    • ร้านขายแว่นตา
    • ฟิตเนส
    • ผู้ประกอบวิชาชีพด้านสุขภาพ
    • ร้านขายยา
    • ร้านทำผม
    Trades
    • ช่างซ่อม
    • ฮาร์ดแวร์และการสนับสนุนด้านไอที
    • ระบบพลังงานแสงอาทิตย์
    • ช่างทำรองเท้า
    • บริการทำความสะอาด
    • HVAC Services
    อื่น ๆ
    • Nonprofit Organization
    • สำนักงานสิ่งแวดล้อม
    • ร้านเช่าป้ายโฆษณา
    • การถ่ายภาพ
    • ร้านเช่าจักรยาน
    • ตัวแทนจำหน่ายซอฟต์แวร์
    Browse all Industries
  • คอมมูนิตี้
    ศึกษา
    • บทเรียน
    • เอกสารกำกับโปรแกรม
    • การรับรอง
    • การฝึกอบรม
    • บล็อก
    • พอดแคสต์
    เพิ่มศักยภาพให้กับการศึกษา
    • โปรแกรมการศึกษา
    • Scale Up! Business Game
    • เยี่ยมชม Odoo
    รับซอฟต์แวร์
    • ดาวน์โหลด
    • เปรียบเทียบรุ่น
    • เผยแพร่
    ทำงานร่วมกัน
    • Github
    • ฟอรั่ม
    • ระบบการจัดงานอีเวนต์
    • การแปล
    • ร่วมเป็นพาร์ทเนอร์
    • Services for Partners
    • ลงทะเบียนเพื่อสร้างบัญชีบริษัทของคุณ
    รับบริการ
    • ค้นหาพาร์ทเนอร์
    • ค้นหานักบัญชี
    • พบกับที่ปรึกษา
    • บริการติดตั้งระบบเพื่อใช้งาน
    • ข้อมูลอ้างอิงลูกค้า
    • การสนับสนุน
    • อัปเกรด
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    รับการสาธิต
  • ราคา
  • ช่วยเหลือ

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • ลูกค้าสัมพันธ์
  • e-Commerce
  • ระบบบัญชี
  • สินค้าคงคลัง
  • PoS
  • โปรเจกต์
  • MRP
All apps
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
ช่วยเหลือ

Issue: Return dynamic domain for field with on change method In Odoo 17

ติดตาม

รับการแจ้งเตือนเมื่อมีกิจกรรมในโพสต์นี้

คำถามนี้ถูกตั้งค่าสถานะ
domainonchangeodoo17
7 ตอบกลับ
14095 มุมมอง
อวตาร
Long Duong Nhat
I'm having a problem with returning the domain for the field when executing onchange method.
For the code below, it works fine on odoo version 14. But on odoo version 17, it doesn't work. Can you guys give me a solution to do this?
I want the service_request_ids field to display only according to the selected service_id.

service_id = fields.Many2one('ahamove.service', string='Service')
service_request_ids = fields.Many2many('ahamove.service.request', 'estimate_request_rel','choose_id', 'request_id', string='Request Type')

@api.onchange('service_id')
def _onchange_service_id(self):
for rec in self:
if rec.service_id:
return {'domain': {'service_request_ids': [('service_id', '=', rec.service_id.id)]}}
1
อวตาร
ละทิ้ง
อวตาร
Kiran K
คำตอบที่ดีที่สุด

Hi  Long Duong Nhat,

@api.onchange functions that return a domain have been deprecated from v17.

Check this alternative method,
https://github.com/odoo/odoo/blob/26239b2d0bdbc2f06d50f7739d61c490248b65bb/addons/account/models/account_tax.py#L1633C5-L1633C154


3
อวตาร
ละทิ้ง
Long Duong Nhat
ผู้เขียน

Hi Kiran K, thank you for your response. I will try your solution now.

อวตาร
Long Duong Nhat
ผู้เขียน คำตอบที่ดีที่สุด

Hi Dương Nguyễn, Kiran K,  Cybrosys Techno Solutions Pvt.Ltd,
Thank you very much for assisting me with different solutions. 
After testing all the solutions, I solved the problem most suitably (By compiling your solutions).

class ChooseDeliveryCarrier(models.TransientModel):
_inherit = 'choose.delivery.carrier'

​service_id = fields.Many2one('ahamove.service', string='Service')
​service_request_domain = fields.Binary(default=[])
​service_request_ids = fields.Many2many('ahamove.service.request', ​'estimate_request_rel','choose_id', 'request_id', string='Request Type')

@api.onchange('service_id')
​def _onchange_service_id(self):
​ ​for rec in self:
​ ​if rec.service_id:
​ ​rec.service_request_domain = [('service_id', '=', rec.service_id.id)]

widget="many2many_tags"
options="{'no_create': True}"
invisible="delivery_type != 'ahamove'"
domain="service_request_domain"
/>

Best regards,
Long Duong Nhat


1
อวตาร
ละทิ้ง
อวตาร
Cybrosys Techno Solutions Pvt.Ltd
คำตอบที่ดีที่สุด

Hi,


You can use the compute function instead like this:

service_id = fields.Many2one('ahamove.service', string='Service')

service_request_ids = fields.Many2many('ahamove.service.request', 'estimate_request_rel',

'choose_id', 'request_id', string='Request Type',                       compute='_compute_service_request_ids', store=True)

@api.depends('service_id')

def _compute_service_request_ids(self):

for rec in self:

if rec.service_id:

rec.service_request_ids = self.env['ahamove.service.request'].search([('service_id', '=', rec.service_id.id)])


Hope it helps


1
อวตาร
ละทิ้ง
Long Duong Nhat
ผู้เขียน

Hi Cybrosys, thank you for the solution. It seems to work, the service_request_ids are all loaded according to the correct service_id. However, service_request_ids is not selectable (it's read-only).

อวตาร
Dương Nguyễn
คำตอบที่ดีที่สุด

Does adding domain in field definition not work ?

service_request_ids = fields.Many2many(domain="[('service_id', '=', service_id)]")

This assume that service_request_ids containt service_id in it as m2o field

1
อวตาร
ละทิ้ง
Long Duong Nhat
ผู้เขียน

Hi Duong Nguyen, thank you for your response.
It (domain="[('service_id', '=', service_id)]") doesn't work. When I select it, it cannot load the record

Long Duong Nhat
ผู้เขียน

The relationship between service_id and service_request_ids are One2Many.
class AhamoveService(models.Model):
_name = 'ahamove.service'
request_ids = fields.One2many('ahamove.service.request', 'service_id', 'Requests')

class AhamoveServiceRequest(models.Model):
_name = 'ahamove.service.request'
service_id = fields.Many2one('ahamove.service', string='Service')

Dương Nguyễn

Which mean when user choose service_id on form view it will automatically load all related record of 'ahamove.service.request' which have that 'service_id'
If that so, i suggest using compute store with readonly=False

Long Duong Nhat
ผู้เขียน

Yes, that's right,
But as far as I understand,
domain="[('service_id', '=', service_id)]" and compute method is a form of the static domain. This means that every time you access the form, it will work as expected. But when you onchange service_id it will not work. I have tried doing this.

Dương Nguyễn

No, i haven't seen any one implement onchange method like you did.
Normally , when implement onchange , it will be used to change some other field value and the most important thing of onchange is not store on the database level.
So i guest u should remove your onchange method and do something like this
@api.depends('service_id')
def _compute_request_ids(self):
all_ahamove_service_request = self.env["ahamove.service.request"].search([("service_id", "in", self.service_id.ids)])
for r in self:
if r.service_id:
r.request_ids = all_ahamove_service_request.filtered(lambda req: req.service_id == r.service_id )
else:
r.request_ids = False

Long Duong Nhat
ผู้เขียน

Thanks Duong, I will try your solution now.

อวตาร
Adil Akbar
คำตอบที่ดีที่สุด

Hi, you can follow this: https://youtu.be/f3mq5fHRPT0

Hope it helps, Thanks

0
อวตาร
ละทิ้ง
Long Duong Nhat
ผู้เขียน

Thanks so much, Adil Akbar

อวตาร
Parth Tilokani
คำตอบที่ดีที่สุด

Why are you using binary field to store domain and do you think in xml it will render it in correct format and work? I have not tried the solution but I am curious about why take a binary field?

​service_request_domain = fields.Binary(default=[])
0
อวตาร
ละทิ้ง
อวตาร
Nicolás
คำตอบที่ดีที่สุด

Hi Long,
Thank you so much. I've been searching for days on how to implement this in Odoo 17.
I only added this to my "service_requests_ids" field in the XML view:

widget="many2many_tags"
options="{'no_create': True}"
domain="service_request_domain"

It is important to note that the "service_request_domain" must be included in the XML view file and set to invisible.

Best regards,
Nicolás

0
อวตาร
ละทิ้ง
Long Duong Nhat
ผู้เขียน

Hi Nicolás,
#python-code
class ChooseDeliveryCarrier(models.TransientModel):
_inherit = 'choose.delivery.carrier'

​service_id = fields.Many2one('ahamove.service', string='Service')
​service_request_domain = fields.Binary(default=[])
​service_request_ids = fields.Many2many('ahamove.service.request', ​'estimate_request_rel','choose_id', 'request_id', string='Request Type')

@api.onchange('service_id')
​def _onchange_service_id(self):
​ ​for rec in self:
​ ​if rec.service_id:
​ ​rec.service_request_domain = [('service_id', '=', rec.service_id.id)]

#xml-code
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_choose_delivery_carrier_form_with_provider" model="ir.ui.view">
<field name="name">view.choose.delivery.carrier.form.with.provider</field>
<field name="model">choose.delivery.carrier</field>
<field name="inherit_id" ref="delivery.choose_delivery_carrier_view_form" />
<field name="arch" type="xml">
<field name="carrier_id" position="after">
<field name="service_id"/>
<field name="service_request_ids" widget="many2many_tags" domain="service_request_domain"/>
<field name="service_request_domain" invisible="1"/>
</field>
</field>
</record>
</odoo>

Thanks and best regards,

สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!

สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!

ลงชื่อ
Related Posts ตอบกลับ มุมมอง กิจกรรม
How i can Apply onchange method on one2many field ?
domain onchange
อวตาร
อวตาร
1
ก.ย. 19
5198
Dynamic domain with Onchange doesn't show value when creating
domain onchange domain_filter
อวตาร
อวตาร
อวตาร
อวตาร
3
พ.ค. 24
6509
How to return a domain on field on onchange action ? แก้ไขแล้ว
domain onchange context
อวตาร
อวตาร
อวตาร
อวตาร
3
พ.ย. 24
46458
How to return domain on one2many field so that seleted values are not shown in next line
domain one2many onchange
อวตาร
1
เม.ย. 23
5936
onchange return domain for one2many product ID Field แก้ไขแล้ว
domain one2many onchange
อวตาร
อวตาร
อวตาร
อวตาร
7
เม.ย. 23
19884
คอมมูนิตี้
  • บทเรียน
  • เอกสารกำกับโปรแกรม
  • ฟอรั่ม
โอเพนซอร์ส
  • ดาวน์โหลด
  • Github
  • Runbot
  • การแปล
บริการ
  • โฮสติ้ง odoo.sh เซิร์ฟเวอร์
  • การสนับสนุน
  • อัปเกรด
  • การพัฒนาที่กำหนดเอง
  • การศึกษา
  • ค้นหานักบัญชี
  • ค้นหาพาร์ทเนอร์
  • ร่วมเป็นพาร์ทเนอร์
เกี่ยวกับเรา
  • บริษัทของเรา
  • ทรัพย์สินในรูปของเครื่องหมายการค้า
  • ติดต่อเรา
  • งาน
  • ระบบการจัดงานอีเวนต์
  • พอดแคสต์
  • บล็อก
  • ลูกค้า
  • กฎหมาย • ความเป็นส่วนตัว
  • ความปลอดภัย
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo เป็นชุดแอปธุรกิจแบบเปิดที่ครอบคลุมทุกความต้องการของบริษัทของคุณ อาธิ CRM eCommerce ระบบบัญชี ระบบสินค้าคงคลัง ระบบการขายหน้าร้าน โปรเจกต์ และ อีกมากมาย

ความเหนือกว่าอันเป็นเอกลักษณ์ของ Odoo คือการใช้งานที่ง่ายดายและผสานการทำงานอย่างสมบูรณ์แบบในเวลาเดียวกัน

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now