summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjem-odoo <jem@openerp.com>2018-09-14 11:18:09 +0200
committerjem-odoo <jem@openerp.com>2018-09-18 14:49:16 +0200
commitfe8893ed3d670fcec95a60a1389f89d2f370abfc (patch)
tree27aa5bd479449cef2553217b36183d716c18df9a
parentbf905014f738ff0b48f1aba6990006321723491a (diff)
[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.
-rw-r--r--addons/sale_timesheet/models/account_invoice.py17
1 files changed, 16 insertions, 1 deletions
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)
+ ]