2019-09-13  今天是中秋节,星期五
#自定义显示名称
def name_get(self):
result = []
for order in self:
rec_name = "%s(%s)"%(record.name,record.date_done)
result.append((record.id, rec_name))
return result # 新添加函数name_search
@api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
if not args:
args = []
products = []
if name:
positive_operators = ['=', 'ilike', '=ilike', 'like', '=like']
products = self.env['product.product']
if operator in positive_operators:
products = self.search([('name', 'ilike', name)] + args, limit=limit)
if not products:
products = self.search([('size', 'ilike', name)] + args, limit=limit)
if not products:
products = self.search([('material', 'ilike', name)] + args, limit=limit)
else:
products = self.search(args, limit=limit)
return products.name_get() #添加约束
from odoo.exceptions import ValidationError
@api.constrains('age')
def _check_something(self):
for record in self:
if record.age > 20:
raise ValidationError("Your record is too old: %s" % record.age) # all records passed the test, don't return anything #更新时间
@api.multi
def change_updatetime(self):
for order in self:
order.update_time=fields.Datetime.now() 在SQL语句里或ORM里 记录集要用tuple 不能用list
search([('id','in',tuple(ids)]) 调用mapped获取员工名字
return employee_ids.mapped('name') #获取用户组:self.user_has_groups('base.group_no_one') 看板默认分组当无此类型当值时也默认出现在看板里
#对于odoo12来说 group_expand='' 对于selection类型
state = fields.Selection([('a', "A"), ('b', "B"),('c', "C"), ('d', "D")], group_expand='_expand_states') def _expand_states(self, states, domain, order):
# return all possible states, in order
return [key for key, val in type(self).state.selection] #对于odoo12来说 group_expand='' 对于many2one类型
stage_id = fields.Many2one('crm.stage', string='Stage', ondelete='restrict', track_visibility='onchange', index=True,
domain="['|', ('team_id', '=', False), ('team_id', '=', team_id)]",
group_expand='_read_group_stage_ids', default=lambda self: self._default_stage_id())
@api.model
def _read_group_stage_ids(self, stages, domain, order):
""" Read group customization in order to display all the stages in the
kanban view, even if they are empty
"""
stage_ids = stages._search([], order=order, access_rights_uid=SUPERUSER_ID)
return stages.browse(stage_ids) #以超级用户身份创建记录
rent_as_superuser = self.env['library.book'].sudo() rent_as_superuser.create(vals) #获取当前用户对于的员工 employee = self.env.user.employee_ids[0] #对象 employee.id employee.name

按钮写法
@api.multi
def btn_import_wizard(self):
context = self._context.copy()
context.update({'related_field_name': 'order_id','import_model':'sale.order.line'})
return {
'type': 'ir.actions.act_window',
'name': (u'导入'),
'res_model': 'base.import.line.wizard',
'view_mode': 'form',
'target': 'new',
'context': context
}

向导里面的 函数,可以通过按钮里面的context传进来
@api.multi
def btm_confirm(self):
active_id = self._context.get('active_id')
res_model = self.env[self._context['import_model']]
related_field_name = self._context['related_field_name']


 <field name="discount" groups="base.group_no_one" string="Disc (%)"/>
<field name="invoice_line_tax_ids" widget="many2many_tags" options="{'no_create': True}" context="{'type':parent.type, 'tree_view_ref': 'account.account_tax_view_tree', 'search_view_ref': 'account.account_tax_view_search'}"
domain="[('type_tax_use','=','sale'),('company_id', '=', parent.company_id)]"/>
<field name="price_subtotal" string="Subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>

动作
<record id="sale_order_line_action" model="ir.actions.act_window">
<field name="name">search_sale_order_line</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.order.line</field>
<field name="view_mode">tree,form</field>
<field name="context">{'tree_view_ref':'sale_order_line_tree',
'form_view_ref':'sale_order_line_form'}
</field>
</record>


继承
<xpath expr="//header" position="inside">
<button name="btn_7" string="" type="object" class="oe_highlight oe_read_only" />
</xpath>

<xpath expr="//header/field[@name='order_id']" position="attributes">
<attribute name="readonly">1</attribute>
</xpath>

查看附件
<div class="o_attachment_preview" attrs="{'invisible': ['|',('type', '!=', 'in_invoice'),('state', '!=', 'draft')]}" />
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="activity_ids" widget="mail_activity"/>
<field name="message_ids" widget="mail_thread"/>
</div>



看板上的进度条:odoo11以上才有
<progressbar field="activity_state" colors='{"planned": "success", "overdue": "danger", "today": "warning"}'/>


 
 
 
 odoo学习链接
https://blog.csdn.net/weixin_38495451/article/details/88548613 ---odoo12 视图使用方式(一)

odoo12常用的方法的更多相关文章

  1. WebAPi添加常用扩展方法及思维发散

    前言 在WebAPi中我们通常需要得到请求信息中的查询字符串或者请求头中数据再或者是Cookie中的数据,如果需要大量获取,此时我们应该想到封装一个扩展类来添加扩展方法,从而实现简便快捷的获取. We ...

  2. StringUtils中的常用的方法

    org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...

  3. JOptionPane类提示框的一些常用的方法

    JOptionPane类提示框的一些常用的方法 XMLOracleSwing 最近在做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法. 很方便的,于是就简单的整理了 ...

  4. 常用js方法

    function dateGetter(name, size, offset, trim) { offset = offset || 0; return function (date) { var v ...

  5. jQuery操作Table tr td常用的方法

    虽然现在DIV+CSS进行页的布局大行其道,但是很多地方使用table还是有很多优势,用table展示数据是比较方便的,下面汇总了jQuery操作Table tr td常用的方法,熟记这些操作技巧,下 ...

  6. iOS常用公共方法

      iOS常用公共方法 字数2917 阅读3070 评论45 喜欢236 1. 获取磁盘总空间大小 //磁盘总空间 + (CGFloat)diskOfAllSizeMBytes{ CGFloat si ...

  7. org.apache.commons.lang.StringUtils中常用的方法

    org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...

  8. 常用js方法整理common.js

    项目中常用js方法整理成了common.js var h = {}; h.get = function (url, data, ok, error) { $.ajax({ url: url, data ...

  9. Java获取各种常用时间方法大全

    Java获取各种常用时间方法大全 package cc.javaweb.test; Java中文网,Java获取各种时间大全 import java.text.DateFormat; import j ...

随机推荐

  1. 【工具解析】瑞士军刀bettercap2.X_解析_第二期_内网钓鱼(嗅探)工具编写

    /文章作者:Kali_MG1937 CNBLOG博客:ALDYS4 QQ:3496925334/ 第一期: https://www.cnblogs.com/aldys4/p/14877783.html ...

  2. 2.docker下centos镜像

    1.下载并运行 # 交互模式下载并运行centos容器 $ docker run -it centos:latest /bin/bash 1.1 配置centos的环境别名 $ vi /etc/bas ...

  3. 深入理解Java中的反射机制和使用原理!详细解析invoke方法的执行和使用

    反射的概念 反射: Refelection,反射是Java的特征之一,允许运行中的Java程序获取自身信息,并可以操作类或者对象的内部属性 通过反射,可以在运行时获得程序或者程序中的每一个类型的成员活 ...

  4. 屌炸天,像写代码一样写PPT,一个小工具解决

    此文已经废,请移步升级版博文: markdown写ppt (史上最全)

  5. 深度解密:Java与线程的关系

    并发不一定要依赖多线程(如PHP的多进程并发),但在Java中谈论并发,大多数都与线程脱不开关系. 线程的实现 线程是CPU调度的基本单位,Thread类与大部分的Java API有显著的差别,它的所 ...

  6. 来了!STM32移植LuatOS,潘多拉示例全新教程

    进击的五月,继上期<使用Air724UG制作简易贪吃蛇>教程之后,@打盹的消防车 又为大家带来基于STM32的潘多拉LuatOS移植全新教程: 为什么使用潘多拉作为教程呢? STM32不能 ...

  7. 2020年11月CKA新题考试心得体会

    1 什么是CKA CKA,即Certificated Kubernetes Administrator,CNCF官方提供的Kubernetes技能认证,含金量还是不错的.还有CKAD,相对简单一些,没 ...

  8. Linux命令大全之帮助命令及压缩命令

    man(manual):帮助命令 help用于解释shell内部命令 格式:help shell内部命令 ls 命令  --help man 命令 info 命令 .zip    .gz    .bz ...

  9. 手写Spring Config,最终一战,来瞅瞅撒!

    上一篇说到了手写Spring AOP,来进行功能的增强,下面本篇内容主要是手写Spring Config.通过配置的方式来使用Spring 前面内容链接: 我自横刀向天笑,手写Spring IOC容器 ...

  10. 使用echarts时,鼠标首次移入屏幕会闪动,全屏会出现滚动条

    原因: 在echarts图表中出现tooltip时,画布的父标签(即:echarts.init()的标签)的有时宽高都会发生变化,导致相对布局的div可能大小发生变化(画布大小却不变),导致页面闪动. ...