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.

0

How put my function into custom report

By
dark
on 1/15/14, 7:44 PM 1,344 views

Hi boys, I have created custom module with 2 custom reports in sale.order object. I use openoffice for report edit. Now I need use custom python function for some fields in this report. (convertion of number into words.)

How can I change this function, when I need new field (wordprice for example.)

    # -*- coding: utf-8 -*-

import time

from openerp.report import report_sxw

class order(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context=None):
        super(order, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time, 
            'show_discount':self._show_discount,
        })

    def _show_discount(self, uid, context=None):
        cr = self.cr
        try: 
            group_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'sale', 'group_discount_per_so_line')[1]
        except:
            return False
        return group_id in [x.id for x in self.pool.get('res.users').browse(cr, uid, uid, context=context).groups_id]

report_sxw.report_sxw('report.sale.order1', 'sale.order', 'addons/pest_reports/report/sale_order1.rml', parser=order, header="external")

I have function in python :

def humanize(x):
some code here....

This function convert x into words - from 123 to "onehundredtwentythree". Now I use field [[ o.amount_total ]] in my report, which print : 123. How can I insert my humanize function into my python report file? For example [[ o.amount_total_humanized ]] which will use my custom "humanize" function?

Many thanks for help.

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

0 follower(s)

Stats

Asked: 1/15/14, 7:44 PM
Seen: 1344 times
Last updated: 3/16/15, 8:10 AM