[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 561ee39356.
This commit is contained in:
jem-odoo
2018-09-18 14:49:16 +02:00
parent bf905014f7
commit fe8893ed3d
@@ -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)
]