odoo12常用的方法
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常用的方法的更多相关文章
- WebAPi添加常用扩展方法及思维发散
前言 在WebAPi中我们通常需要得到请求信息中的查询字符串或者请求头中数据再或者是Cookie中的数据,如果需要大量获取,此时我们应该想到封装一个扩展类来添加扩展方法,从而实现简便快捷的获取. We ...
- StringUtils中的常用的方法
org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...
- JOptionPane类提示框的一些常用的方法
JOptionPane类提示框的一些常用的方法 XMLOracleSwing 最近在做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法. 很方便的,于是就简单的整理了 ...
- 常用js方法
function dateGetter(name, size, offset, trim) { offset = offset || 0; return function (date) { var v ...
- jQuery操作Table tr td常用的方法
虽然现在DIV+CSS进行页的布局大行其道,但是很多地方使用table还是有很多优势,用table展示数据是比较方便的,下面汇总了jQuery操作Table tr td常用的方法,熟记这些操作技巧,下 ...
- iOS常用公共方法
iOS常用公共方法 字数2917 阅读3070 评论45 喜欢236 1. 获取磁盘总空间大小 //磁盘总空间 + (CGFloat)diskOfAllSizeMBytes{ CGFloat si ...
- org.apache.commons.lang.StringUtils中常用的方法
org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...
- 常用js方法整理common.js
项目中常用js方法整理成了common.js var h = {}; h.get = function (url, data, ok, error) { $.ajax({ url: url, data ...
- Java获取各种常用时间方法大全
Java获取各种常用时间方法大全 package cc.javaweb.test; Java中文网,Java获取各种时间大全 import java.text.DateFormat; import j ...
随机推荐
- 我的物联网大学【第二章】:Luat的出世
壹 启动火种 有一位软件行业的大神,名字叫做许小刚. 小刚是一位憨厚的年轻的码农,嵌入式.后端.前端,无所不能,是一个很牛的物联网全栈工程师,也是一家物联网软件公司的创始人兼CEO. 有次跟我.老陆. ...
- 小Z的袜子(hose) &&作业 (莫队)
莫队:一种非常优雅的暴力,时间复杂度一般情况下是n*根号n,还是很优秀的. 今天水了三道莫队题,对普通莫队有了些了解 1.莫队l和r为指针,维护当前区间的某些信息,一般可以是当前区间不同权值的个数,( ...
- 管理后台Vue
管理后台 遇到的问题 搭建 基于vue 3.0 Vue CLI 4.x Ant Design Vue 2.0 搭建后台管理系统 Ant Design Vue 2.0 npm i --save ant- ...
- 在vue项目中使用echarts
1.安装echarts依赖npm install echarts --save 2.在要使用的页面引入import echarts from 'echarts'v5之后使用 import * echa ...
- Docker与k8s的恩怨情仇(三)—后浪Docker来势汹汹
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 上一节我们为大家介绍了Cloud Foundry等最初的PaaS平台如何解决容器问题,本文将为大家展示Doc ...
- AIDL —— Android接口定义语言
AIDL:Android Interface Definition Language,即Android接口定义语言,是Android进程间通信比较常用的一种方式.翻译一下,就是为了让某个Service ...
- 【LeetCode每日一题 Day 5】5. 最长回文子串
大家好,我是编程熊,今天是LeetCode每日一题的第五天,一起学习LeetCode第五题<最长回文子串>. 题意 给你一个字符串 s,找到 s 中最长的回文子串. 示例 输入:s = & ...
- MySQL数据库快速入门与应用实战(阶段一)
MySQL数据库快速入门与应用实战(阶段一) 作者 刘畅 时间 2020-09-02 实验环境说明: 系统:centos7.5 主机名 ip 配置 slavenode3 172.16.1.123 4核 ...
- To_Heart—题解——AT2165
这是一篇解题报告 首先,看到标签,考虑二分答案. 我们二分答案(即塔顶的值),把大于或等于这个值的变为1,否则变为0. 很容易发现,如果塔顶的答案是1,那么就说明值可以更大,否则相反. 复制一波样例 ...
- nginx限流模块(防范DDOS攻击)
Nginx限流模式(防范DDOS攻击) nginx中俩个限流模块: 1.ngx_http_limit_req_module(按请求速率限流) 2.ngx_http_limit_conn_module( ...