[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 <arm@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user