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 视图使用方式(一)

最新文章

  1. 使用COALESCE时注意left join为null的情况
  2. 【IOS】1.学前准备
  3. UIImage的简单用法和实际操作
  4. Lucene为不同字段指定不同分词器(转)
  5. 用CodeBlocks构建C项目时候出现的问题
  6. 51 nod 1203 JZPLCM
  7. [UOJ UNR#1]奇怪的线段树
  8. App阅读pdf和扫描二维码功能
  9. js之Ajax下载文件
  10. bootstrap 弹窗或者提示框插件 bootstrap-growl 和bootstrap-notify
  11. logistics回归简单应用(二)
  12. RelativeLayout中include 控件覆盖重叠的问题
  13. mysql 表中已经存在数据 修改字段类型 varchar(11) 改为 int(11)
  14. 使用SonarCloud对.NET Core项目进行静态代码分析
  15. 2019.01.17 bzoj1854: [Scoi2010]游戏(二分图匹配)
  16. Vue父子组件之间通信
  17. 8 stark组件 展示数据
  18. OSI参考模型和TCP/IP模型基本知识
  19. C# 四舍五入的理解
  20. nginx和php-fpm的用户权限

热门文章

  1. UiPath中恢复依赖项失败的解决方法
  2. 【Android编程】Java利用apktool编写Metasploit恶意后门注入工具
  3. Python使用websocket调用语音识别,语音转文字
  4. C#调用JAVA(一)制作jar包
  5. Redis之复制
  6. 第8章:深入理解Service
  7. Centos 6.5 GitLab安装配置搭建详细过程
  8. redis--hash的实现
  9. 6-x2 echo命令:将指定字符串输出到 STDOUT
  10. webView远程代码执行漏洞复现