版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_23931991/article/details/82219096
以批次(stock.production.lot)模型为测试模型,建立三个字段,分别如下:
class StockProductionLotInherit(models.Model):
_inherit = "stock.production.lot"
# 根据字段属性digits来定义精度(手工定义为2位)
float_digits = fields.Float(string='digits', help='digits', digits=(10, 2))
# 根据digits_compute来引用系统定义的精度 ('Product Unit of Measure'精度三位)
float_digits_compute = fields.Float(string='digits_compute', help='digits_compute',
digits_compute=dp.get_precision('Product Unit of Measure'))
# 测试计算字段是否会受字段定义的精度属性控制
float_compute = fields.Float(string='compute', help='compute', digits=(10, 2),
compute='_get_float_compute')
@api.one
@api.depends('float_digits', 'float_digits_compute',)
def _get_float_compute(self):
if self.float_digits and self.float_digits_compute:
self.float_compute = 0.12345678
未保存:
保存之后:
数据库存储值:
结论:
1.digits_compute 通过引用系统定义的精度值来动态引用精度值;
digits 可以通过手工定义具体精度值,也可以引用系统定义的精度
例:digits=dp.get_precision('Product Unit of Measure');
2. 计算字段添加精度定义没有意义,因为数据库不会存储,前台显示的位数受系统的默认位数;
3. py文件中定义字段属性中添加精度会影响数据库存储的精度,但是不会影响前台界面显示的精度位数;
xml中添加精度定义会影响前台显示的精度值,而不会影响数据库中的存储精度。
字段定义时添加的精度属性,会影响该字段在数据库中的存储精度;
字段在前台界面显示的精度受视图上的精度定义来控制(默认为2位);