Search code examples
python-2.7odoo-9

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


I'm using odoo 9 and i have created in Settings -> Technical -> Database Structure -> Decimal Accuracy-> Account with digits 3 for subtotal rounding. Then i have added in sale.py price_subtotal = fields.Monetary(compute='_compute_amount', string='Subtotal', digits=dp.get_precision('Account')) . After that i updated the two modules sale and decimal_precision. But when i create a new saleorder there is no change in the subtotal rounding it display 2 digits instead of 3. Any help please i'm stuck with this problem for days now


Solution

  • When the parser tries to get the precision of the monetary field, first it looks for digits attribute.

    So to change the decimal precision you can add digitsattribute to the xml view.

    <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>