Skip to Content
Menu
This question has been flagged

Hello guys,

I have this method who should be called when the user modify the field timesheet_ids.unit_amount.

But when the user modify the field timesheet_ids.unit_amount and clicks on "save", the method is not called ONE time but 3 times... Why?

At the end, my to_invoice_hours is calculated correctly and well stored in the database.

The code

class Task(models.Model):
_inherit = "project.task"
     _order = "id desc"

    @api.depends('timesheet_ids.unit_amount')
    def _to_invoice_hours_get(self):
        _logger.error("        _to_invoice_hours_get BEGIN")
        hours = 0
        for task in self.browse(self.ids):
           analytic_line_ids = self.env['account.analytic.line'].search([('task_id', 'in', [task.id]), ('to_invoice', '=', True)])
           for record in analytic_line_ids:
                hours = hours + record.unit_amount
        _logger.error("            hours :: %s", str(hours))
        _logger.error("        _to_invoice_hours_get END")
        self.to_invoice_hours = hours
 

    to_invoice_hours = fields.Float(compute='_to_invoice_hours_get', string='Hours To Invoice', store=True)


The log

2017-02-02 12:13:17,249 18232 ERROR odoo-10 odoo.addons.vtm2_invoiceable_timesheet_power.models.models:         _to_invoice_hours_get BEGIN

2017-02-02 12:13:17,250 18232 ERROR odoo-10 odoo.addons.vtm2_invoiceable_timesheet_power.models.models:             hours :: 0

2017-02-02 12:13:17,250 18232 ERROR odoo-10 odoo.addons.vtm2_invoiceable_timesheet_power.models.models:         _to_invoice_hours_get END

2017-02-02 12:13:17,254 18232 INFO odoo-10 werkzeug: 127.0.0.1 - - [02/Feb/2017 12:13:17] "POST /web/dataset/call_kw/project.task/onchange HTTP/1.0" 200 -

2017-02-02 12:13:17,391 18232 INFO odoo-10 werkzeug: 127.0.0.1 - - [02/Feb/2017 12:13:17] "POST /web/dataset/call_kw/account.analytic.line/search_read HTTP/1.0" 200 -

2017-02-02 12:13:17,599 18232 ERROR odoo-10 odoo.addons.vtm2_invoiceable_timesheet_power.models.models:         _to_invoice_hours_get BEGIN

2017-02-02 12:13:17,605 18232 ERROR odoo-10 odoo.addons.vtm2_invoiceable_timesheet_power.models.models:             hours :: 11.0

2017-02-02 12:13:17,605 18232 ERROR odoo-10 odoo.addons.vtm2_invoiceable_timesheet_power.models.models:         _to_invoice_hours_get END

2017-02-02 12:13:17,623 18232 ERROR odoo-10 odoo.addons.vtm2_invoiceable_timesheet_power.models.models:         _to_invoice_hours_get BEGIN

2017-02-02 12:13:17,626 18232 ERROR odoo-10 odoo.addons.vtm2_invoiceable_timesheet_power.models.models:             hours :: 0

2017-02-02 12:13:17,626 18232 ERROR odoo-10 odoo.addons.vtm2_invoiceable_timesheet_power.models.models:         _to_invoice_hours_get END


EDIT #1

the _to_invoice_hours_get method is triggered 2 times even if I modify the timesheet_ids.name field instead of the timesheet_ids.unit_amount field.

Avatar
Discard

I am facing a similar problem, I can’t figure out why

Related Posts Replies Views Activity
5
Jul 18
21020
0
Apr 18
30571
6
Jan 18
30328
0
Mar 17
12
1
Aug 15
5774