Files
odoo_source/addons/product_expiry
stcc-odoo 94cc077e21 [FIX] product_expiry: update expiry dates correctly
Steps to reproduce:

- Install product_expiry
- Create Product P:
	- Product type: Storable
	- Inventory tab > Tracking: By Lots
	- Check Expiration Date
	- Expiration Date: 100 days after receipt
	- Best Before Date, Removal Date, Alert Date: 10 days before
	expiration date
	- Save
- Products > Lots/Serial Numbers > New
	- Product: P
	- open Dates tab

There are two different usecases and issues starting from this point.

Usecase 1:
	- Dates tab, delete all dates, save
	- set the Expiration Date, all other dates are set
	- without saving, update the Expiration Date again

Issue 1: The other dates don't update according to the new Expiration Date. This happens because neither if conditions in `_compute_dates` match the case where the product has an expiration date set, but it has not been saved to the lot.

Solution 1: Add an additional condition in the `_compute_dates` method where `lot.expiration_date` is set, but `lot._origin.expiration_date` is not set. This will ensure the other dates are updated correctly when setting the Expiration Date without saving.

Usecase 2:
	- Dates tab, set an Expiration Date, save
	- Without saving the record, update the Expiration Date several times, with dates in the future

Issue 2: The other dates (Best Before Date, Removal Date, Alert Date) will drift off further in the future, while they should always be 10 days apart from the expiration date. This happens because the new dates are being set relative to the actual value of the date, which changes with each successive update.

Solution 2: set the new dates relative to the value of the `lot._origin` dates, which remain constant between successive (saveless) updates. This will ensure that the other dates maintain a 10-day difference from the Expiration Date consistently.

opw-3374135

closes odoo/odoo#130599

X-original-commit: a275cbcd2d8a87bbd8cadf85c094625ebd8358c4
Signed-off-by: Tiffany Chang <tic@odoo.com>
2023-08-03 10:43:23 +02:00
..
…
…