Skip to content

Commit f67a3be

Browse files
committed
[FIX] sale_timesheet : Prevent linking not-invoiced timesheet to invoice
Steps to reproduce: - Create a recurring service (product) with invoicing policy set as 'Based on Timesheets' - Create a subscription using the created product - Create a task and link it to this subscription order - Timesheet 3 line in the task one in the past one on the same date of creation and one in the future. - Create an invoice for this order - Notice the quantity has been invoiced is the present timesheet line only - Notice that the 3 timesheet lines have all been validated Cause: This is happening because when trying to link the lines to the invoice we consider the timesheets within the date range that the user might have set in the create invoice wizard. https://github.com/odoo/odoo/blob/9a4ec08b9a6b07470747923d09adcf51f7e4cd6a/addons/sale_timesheet/wizard/sale_make_invoice_advance.py#L33-L51 https://github.com/odoo/odoo/blob/9a4ec08b9a6b07470747923d09adcf51f7e4cd6a/addons/sale_timesheet/models/sale_order.py#L153 Fix: In subscription we can use the last and next invoice dates if the user hasn't set a period for the invoice. opw-4523727 closes odoo#205782 X-original-commit: 09d76aa Related: odoo/enterprise#83333 Signed-off-by: Arnaud Joset (arj) <arj@odoo.com> Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
1 parent 7c7b0ea commit f67a3be

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

addons/sale_timesheet/models/account_move.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def _link_timesheets_to_invoice(self, start_date=None, end_date=None):
7777
"""
7878
for line in self.filtered(lambda i: i.move_type == 'out_invoice' and i.state == 'draft').invoice_line_ids:
7979
sale_line_delivery = line.sale_line_ids.filtered(lambda sol: sol.product_id.invoice_policy == 'delivery' and sol.product_id.service_type == 'timesheet')
80+
if not start_date and not end_date:
81+
start_date, end_date = self._get_range_dates(sale_line_delivery.order_id)
8082
if sale_line_delivery:
8183
domain = line._timesheet_domain_get_invoiced_lines(sale_line_delivery)
8284
if start_date:
@@ -85,3 +87,8 @@ def _link_timesheets_to_invoice(self, start_date=None, end_date=None):
8587
domain = expression.AND([domain, [('date', '<=', end_date)]])
8688
timesheets = self.env['account.analytic.line'].sudo().search(domain)
8789
timesheets.write({'timesheet_invoice_id': line.move_id.id})
90+
91+
def _get_range_dates(self, order):
92+
# A method that can be overridden
93+
# to set the start and end dates according to order values
94+
return None, None

0 commit comments

Comments
 (0)