This question has been flagged

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, 

 

Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer

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

Avatar
Discard

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,