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

Small adjustments to existing module keep the browser loading unless I debug, then it works fine

By
Jeroen Nelen
on 8/6/14, 10:29 AM 857 views

Hello everyone,

There is a module called hr_timesheet_print in which you have the following function:

    def _get_tot_hours(self, ts_lines):
        from pydevd import pydevd
        pydevd.settrace('localhost', port=21000, stdoutToServer=True, stderrToServer=True)
        tot = 0.0
        deduced = 0.0
        for line in ts_lines:
            if line.product_uom_id:
                factor = line.product_uom_id.factor
                if factor == 0.0:
                    factor = 1.0
            else:
                factor = 1.0
            factor_invoicing = 1.0
            if line.to_invoice and line.to_invoice.factor != 0.0:
                factor_invoicing = 1.0 - line.to_invoice.factor / 100
            if factor_invoicing > 1.0:
                deduced += ((line.unit_amount / factor) * factor_invoicing)
                tot += ((line.unit_amount / factor) * factor_invoicing)
            elif factor_invoicing <= 1.0:
                tot += (line.unit_amount / factor)
                deduced += ((line.unit_amount / factor) * factor_invoicing)
        return {'total': total, 'deduced': total_deduced}

Because of the factor, this returns the total in days in stead of hours. So I would like it to return the total amount in hours. Therefore the only thing I have added are the two rules at the bottom:

 

def _get_tot_hours(self, ts_lines):
        from pydevd import pydevd
        pydevd.settrace('localhost', port=21000, stdoutToServer=True, stderrToServer=True)
        tot = 0.0
        deduced = 0.0
        for line in ts_lines:
            if line.product_uom_id:
                factor = line.product_uom_id.factor
                if factor == 0.0:
                    factor = 1.0
            else:
                factor = 1.0
            factor_invoicing = 1.0
            if line.to_invoice and line.to_invoice.factor != 0.0:
                factor_invoicing = 1.0 - line.to_invoice.factor / 100
            if factor_invoicing > 1.0:
                deduced += ((line.unit_amount / factor) * factor_invoicing)
                tot += ((line.unit_amount / factor) * factor_invoicing)
            elif factor_invoicing <= 1.0:
                tot += (line.unit_amount / factor)
                deduced += ((line.unit_amount / factor) * factor_invoicing)
        total = tot*factor #zodat het in uren wordt weergegeven
        total_deduced = deduced*factor #zodat het in uren wordt weergegeven

        return {'total': total, 'deduced': total_deduced}

When I run the project and debug the function, it works just fine. It also allows me to download the pdf after debugging.

However, as soon as I turn of the debugging and re-run the process (selecting rows and generating a print-out) the browser simply keeps loading the page and never seems to advance to show the download dialog. 

How can this work while debugging but not without debugging? 

After it is stuck, I refresh and go to another page, sometimes this does not cause any issues, but sometimes the entire environment seems bugged and simply stopping and starting the server (sudo /etc/init.d/openerp-server stop/start) seems to not do the trick, I have to kill any redundant openerp-server process that started (ps ax | grep openerp-server) before I can get the OpenERP version back up and running. 

I have seen this behavior before, when making changes to certain modules they seem to work fine while debugging but get stuck on loading screen when running without debugging.

Can anyone please provide further insight/advice? I have no idea what might be wrong. 

If you need additional information, please let me know.

 

Kind regards and have a nice day, 

 

0
Marvin Taboada
On 8/11/14, 5:50 PM

You are using "PyDev" debugging utilities there, which won't be available at running OpenERP standalone, please remove that.

Use Python built-in logging to avoid runtime dependencies, OpenERP uses it as well: https://docs.python.org/2/library/logging.html

0
Jeroen Nelen
On 8/11/14, 10:22 AM

What happen if you remove the first two lines in body function?

This indeed seems to no longer keep the page loading. It doesn't makes sense to me. THe only reason I can think of is that, altough I am not debugging, it still stops at one of the breakpoints? Because I also noticed that when debugging it also still stops at a line where there no longer is a breakpoint; Kind regards,

Jeroen Nelen
on 8/11/14, 10:24 AM

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

2 follower(s)

Stats

Asked: 8/6/14, 10:29 AM
Seen: 857 times
Last updated: 3/16/15, 8:10 AM