From b5e0fdfcb454e271edac910c664ff810d94d8682 Mon Sep 17 00:00:00 2001 From: Vishal Thacker Date: Thu, 21 Oct 2021 09:03:36 +0000 Subject: [PATCH] [IMP] sale_stock: DO deadline based on SO deadline When a Sale Order is created, if no deadline was set, the Delivery Order takes the SO expected date as deadline. However, before this commit, if the SO has a deadline and the user removes it, the DO deadline will not be recomputed. Now, the DO will take the SO expected date as it does at its creation. task-2581265 opw-2528705 closes odoo/odoo#74695 Signed-off-by: Arnold Moyaux --- addons/sale_stock/models/sale_order.py | 10 ++++++---- addons/sale_stock/tests/test_sale_stock_lead_time.py | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/addons/sale_stock/models/sale_order.py b/addons/sale_stock/models/sale_order.py index 13103791ca4..dc31e57b068 100644 --- a/addons/sale_stock/models/sale_order.py +++ b/addons/sale_stock/models/sale_order.py @@ -7,7 +7,7 @@ from datetime import timedelta from collections import defaultdict from odoo import api, fields, models, _ -from odoo.tools import float_compare, float_round +from odoo.tools import float_compare from odoo.exceptions import UserError @@ -110,10 +110,12 @@ class SaleOrder(models.Model): You should probably update the partner on this document.""") % addresses picking.activity_schedule('mail.mail_activity_data_warning', note=message, user_id=self.env.user.id) - if values.get('commitment_date'): + if 'commitment_date' in values: # protagate commitment_date as the deadline of the related stock move. # TODO: Log a note on each down document - self.order_line.move_ids.date_deadline = fields.Datetime.to_datetime(values.get('commitment_date')) + deadline_datetime = values.get('commitment_date') + for order in self: + order.order_line.move_ids.date_deadline = deadline_datetime or order.expected_date res = super(SaleOrder, self).write(values) if values.get('order_line') and self.state == 'sale': @@ -124,7 +126,7 @@ class SaleOrder(models.Model): to_log[order_line] = (order_line.product_uom_qty, pre_order_line_qty.get(order_line, 0.0)) if to_log: documents = self.env['stock.picking']._log_activity_get_documents(to_log, 'move_ids', 'UP') - documents = {k:v for k, v in documents.items() if k[0].state != 'cancel'} + documents = {k: v for k, v in documents.items() if k[0].state != 'cancel'} order._log_decrease_ordered_quantity(documents) return res diff --git a/addons/sale_stock/tests/test_sale_stock_lead_time.py b/addons/sale_stock/tests/test_sale_stock_lead_time.py index 3e993a1728f..579159c9721 100644 --- a/addons/sale_stock/tests/test_sale_stock_lead_time.py +++ b/addons/sale_stock/tests/test_sale_stock_lead_time.py @@ -197,3 +197,12 @@ class TestSaleStockLeadTime(TestSaleCommon, ValuationReconciliationTestCommon): self.assertEqual(pack.date_deadline, new_deadline) new_deadline -= timedelta(days=pick.move_ids[0].rule_id.delay) self.assertEqual(pick.date_deadline, new_deadline) + + # Removes the SO deadline and checks the delivery deadline is updated accordingly. + order.commitment_date = False + new_deadline = order.expected_date + self.assertEqual(out.date_deadline, new_deadline) + new_deadline -= timedelta(days=pack.move_ids.rule_id.delay) + self.assertEqual(pack.date_deadline, new_deadline) + new_deadline -= timedelta(days=pick.move_ids.rule_id.delay) + self.assertEqual(pick.date_deadline, new_deadline)