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 sales
order.
</p><p>
OpenERP will help you efficiently handle the complete sales flow:
quotation, sales order, delivery, invoicing and payment.
</p>
</field>
</record>

其中:

<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),
}

其中:

'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>

其中:

<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>

其中:

<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))))

openerp学习笔记 domain 的应用的更多相关文章

  1. openerp学习笔记 domain 增加扩展支持,例如支持 <field name="domain">[('type','=','get_user_ht_type()')]</field>

    示例代码1,ir_action_window.read : # -*- coding: utf-8 -*-from openerp.osv import fields,osv class res_us ...

  2. openerp学习笔记 计算字段支持搜索

    示例1: # -*- encoding: utf-8 -*-import poolerimport loggingimport netsvcimport toolslogger = netsvc.Lo ...

  3. openerp学习笔记 视图样式(表格行颜色、按钮,字段只读、隐藏,按钮状态、类型、图标、权限,group边距,聚合[合计、平均],样式)

    表格行颜色:             <tree string="请假单列表" colors="red:state == 'refuse';blue:state = ...

  4. openerp学习笔记 对象间关系【多对一(一对一)、一对多(主细结构)、多对多关系、自关联关系(树状结构)】

    1.多对一(一对一)关系:采购单与供应商之间的关系 'partner_id':fields.many2one('res.partner', 'Supplier', required=True, sta ...

  5. openerp学习笔记 统计、分析、报表(过滤条件向导、分组报表、图形分析、比率计算、追加视图排序)

    待解决:图形中当改变分组时,图例不正确            存储比率计算时,分组合计不正确 wizard:过滤条件向导,用于输入过滤条件 wizard/sale_chart.py # -*- cod ...

  6. openerp学习笔记 context 的应用

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

  7. openerp学习笔记 webkit 打印

    1.webkit 打印需要安装的支持模块 请首先安装 Webkit 报表引擎(report_webkit),再安装 Webkit 报表的支持库(report_webkit_lib),该模块讲自动安装和 ...

  8. openerp学习笔记 自定义小数精度(小数位数)

    小数位数标识定义: lx_purchase/data/lx_purchase_data.xml <?xml version="1.0" encoding="utf- ...

  9. openerp学习笔记 跟踪状态,记录日志,发送消息

    跟踪状态基础数据: kl_qingjd/kl_qingjd_data.xml <?xml version="1.0"?><openerp>    <d ...

随机推荐

  1. ping别的电脑出错

    原因ifconfig 电脑1:172.31.45.101 电脑2:172.31.188.232 http://ask.csdn.net/questions/178358 如何防止别人ping自己的电脑 ...

  2. 敏捷软件开发:原则、模式与实践——第9章 OCP:开放-封闭原则

    第9章 OCP:开放-封闭原则 软件实体(类.模块.函数等)应该是可以扩展的,但是不可修改. 9.1 OCP概述 遵循开放-封闭原则设计出的模块具有两个主要特征: (1)对于扩展是开放的(open f ...

  3. ACM 韩信点兵 、n的另一种阶乘、6174的问题

    3.6174问题 描述 假设你有一个各位数字互不相同的四位数,把所有的数字从大到小排序后得到a,从小到大后得到b,然后用a-b替换原来这个数,并且继续操作.例如,从1234出发,依次可以得到4321- ...

  4. ASP.NET Identity + Entity Framework 6 注意

    最近一个项目使用ASP.NET Identity + Entity Framework 6开发,本来一切正常. 某时注意到,更改密码功能程序执行起来没有问题,界面上也报修改密码成功,但实际上密码并没有 ...

  5. 构造复杂Lambda困惑之学会用LinqPad和Linqer实现Sql 和 Lambda之间的互转

    一:linq的话我们可能会遇到两个问题: 1. 我们的linq出现性能低下的时候,如果优化???? 我们写的linq所生成的sql是无法控制的... (要做性能优化,必须预先知道sql会生成啥样的?? ...

  6. (原创)用Microsoft Chart Controls(MSChart)实现曲线图,并支持拖动放大到秒

    Microsoft Chart Controls(简称MSChart)控件,给图形统计和报表图形显示提供了很好的解决办法,同时支持Web和WinForm两种方式. MSChart 在.NET 4.0自 ...

  7. Replication--无法将事务提升为分布式事务,因为在事务中有活动的保存点

    场景描述在SQL SERVER 2012上创建事务发布,发布库已搭建为可AWAYSON,分发服务器和发布服务器分离,创建发布时提示“无法将事务提升为分布式事务,因为在事务中有活动的保存点” 解决方法E ...

  8. ASP .Net Core 2.0 修改默认端口

    ASP .Net Core 的默认端口是5000,如果想在同一台服务器上运行多个实例,就不能都监听5000端口了,需要每一个实例都监听不同的端口.当然,如果您正在使用IIS或者Jexus来托管,可以不 ...

  9. Spring Boot - Spring Async

    除了使用Thread.Runnable.TimerTask.FeatureTask.CompletableFuture等类,在Spring Boot中还可以使用注解创建异步任务,可以减少线程处理的代码 ...

  10. Page.FindControl(string id) 与母版页结合后发现的一个问题

    MSDN上解释Page.FindControl(string id)方法用于查找指定ID的控件.例如: <asp:TextBox id="Email" runat=" ...