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
เกี่ยวกับฟอรั่มนี้
ช่วยเหลือ

using function in domain filter

ติดตาม

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

คำถามนี้ถูกตั้งค่าสถานะ
functiondomain
4 ตอบกลับ
74974 มุมมอง
อวตาร
Muszik Adrián

i want to use a function's return as a domain filter.

'product_id' : fields.many2one('product.product', 'products', domain=[('id', 'in',lambda self,cr,uid,ids, context: self._get_technic_warehause(cr,uid,ids,context))])

like that but it sadly wont work.... this is the error i get

2013-12-07 09:59:49,686 16226 ERROR test werkzeug: Error on request:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 159, in run_wsgi
    execute(app)
  File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 146, in execute
    application_iter = app(environ, start_response)
  File "/opt/openerp/server/openerp/service/wsgi_server.py", line 417, in application
    return application_unproxied(environ, start_response)
  File "/opt/openerp/server/openerp/service/wsgi_server.py", line 403, in application_unproxied
    result = handler(environ, start_response)
  File "/opt/openerp/web/addons/web/http.py", line 528, in __call__
    return self.dispatch(environ, start_response)
  File "/opt/openerp/web/addons/web/http.py", line 487, in __call__
    return self.app(environ, start_wrapped)
  File "/usr/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 411, in __call__
    return self.app(environ, start_response)
  File "/opt/openerp/web/addons/web/http.py", line 553, in dispatch
    result = handler(request)
  File "/opt/openerp/web/addons/web/http.py", line 618, in <lambda>
    return lambda request: JsonRequest(request).dispatch(method)
  File "/opt/openerp/web/addons/web/http.py", line 251, in dispatch
    body = simplejson.dumps(response)
  File "/usr/share/pyshared/simplejson/__init__.py", line 321, in dumps
    return _default_encoder.encode(obj)
  File "/usr/share/pyshared/simplejson/encoder.py", line 237, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/share/pyshared/simplejson/encoder.py", line 311, in iterencode
    return _iterencode(o, 0)
  File "/usr/share/pyshared/simplejson/encoder.py", line 213, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <function <lambda> at 0x535c230> is not JSON serializable

the function returns a list of Ids, but here is the function itself:

def _get_technic_warehause(self, cr, uid,ids, context=None):
        data = self.browse(cr, uid, ids, context=context)[0]
        pdb.set_trace()
        if data.technic_id.id:
            location_obj = self.pool.get('stock.location')
            lines_ids = location_obj.search(cr, uid, [('user_id', '=', data.technic_id.id)])
            #res = {data['id'] : []}
            res = []
            for line_id in lines_ids:
                prod_info = location_obj._product_get(cr, uid, line_id, context=context)
                for prod_id in prod_info.keys():
                    if prod_info[prod_id] != 0.0:
                        #res[data['id']].append(prod_id)
                        res.append(prod_id)
            return res
        #return {}

is there anyway in openerp to make this work? I know that openerp doesn't allow function fields in domain filter sadly, but anyway to get around it?

1
อวตาร
ละทิ้ง
อวตาร
Henri-Maxime Ducoulombier
คำตอบที่ดีที่สุด

Hello there,

I found out how to (very simple) solve this problem. I'm working with Odoo v8 (I don't know if it's working with v7), and all you have to do is to define a function that will return a JSON serializable domain (in fact, a domain as if you had put it directly in your field definition). Here's me code :

class myClass(models.Model)

    ...

    @api.model
    def _getUserGroupId(self):
        return [('groups_id', '=', self.env.ref('module.xml_id').id)]

    rel_ids = fields.Many2many(comodel_name='res.users', relation='my_relation_table_name', column1='rel_id', column2='user_id', string='Relation field', domain=_getUserGroupId)

Hope this helps.

 

5
อวตาร
ละทิ้ง
อวตาร
klacus
คำตอบที่ดีที่สุด

Hi.

You can avoid the problem with the new field in python.  This field is must point a fiunction (field.function) and call the function with this. Call the procedure with this function, and the field will be get the result of the function. The doamin will be accept it, you need to hide the new field and you finish with this.

 

 

Sorry for the original hungarian post. :-) +2 pls. :-)

L.

1
อวตาร
ละทิ้ง
อวตาร
Abdul Nazar
คำตอบที่ดีที่สุด

Here i am going to give a example of filter employee by his related user.

In Python:

@api.model    def _get_emp_domain(self):
    domain = []    ctx = self.env.context
    if ('user' in self.env.context and 'user' in self.env.context and 'cond' in self.env.context) and ctx.get('val') and ctx.get('cond') and ctx.get('val'):
        domain = [(ctx.get('user'),ctx.get('cond'),ctx.get('val'))]
    return domain


employee_id = fields.Many2one('hr.employee', string="Employee", domain=lambda self:self._get_emp_domain(), required=True,  default=_get_employee)


In XML:

<record id="action_my_custom" model="ir.actions.act_window">

        <field name="name">My List</field>

        <field name="res_model">my.custom</field>

        <field name="view_type">form</field>

        <field name="view_mode">tree,form</field>

        <field name="domain">[('employee_id.user_id','=',uid)]</field>

        <field name="context">{'user': 'user_id','cond': '=','val': uid}</field>

        <field name="view_id" eval="False"/>

        <field name="search_view_id" ref="view_my_custom_filter"/>

    </record>


I hope it will be helpful for you....

 
          

0
อวตาร
ละทิ้ง
อวตาร
bernscheinder
คำตอบที่ดีที่สุด

Hi adrian,

Have you solved this bug please, I need something like this!

 

Sincerly,

0
อวตาร
ละทิ้ง
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!

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

ลงชื่อ
Related Posts ตอบกลับ มุมมอง กิจกรรม
New api search domain id and condition? แก้ไขแล้ว
function domain api
อวตาร
อวตาร
1
ต.ค. 15
10016
production of not enough materials for a PO
function
อวตาร
อวตาร
อวตาร
2
ก.ย. 25
1115
POS Product Category Community Edition
function
อวตาร
อวตาร
1
ก.ย. 25
1788
Options for collections management addons for museums or private collection
function
อวตาร
0
ก.ค. 25
1180
naked domain set up แก้ไขแล้ว
domain
อวตาร
อวตาร
อวตาร
อวตาร
3
ก.ค. 25
6020
คอมมูนิตี้
  • บทเรียน
  • เอกสารกำกับโปรแกรม
  • ฟอรั่ม
โอเพนซอร์ส
  • ดาวน์โหลด
  • 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