1.在Action中定义,domain用于对象默认的搜索条件:

示例:

        <record id="action_orders" model="ir.actions.act_window"><field name="name">Sales Orders</field><field name="type">ir.actions.act_window</field><field name="res_model">sale.order</field><field name="view_type">form</field><field name="view_mode">tree,form,calendar,graph</field><field name="search_view_id" ref="view_sales_order_filter"/><field name="context">{}</field><field name="domain">[('state','not in',('draft','sent','cancel'))]</field><field name="help" type="html"><p class="oe_view_nocontent_create">Click to create a quotation that can be converted into a salesorder.</p><p>OpenERP will help you efficiently handle the complete sales flow:quotation, sales order, delivery, invoicing and payment.</p></field></record>

View Code

其中:

<field name="domain">[('state','not in',('draft','sent','cancel'))]</field>

定义了打开订单窗口时仅搜索不处于 ('draft','sent','cancel') 三种状态的订单。

2.在对象(或视图)的关联字段(many2one和many2many类型字段)中定义,字段值是关联表的id,domain用于过滤关联表的记录:

示例:

    _name = 'sale.order.line'_description = 'Sales Order Line'_columns = {'order_id': fields.many2one('sale.order', 'Order Reference', required=True, ondelete='cascade', select=True, readonly=True, states={'draft':[('readonly',False)]}),'name': fields.text('Description', required=True, readonly=True, states={'draft': [('readonly', False)]}),'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of sales order lines."),'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok', '=', True)], change_default=True),'invoice_lines': fields.many2many('account.invoice.line', 'sale_order_line_invoice_rel', 'order_line_id', 'invoice_id', 'Invoice Lines', readonly=True),'invoiced': fields.function(_fnct_line_invoiced, string='Invoiced', type='boolean',store={'account.invoice': (_order_lines_from_invoice, ['state'], 10),'sale.order.line': (lambda self,cr,uid,ids,ctx=None: ids, ['invoice_lines'], 10)}),'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price'), readonly=True, states={'draft': [('readonly', False)]}),'type': fields.selection([('make_to_stock', 'from stock'), ('make_to_order', 'on order')], 'Procurement Method', required=True, readonly=True, states={'draft': [('readonly', False)]},help="From stock: When needed, the product is taken from the stock or we wait for replenishment.\nOn order: When needed, the product is purchased or produced."),'price_subtotal': fields.function(_amount_line, string='Subtotal', digits_compute= dp.get_precision('Account')),'tax_id': fields.many2many('account.tax', 'sale_order_tax', 'order_line_id', 'tax_id', 'Taxes', readonly=True, states={'draft': [('readonly', False)]}),'address_allotment_id': fields.many2one('res.partner', 'Allotment Partner',help="A partner to whom the particular product needs to be allotted."),'product_uom_qty': fields.float('Quantity', digits_compute= dp.get_precision('Product UoS'), required=True, readonly=True, states={'draft': [('readonly', False)]}),'product_uom': fields.many2one('product.uom', 'Unit of Measure ', required=True, readonly=True, states={'draft': [('readonly', False)]}),'product_uos_qty': fields.float('Quantity (UoS)' ,digits_compute= dp.get_precision('Product UoS'), readonly=True, states={'draft': [('readonly', False)]}),'product_uos': fields.many2one('product.uom', 'Product UoS'),'discount': fields.float('Discount (%)', digits_compute= dp.get_precision('Discount'), readonly=True, states={'draft': [('readonly', False)]}),'th_weight': fields.float('Weight', readonly=True, states={'draft': [('readonly', False)]}),'state': fields.selection([('cancel', 'Cancelled'),('draft', 'Draft'),('confirmed', 'Confirmed'),('exception', 'Exception'),('done', 'Done')], 'Status', required=True, readonly=True,help='* The \'Draft\' status is set when the related sales order in draft status. \\n* The \'Confirmed\' status is set when the related sales order is confirmed. \\n* The \'Exception\' status is set when the related sales order is set as exception. \\n* The \'Done\' status is set when the sales order line has been picked. \\n* The \'Cancelled\' status is set when a user cancel the sales order related.'),'order_partner_id': fields.related('order_id', 'partner_id', type='many2one', relation='res.partner', store=True, string='Customer'),'salesman_id':fields.related('order_id', 'user_id', type='many2one', relation='res.users', store=True, string='Salesperson'),'company_id': fields.related('order_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True),}

View Code

其中:

'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok', '=', True)], change_default=True),

