Skip to content

Commit

Permalink
fixup! sale_stock_available_to_promise_release_block: add Unblock Rel…
Browse files Browse the repository at this point in the history
…ease wizard
  • Loading branch information
sebalix committed May 27, 2024
1 parent b09a14d commit ba847f6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ def test_sale_release_blocked(self):
self.assertTrue(self.sale.picking_ids.release_blocked)

def _create_unblock_release_wizard(
self, order_lines, date_deadline=None, from_order=None, option="free"
self, records=None, date_deadline=None, from_order=None, option="free"
):
wiz_form = Form(
self.env["unblock.release"].with_context(
from_sale_order_id=from_order and from_order.id,
active_model=order_lines._name,
active_ids=order_lines.ids,
active_model=records._name,
active_ids=records.ids,
default_option=option,
)
)
if date_deadline:
wiz_form.date_deadline = date_deadline
return wiz_form.save()

def test_sale_order_line_unblock_release_contextual(self):
def test_unblock_release_contextual(self):
self._set_stock(self.line.product_id, self.line.product_uom_qty)
self.sale.block_release = True
self.sale.action_confirm()
Expand All @@ -65,7 +65,33 @@ def test_sale_order_line_unblock_release_contextual(self):
self.assertNotEqual(old_picking, new_picking)
self.assertFalse(old_picking.exists())

def test_sale_order_line_unblock_release_free(self):
def test_unblock_release_contextual_update_date(self):
self._set_stock(self.line.product_id, self.line.product_uom_qty)
self.sale.block_release = True
self.sale.action_confirm()
# Unblock deliveries through the wizard, opened from another SO
# to define default values + update the proposed date
new_sale = self._create_sale_order()
new_sale.commitment_date = fields.Datetime.add(fields.Datetime.now(), days=1)
wiz = self._create_unblock_release_wizard(
self.sale.order_line, from_order=new_sale
)
self.assertEqual(wiz.option, "contextual")
self.assertEqual(wiz.date_deadline, new_sale.commitment_date)
self.assertNotEqual(wiz.order_line_ids.move_ids.date, new_sale.commitment_date)
old_picking = wiz.order_line_ids.move_ids.picking_id
new_date_deadline = fields.Datetime.add(fields.Datetime.now(), days=2)
wiz.date_deadline = new_date_deadline
wiz.validate()
# Deliveries have been scheduled to the new date deadline
new_picking = wiz.order_line_ids.move_ids.picking_id
self.assertEqual(wiz.order_line_ids.move_ids.date, new_sale.commitment_date)
self.assertNotEqual(old_picking, new_picking)
self.assertFalse(old_picking.exists())
# Commitment date on contextual order has been updated too
self.assertEqual(new_sale.commitment_date, new_date_deadline)

def test_unblock_release_free(self):
self._set_stock(self.line.product_id, self.line.product_uom_qty)
self.sale.block_release = True
self.sale.action_confirm()
Expand All @@ -84,16 +110,16 @@ def test_sale_order_line_unblock_release_free(self):
self.assertNotEqual(old_picking, new_picking)
self.assertFalse(old_picking.exists())

def test_sale_order_line_unblock_release_asap(self):
def test_unblock_release_asap(self):
# Start with a blocked SO having a commitment date in the past
self._set_stock(self.line.product_id, self.line.product_uom_qty)
self.sale.block_release = True
yesterday = fields.Datetime.subtract(fields.Datetime.now(), days=1)
self.sale.commitment_date = yesterday
self.sale.action_confirm()
# Unblock deliveries through the wizard
today = fields.Datetime.now()
wiz = self._create_unblock_release_wizard(self.sale.order_line, option="asap")
today = wiz.date_deadline
self.assertEqual(wiz.date_deadline, today)
self.assertNotEqual(wiz.order_line_ids.move_ids.date, today)
old_picking = wiz.order_line_ids.move_ids.picking_id
Expand All @@ -104,7 +130,30 @@ def test_sale_order_line_unblock_release_asap(self):
self.assertNotEqual(old_picking, new_picking)
self.assertFalse(old_picking.exists())

def test_sale_order_line_unblock_release_past_date_deadline(self):
def test_unblock_release_asap_from_moves(self):
# Same test than above but running the wizard from moves.
# Start with a blocked SO having a commitment date in the past
self._set_stock(self.line.product_id, self.line.product_uom_qty)
self.sale.block_release = True
yesterday = fields.Datetime.subtract(fields.Datetime.now(), days=1)
self.sale.commitment_date = yesterday
self.sale.action_confirm()
# Unblock deliveries through the wizard
today = fields.Datetime.now()
wiz = self._create_unblock_release_wizard(
self.sale.order_line.move_ids, option="asap"
)
self.assertEqual(wiz.date_deadline, today)
self.assertNotEqual(wiz.move_ids.date, today)
old_picking = wiz.move_ids.picking_id
wiz.validate()
# Deliveries have been scheduled for today
new_picking = wiz.move_ids.picking_id
self.assertEqual(wiz.move_ids.date, today)
self.assertNotEqual(old_picking, new_picking)
self.assertFalse(old_picking.exists())

def test_unblock_release_past_date_deadline(self):
self._set_stock(self.line.product_id, self.line.product_uom_qty)
self.sale.block_release = True
self.sale.action_confirm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,8 @@ def validate(self):
moves.action_unblock_release()
# Clean up empty deliveries
pickings.filtered(lambda o: not o.move_ids and not o.printed).unlink()
# Update commitment date of contextual sale order if any
from_sale_order_id = self.env.context.get("from_sale_order_id")
from_sale_order = self.env["sale.order"].browse(from_sale_order_id).exists()
if from_sale_order.state in ("draft", "sent"):
from_sale_order.commitment_date = self.date_deadline

0 comments on commit ba847f6

Please sign in to comment.