From fe8893ed3d670fcec95a60a1389f89d2f370abfc Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Fri, 14 Sep 2018 11:18:09 +0200 Subject: [PATCH] [FIX] sale_timesheet: hook to invoice validated timesheet When invoicing only validated timesheet (enterprise feature), the actual code also link other non validated timesheet from the same Sale line. This is not correct. This commit provide a hook to extend the domain of timesheets to link correctly. This came from 561ee39356408cb7edcffc694291dd029f236e3f. --- addons/sale_timesheet/models/account_invoice.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/addons/sale_timesheet/models/account_invoice.py b/addons/sale_timesheet/models/account_invoice.py index 3fac8186edd..12a18f5524b 100644 --- a/addons/sale_timesheet/models/account_invoice.py +++ b/addons/sale_timesheet/models/account_invoice.py @@ -60,8 +60,23 @@ class AccountInvoiceLine(models.Model): if invoice_line.invoice_id.type == 'out_invoice' and invoice_line.invoice_id.state == 'draft': sale_line_delivery = invoice_line.sale_line_ids.filtered(lambda sol: sol.product_id.invoice_policy == 'delivery' and sol.product_id.service_type == 'timesheet') if sale_line_delivery: - timesheets = self.env['account.analytic.line'].search([('so_line', 'in', sale_line_delivery.ids), ('timesheet_invoice_id', '=', False), ('project_id', '!=', False)]) + domain = self._timesheet_domain_get_invoiced_lines(sale_line_delivery) + timesheets = self.env['account.analytic.line'].search(domain) timesheets.write({ 'timesheet_invoice_id': invoice_line.invoice_id.id, }) return invoice_line + + @api.model + def _timesheet_domain_get_invoiced_lines(self, sale_line_delivery): + """ Get the domain for the timesheet to link to the created invoice + :param sale_line_delivery: recordset of sale.order.line to invoice + :return a normalized domain + """ + return [ + '&', + ('so_line', 'in', sale_line_delivery.ids), + '&', + ('timesheet_invoice_id', '=', False), + ('project_id', '!=', False) + ]