How to modify the decimal precision in OpenERP?

By
Anirudh Lou
on 7/7/15, 5:06 AM 1,604 views

I did some changes on field behavior of sale order line. I try to modify subtotal by changing its decimal precision into four, how ever the result is still on two decimal precision.

Example output: 1 X 87.5833 the result subtotal is 87.5800

Following is my code chunk:

<record forcecreate="True" id="base_prices" model="decimal.precision">

<field name="name">Base Digits</field>

<field name="digits">4</field>

</record>

class sale_order_line(osv.osv)

...

'price_subtotal' : fields.function(_amount_line, string='Subtotal', digits_compute= dp.get_precision('Base Digits')),

...

Any help is much appreciated.

FEDERICO LEONI
On 7/7/15, 8:20 AM

I don't know if I've well understood your issue.

The first think coming in mind is that decimal accuracy for Product Price is set to 2 on Odoo. Obviously if you change the decimal accuracy on

`Settings --> Database Structure --> Decimal Accuracy`

you'll change it globally. If you just change to 4 digits to subtotal field I think Odoo will add just two '0' to the right because the rest of the fields were saved with 2 digits. Try to set 4 digit globally, create an order and see how Odoo compute it.

Second thing I can think is that somewhere Odoo do a round for values on module. I don't know in wich one you are working, you need to have a look on it yourself.

Edit:

The solution of your problem could be on sale.py. For example:

`    def _amount_all(self, cr, uid, ids, field_name, arg, context=None):        cur_obj = self.pool.get('res.currency')        res = {}        for order in self.browse(cr, uid, ids, context=context):            res[order.id] = {                'amount_untaxed': 0.0,                'amount_tax': 0.0,                'amount_total': 0.0,            }            val = val1 = 0.0            cur = order.pricelist_id.currency_id            for line in order.order_line:                val1 += line.price_subtotal                val += self._amount_line_tax(cr, uid, line, context=context)            res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val)            res[order.id]['amount_untaxed'] = cur_obj.round(cr, uid, cur, val1)            res[order.id]['amount_total'] = res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']        return res`

And

` def _amount_line(self, cr, uid, ids, field_name, arg, context=None):        tax_obj = self.pool.get('account.tax')        cur_obj = self.pool.get('res.currency')        res = {}        if context is None:            context = {}        for line in self.browse(cr, uid, ids, context=context):            price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)            taxes = tax_obj.compute_all(cr, uid, line.tax_id, price, line.product_uom_qty, line.product_id, line.order_id.partner_id)            cur = line.order_id.pricelist_id.currency_id            res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])        return res`

Where round function is used on all related voices you need to change. Since those are computed values the global decimal setting do not works. Good hunting.

Thanks for response. Actually I already did that, how ever it still appear to on two decimal format instead of four. What I want is that the result of my subtotal is in four decimal precision, for example if the result of sale order line when saved or confirmed is 87.853321 I want to show 87.8533 not 87.8500.

Anirudh Lou
on 7/8/15, 1:51 AM

I mean the result of subtotal, untaxed amount, taxes, total and balance I want them to be on four decimal precision.

Anirudh Lou
on 7/8/15, 1:54 AM

FEDERICO LEONI
on 7/9/15, 8:45 AM

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

1 follower(s)

Stats

 Asked: 7/7/15, 5:06 AM Seen: 1604 times Last updated: 3/18/18, 5:48 AM