This question has been flagged
6 Replies
36196 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 ?

 

Avatar
Discard
Best Answer

Hello 

You can take reference of below code

<span t-esc="sum(docs.mapped('amount'))" t-options='{"widget": "float", "precision": 2}'/>
Best Thanks,
Ankit H Gandhi.


Avatar
Discard

Thanks That's Work

Best Answer

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


Avatar
Discard
Best Answer

Try simmilar to (o.currency_id is mandatory):

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

Avatar
Discard
Author Best Answer

Thanks guys , for the help both examples worked .

Avatar
Discard

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

Best Answer

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

 

 

Avatar
Discard