Odoo Help

Welcome!

This community 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.

1

Qweb decimal point in reports

By
Erhuvwu Akpobaro
on 1/22/15, 9:36 AM 4,241 views

Hello i have created a custom module , and i dsplay the fields in a qweb report which i also created , the problem is when i look at the module i a normal list view data shows correctly like :

deposit :45.00

How ever if print the custom report : the data shown is 45.0

here is an example of my modules code :

from openerp.osv import fields,osv
from openerp import tools
class cm_rental_contracts(osv.osv):
    _name = "cm.rental.contracts"
    _description = "Camden Market Rental Contracts"
    _auto = False
    _columns = {
                 'name':fields.char('Name'),  
                 'address':fields.char('Address'),
                 'address2':fields.char('Address2'),
                 'state':fields.char('Town'),
                 'city':fields.char('City'),
                 'post_code':fields.char('Post Code'),
                 'country':fields.char('Country'),
                 'sale_items':fields.char('Items of Sale'),
                 'rent':fields.char('Rent'),
                 'outgoing':fields.char('Outgoing'),
                 'service_charge':fields.char('Service Charge'),
                 'contract_category':fields.char('Contracts Category'),
                 'deposit':fields.float('Deposit'),
                 'start_date':fields.date('Start Date'),
                 'units':fields.char('units'),
                 'invoicing_company':fields.char('Invoicing Company'),
                 'invoicing_company_number':fields.char('Invoicing Company Number')

 

here is an example of a line of in my qweb report in which calls data from my module and displays it :

 <font t-field ="o.rent" face="Arial, serif">:</font>

 

Is there any way to fix this ?

 

2
Yogesh
On 8/21/15, 3:38 PM

You can use python for format your decimal numbers. "t-esc" attribute in qweb allows you to write python code, eg:


<span t-esc="'%.2f'%(t.amount)"/></span> 

You can add some computation as well

<span t-esc="'%.2f'%(t.amount * 100)"/></span>



This will print value to exactly two decimal places


1

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 1/22/15, 10:06 AM

Try simmilar to (o.currency_id is mandatory):

<span t-field="o.deposit" t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>

0
Erhuvwu Akpobaro
On 1/22/15, 11:24 AM

Thanks guys , for the help both examples worked .

If worked, you vote and/or accept good answer or answers.

zbik
on 1/22/15, 12:09 PM
0
Kazim Mirza
On 1/22/15, 10:02 AM

Hello Erhuvwu Akpobaro

You need to import 
import openerp.addons.decimal_precision as dp

 'rent':fields.char('Rent') should be  'rent':fields.float('Rent',digits_compute= dp.get_precision('Account')),

Thank You

 

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/22/15, 9:36 AM
Seen: 4241 times
Last updated: 8/21/15, 3:40 PM