odoo/enterprise#85515

Created by fw-bot
Merged at e5cce080c00f936ed5543dc930c4dc481f5cb99e

Statuses:

Linked pull requests
label
odoo-dev:saas-18.3-18.0-opw-4523727-prevent_linking_all_timesheets-yoba-436034-fw
head
fd57ed4b5ead196cf5dd2a7e48a94c3020f05495
merged
6 months ago by Bugfix, Youssef Bashandy (yoba)
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

[FW][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

Forward-Port-Of: #83333
Forward-Port-Of: #80582