23.odoo入门——工作杂记

来源:互联网 发布:android 7.0源码 编辑:程序博客网 时间:2024/06/06 20:23

23————————

上午:

添加一个页面,里面有highcharts实现的图表,再画一个没有线的表格

再学习,测试git

下午:

问题1:odoo端实现一个需求:菜单中有2个项,往其中一项中输入数字,另外一项中根据一定的逻辑得到相应的数字

2个字段分别定义为onchange函数即可

实现代码如下:

#-----------------------装饰器函数,lwl----------------------------##onchange handler@api.onchange('each')def _onchange_each(self):    product_id = int(self.product_id)    total = 0    subscription_model = self.env['wens.investment.financing.subscription']    subscription_records = subscription_model.search([('product_id', '=', product_id)])    for item in subscription_records:        total += item.money    self.total = total * self.each@api.onchange('total')def _onchange_total(self):    product_id = int(self.product_id)    total = 0    subscription_model = self.env['wens.investment.financing.subscription']    subscription_records = subscription_model.search([('product_id', '=', product_id)])    for item in subscription_records:        total += item.money    if abs(total - 0) < 0.000001:        self.each = 0    else:        self.each = float(self.total) / total#-----------------------装饰器函数,lwl----------------------------#

关于装饰器,推荐博客:

https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014318435599930270c0381a3b44db991cd6d858064ac0000


问题2:实现了2个菜单数值的互相依赖,但是发现float类型的字段each只能显示2位小数,如何控制这个小数位数

请教了大佬,修改用法是:

each = fields.Float(string=u'每份分红',required=True, digits=(16, 5))

该字段其实在odoo/fields.py的源代码中有提到:

Some field attributes are automatically copied from the source field ifthey are not redefined: ``string``, ``help``, ``readonly``, ``required`` (onlyif all fields in the sequence are required), ``groups``, ``digits``, ``size``,``translate``, ``sanitize``, ``selection``, ``comodel_name``, ``domain``,``context``. All semantic-free attributes are copied from the sourcefield.

例如看代码:

class Float(Field):    """ The precision digits are given by the attribute    :param digits: a pair (total, decimal), or a function taking a database                   cursor and returning a pair (total, decimal)    """……

有时候感叹当个伸手党真爽,这种东西要查起来也挺麻烦- - !


问题3:在形如下图的表的列名中,字段是数据库的列名,这能否修改呢?

请教大佬,可以的,只要在xml的field字段中加入string属性就可以修改了,代码如下:

<field name="confirmed" string = '认购是否有效'/>

原创粉丝点击