Skip to Content
Menu
This question has been flagged
2 Replies
7495 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.

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

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.

Author

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

I've update my reply.

Best Answer

Hello Odooers,

I think if you are dealing with Monetary fields, then you dont need any code change, only need to set proper

"Decimal Places" in currency settings.

Steps to change Subtotal fields (Monetary) decimal accuracy from 2 digit to 3 digits:

1. Activate Multi Currency from General Settings (Settings > General Settings > Accounting ('Invoicing' If Community)), Now activate Multi-Currencies from Currencies section.

2. Now go to Accounting ('Invoicing' If Community) > Configuration > Accounting > Currencies.

3. In currency form change value 0.010000 to 0.001000 in Rounding Factor field and save record.

I hope this will helpful.

--
Regards
Haresh Kansara
Odoo Application Engineer
  


Avatar
Discard