定义了关联选择产品时,仅显示可销售的产品。

3.在搜索视图中定义,domain用于自定义的搜索条件:

示例:

        <record id="view_sales_order_filter" model="ir.ui.view"><field name="name">sale.order.list.select</field><field name="model">sale.order</field><field name="arch" type="xml"><search string="Search Sales Order"><field name="name" string="Sales Order" filter_domain="['|',('name','ilike',self),('client_order_ref','ilike',self)]"/><filter icon="terp-mail-message-new" string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]"/><separator/><filter icon="terp-document-new" string="Quotations" name="draft" domain="[('state','in',('draft','sent'))]" help="Sales Order that haven't yet been confirmed"/><filter icon="terp-check" string="Sales" name="sales" domain="[('state','in',('manual','progress'))]"/><filter icon="terp-dolar_ok!" string="To Invoice" domain="[('state','=','manual')]" help="Sales Order ready to be invoiced"/><filter icon="terp-dolar_ok!" string="Done" domain="[('state','=','done')]" help="Sales Order done"/><separator/><filter string="My Sales Orders" domain="[('user_id','=',uid)]" help="My Sales Orders" icon="terp-personal" name="my_sale_orders_filter"/><field name="partner_id" filter_domain="[('partner_id', 'child_of', self)]"/><field name="user_id"/><field name="project_id"/><group expand="0" string="Group By..."><filter string="Customer" icon="terp-personal" domain="[]" context="{'group_by':'partner_id'}"/><filter string="Salesperson" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/><filter string="Status" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/><filter string="Order Date" icon="terp-go-month" domain="[]" context="{'group_by':'date_order'}"/></group></search></field></record>

View Code

其中:

<field name="name" string="Sales Order" filter_domain="['|',('name','ilike',self),('client_order_ref','ilike',self)]"/>

定义了在搜索视图中输入订单编号时,同时按订单编号和客户关联编号过滤。

<filter string="My Sales Orders" domain="[('user_id','=',uid)]" help="My Sales Orders" icon="terp-personal" name="my_sale_orders_filter"/>

定义了在搜索视图中选择"My Sales Orders"标签时,过滤销售员是当前登录用户的订单。

4.在记录规则中定义,domain用于定义用户对对象中记录访问的权限:

示例:

    <record model="ir.rule" id="sale_order_comp_rule"><field name="name">Sales Order multi-company</field><field name="model_id" ref="model_sale_order"/><field name="global" eval="True"/><field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field></record>

View Code

其中:

<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>

定义了用户仅允许查询订单中未指定分公司或订单中指定的分公司用户具有访问权限的销售订单。

5.domain表达式规则说明:

domain中的单个条件是一个三个元素组成的元组。
第一个是对象的一个column,也就是字段名;
第二个是比较运算符 “=, !=, >, >=, <, <=, like, ilike, in, not in, child_of, parent_left, parent_right“ ;
第三个就是用来比较的值了。
多个条件用“|”(or),“&”(and),“!”(no)逻辑运算符链接。
逻辑运算符作为前缀放置于条件前面。“|”与“&”必须两个条件链接,“!”对一个条件取反。默认逻辑运算符为“&”。

举个例子:

['|', ('project_id.privacy_visibility', '=', 'public'), '&', ('project_id.privacy_visibility', 'in', ['portal', 'followers']), '|', ('message_follower_ids','in', [user.partner_id.id]), ('user_id', '=', user.id), ]

写个容易看的方式:

[
'|',('project_id.privacy_visibility', '=', 'public'),

  '&',('project_id.privacy_visibility', 'in', ['portal', 'followers']),

  '|', ('message_follower_ids','in', [user.partner_id.id]),
      ('user_id', '=', user.id),
]


这个例子的意思是:

(('project_id.privacy_visibility', '=', 'public') or
(
('project_id.privacy_visibility', 'in', ['portal', 'followers']) and (('message_follower_ids','in', [user.partner_id.id]) or ('user_id', '=', user.id))))

转载于:https://www.cnblogs.com/cnshen/p/3189306.html

