如何在销售订单 odoo 9 中为小计创建新的小数精度

How to create a new decimal accuracy for subtotal in sale order odoo 9

我正在使用 odoo 9,我在设置 -> 技术 -> 数据库结构 -> 小数精度 -> 帐户中创建了数字 3 进行小计舍入。然后我添加了 sale.py price_subtotal = fields.Monetary(compute='_compute_amount', string='Subtotal', digits=dp.get_precision('Account')) 。之后我更新了两个模块 saledecimal_precision。但是当我创建一个新的销售订单时,小计四舍五入没有变化,它显示 2 位数字而不是 3 位数字。任何帮助我现在都被这个问题困扰了好几天

解决方案是将字段类型从 Monetary 修改为 Floatprice_subtotal = fields.Float(compute='_compute_amount', string='Subtotal', digits=dp.get_precision('Account'))

当解析器尝试获取货币字段的精度时,它首先查找 digits 属性。

因此,要更改小数精度,您可以将 digits 属性添加到 xml 视图。

<record id="view_order_form_precision_3" model="ir.ui.view">
    <field name="name">view.order.form.precision</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">

        <xpath expr='//tree/field[@name="price_subtotal"]' position="attributes">
            <attribute name="digits">(14, 3)</attribute>
        </xpath>

        <field name="amount_untaxed" position="attributes">
            <attribute name="digits">(14, 3)</attribute>
        </field>

        <field name="amount_tax" position="attributes">
            <attribute name="digits">(14, 3)</attribute>
        </field>

        <field name="amount_total" position="attributes">
            <attribute name="digits">(14, 3)</attribute>
        </field>

    </field>
</record>