openerp学习笔记 自定义小数精度(小数位数)

openerp学习笔记 自定义小数精度(小数位数)openerp学习笔记 自定义小数精度(小数位数)
小数位数标识定义:

lx_purchase/data/lx_purchase_data.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data
noupdate="1">

<record
forcecreate="True" id="decimal_payment"
model="decimal.precision">
           
<field
name="name">lx_purchase_price</field>
           
<field
name="digits">2</field>
       
</record>

</data>
</openerp>

小数位数标识引用:

lx_purchase/lx_purchase.py

class lx_purchase_order_line(osv.osv):

def _amount_line(self, cr, uid, ids, prop, arg,
context=None):
       
res={}
        for line in
self.browse(cr,uid,ids,context=context):
           
a=self.read(cr,uid,line.id,["price","product_qty"])
           
res[line.id]=a["price"]*a["product_qty"]
       
return res

_name='lx.purchase.order.line'
   
_description=u"lx采购单明细"
   
_columns={
       
'order_id':fields.many2one('lx.purchase.order',u'采购单ID',select=True,
ondelete='cascade'),
       
'product':fields.char(u'产品',size=128,required=True),
       
'price':fields.float(u'价格', digits_compute =
dp.get_precision('lx_purchase_price'),
required=True),
       
'product_qty':fields.integer(u'数量',required=True),
       
'unit':
fields.char(u'计量单位',size=6),
       
'subtotal':fields.function(_amount_line, string=u'小计', digits=(18, 2)),
   
}
   
_defaults={
        'product_qty': lambda
*a: 1.0,
    }

lx_purchase_order_line()

自定义小数位数需引用的模块:

lx_purchase/__openerp__.py

    'depends' : ['base', 'hr', 'process', 'decimal_precision'],
#依赖的模块
    'data' :
[
       
'security/purchase_security.xml',
       
'security/ir.model.access.csv',
       
'data/lx_purchase_data.xml',
       
'lx_purchase_view.xml',
       
'lx_purchase_sequence.xml',
       
'lx_purchase_workflow.xml',
       
'lx_purchase_report.xml'
                   
], #模块安装、更新的时候会读入的文件

上一篇:CTSC && APIO 总结


下一篇:NOI2019省选模拟赛 第六场