openerp学习笔记 domain 的应用相关推荐

  1. openerp学习笔记 context 的应用

    1.在Action中定义,context用于传递搜索条件和分组条件,在搜索视图中默认显示: 示例代码: <record model="ir.actions.act_window&quo ...

  2. 图像处理(二十四)Gradient Domain High Dynamic Range Compression学习笔记

    <Gradient Domain High Dynamic Range Compression>学习笔记 原文地址: 作者:hjimce 一.相关理论 本篇博文主要讲解基于梯度域编辑的HD ...

  3. Partial Adversarial Domain Adaptation学习笔记

    Partial Adversarial Domain Adaptation学习笔记 文章目录 Partial Adversarial Domain Adaptation学习笔记 tip Abstrac ...

  4. Importance Weighted Adversarial Nets for Partial Domain Adaptation学习笔记

    Importance Weighted Adversarial Nets for Partial Domain Adaptation学习笔记 文章目录 Importance Weighted Adve ...

  5. 知识图谱学习笔记(1)

    知识图谱学习笔记第一部分,包含RDF介绍,以及Jena RDF API使用 知识图谱的基石:RDF RDF(Resource Description Framework),即资源描述框架,其本质是一个 ...

  6. kvm虚拟化学习笔记(十七)之KVM到KVM之v2v迁移

    1.源KVM虚拟主机node1 (1).查看源KVM虚拟主机上的虚拟机列表,本文计划将CentOS6.5-01虚拟机迁移到其它KVM虚拟主机中. [root@node1 ~]# virsh list ...

  7. 《繁凡的深度学习笔记》前言、目录大纲 一文让你完全弄懂深度学习所有基础(DL笔记整理系列)

    <繁凡的深度学习笔记>前言.目录大纲 (DL笔记整理系列) 一文弄懂深度学习所有基础 ! 3043331995@qq.com https://fanfansann.blog.csdn.ne ...

  8. 一文弄懂元学习 (Meta Learing)(附代码实战)《繁凡的深度学习笔记》第 15 章 元学习详解 (上)万字中文综述

    <繁凡的深度学习笔记>第 15 章 元学习详解 (上)万字中文综述(DL笔记整理系列) 3043331995@qq.com https://fanfansann.blog.csdn.net ...

  9. JavaWeb学习笔记(十)--HttpServletRequest

    1. HttpServletRequest简介 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中 2. Ht ...

最新文章

  1. 无线分类新写法,是不是很吊@!
  2. Android 学习笔记之Volley开源框架解析(一)
  3. 设计模式之_Strategy_05
  4. Archive object standard check
  5. 哪些信用卡取现0手续费?
  6. AJAX,只是一种过渡技术吗?
  7. 为什么打不开_发票查重百科导出的发票台账为什么附件打不开?
  8. 2020年数字营销与商业增长白皮书
  9. 3-3.HDFS项目实战目标和要求
  10. Zookeeper的选举机制详解
  11. 测试人如何高效地设计自动化测试框架?
  12. NATAPP内网穿透
  13. 进制转换—任意进制乘法表
  14. 《经济机器是怎样运行的》笔记(二)
  15. visual studio 总是和搜狗输入法冲突
  16. [会员积分运营了解]各大主流电商平台会员及积分体系概况集合!
  17. vue3 watch 监听多值以及深度监听用法
  18. 凸包算法-------Graham扫描法
  19. 基于遗传算法在机器人路径规划中的应用研究(Matlab代码实现)
  20. 高级面试题--SpringBoot启动流程解析

热门文章

  1. 【库】/lib64/libc.so.6: version `GLIBC_2.14' not found问题
  2. 【Android】Android适配器之ArrayAdapter、SimpleAdapter和BaseAdapter的简单用法
  3. [Qt教程] 第31篇 网络(一)Qt网络编程简介
  4. ubuntu linux安装控制面板,在Ubuntu 20.04上安装Ajenti控制面板的方法
  5. pythonscrapy爬虫_零基础写python爬虫之使用Scrapy框架编写爬虫
  6. vue 中provide的用法_聊聊Vue中provide/inject的应用详解
  7. python split()方法_秘籍:10个Python字符串处理技巧(附代码)
  8. keepalived(6)——lvs和arrp集成操作(2)——完成
  9. POJ 3061 -- Subsequence(二分)
  10. 智能指针shared_ptr