odoo/enterprise#80582

Created by Bugfix, Youssef Bashandy (yoba)
Merged at 4f9e69737e6706282c136bd8e941faf49b6f2f18

Statuses:

Linked pull requests
label
odoo-dev:18.0-opw-4523727-prevent_linking_all_timesheets-yoba
head
dd471d5c7dff14572353c9f0a37e55f05548e911
merged
7 months ago by Misc, Arnaud Joset (arj)
odoo/odoo odoo/enterprise
18.0 #205029 #80582
saas-18.1 #205782 #83333
saas-18.2 #209915 #85496
saas-18.3 #209950 #85515
saas-18.4
19.0
master #209975 #85533

[FIX] sale_subscription_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