summaryrefslogtreecommitdiff
path: root/addons/product_expiry
diff options
context:
space:
mode:
authorsvs-odoo <svs@odoo.com>2019-11-05 09:54:20 +0000
committersvs-odoo <svs@odoo.com>2019-11-05 12:06:37 +0000
commit4d71fe100d9795cd68feea85fb4e5595b9e06bb7 (patch)
treea783744ffb49e3bba95c9ef273e49fcf81e685d7 /addons/product_expiry
parent2560c332ae06ae6286920bdb09127eb3df52db48 (diff)
[FIX] product_expiry: expiration date on receipt
How to reproduce: - Create a tracked product using expiration dates and don't set the `expiration_time` field; - Create a receipt for this product (using "Create New Lots/Serial Numbers") and confirm it; - Create a move line for this product and define an expiration date; - Valid the picking -> Traceback. The issue was as `expiration_time` isn't set on product, the production lot created on the receipt's validation don't have an `expiration_date`. So, if the `expiration_date` is set on the receipt move line, the production lot will try to get a time delta with its unset `expiration_date`, causing the traceback. task-2119330 closes odoo/odoo#39795 Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
Diffstat (limited to 'addons/product_expiry')
-rw-r--r--addons/product_expiry/models/production_lot.py2
-rw-r--r--addons/product_expiry/tests/test_stock_production_lot.py50
2 files changed, 51 insertions, 1 deletions
diff --git a/addons/product_expiry/models/production_lot.py b/addons/product_expiry/models/production_lot.py
index 062d696d95f..122c59bf7ba 100644
--- a/addons/product_expiry/models/production_lot.py
+++ b/addons/product_expiry/models/production_lot.py
@@ -103,7 +103,7 @@ class StockProductionLot(models.Model):
def _update_date_values(self, new_date):
if new_date:
- time_delta = new_date - self.expiration_date
+ time_delta = new_date - (self.expiration_date or fields.Datetime.now())
vals = self._get_date_values(time_delta)
vals['expiration_date'] = new_date
self.write(vals)
diff --git a/addons/product_expiry/tests/test_stock_production_lot.py b/addons/product_expiry/tests/test_stock_production_lot.py
index 84a9974ac8f..fda5ad4e34b 100644
--- a/addons/product_expiry/tests/test_stock_production_lot.py
+++ b/addons/product_expiry/tests/test_stock_production_lot.py
@@ -314,6 +314,56 @@ class TestStockProductionLot(TestStockCommon):
self.assertAlmostEqual(
apple_lot.alert_date, expiration_date - timedelta(days=6), delta=time_gap)
+ def test_04_2_expiration_date_on_receipt(self):
+ """ Test we can set an expiration date on receipt even if all expiration
+ date related fields aren't set on product. """
+ partner = self.env['res.partner'].create({
+ 'name': 'Apple\'s Joe',
+ 'company_id': self.env.ref('base.main_company').id,
+ })
+ # Unset some fields.
+ self.apple_product.expiration_time = False
+ self.apple_product.removal_time = False
+
+ expiration_date = datetime.today() + timedelta(days=30)
+ time_gap = timedelta(seconds=10)
+
+ # Receives a tracked production using expiration date.
+ picking_form = Form(self.env['stock.picking'])
+ picking_form.partner_id = partner
+ picking_form.picking_type_id = self.env.ref('stock.picking_type_in')
+ with picking_form.move_ids_without_package.new() as move:
+ move.product_id = self.apple_product
+ move.product_uom_qty = 4
+ receipt = picking_form.save()
+ receipt.action_confirm()
+
+ # Defines a date during the receipt.
+ move = receipt.move_ids_without_package[0]
+ line = move.move_line_ids[0]
+ self.assertEqual(move.use_expiration_date, True)
+ line.lot_name = 'Apple Box #3'
+ line.expiration_date = expiration_date
+ line.qty_done = 4
+
+ receipt._action_done()
+ # Get back the lot created when the picking was done...
+ apple_lot = self.env['stock.production.lot'].search(
+ [('product_id', '=', self.apple_product.id)],
+ limit=1,
+ )
+ # ... and checks all date fields are correctly set.
+ self.assertAlmostEqual(
+ apple_lot.expiration_date, expiration_date, delta=time_gap,
+ msg="Must be define even if the product's `expiration_time` isn't set.")
+ self.assertAlmostEqual(
+ apple_lot.use_date, expiration_date + timedelta(days=5), delta=time_gap)
+ self.assertEqual(
+ apple_lot.removal_date, False,
+ "Must be false as the `removal_time` isn't set on product.")
+ self.assertAlmostEqual(
+ apple_lot.alert_date, expiration_date + timedelta(days=4), delta=time_gap)
+
def test_05_confirmation_on_delivery(self):
""" Test when user tries to delivery expired lot, he/she gets a
confirmation wizard. """