Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! sale_s…
Browse files Browse the repository at this point in the history
…tock_available_to_promise_release_block: add Unblock Release wizard
  • Loading branch information
sebalix committed Aug 5, 2024
1 parent 666a153 commit 6a6dd72
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ def test_unblock_release_contextual(self):
all(not m.release_blocked for m in (existing_moves | new_moves))
)

def test_unblock_release_contextual_order_not_eligible(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
new_sale = self._create_sale_order()
self.env["sale.order.line"].create(
{
"order_id": new_sale.id,
"product_id": self.product.id,
"product_uom_qty": 50,
"product_uom": self.uom_unit.id,
}
)
new_sale.action_cancel()
wiz = self._create_unblock_release_wizard(
self.sale.order_line,
from_order=new_sale,
date_deadline=fields.Datetime.now(),
)
self.assertEqual(wiz.option, "manual")

def test_unblock_release_contextual_different_shipping_policy(self):
self._set_stock(self.line.product_id, self.line.product_uom_qty)
self.sale.block_release = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ def _constrains_date_deadline(self):
_("You cannot reschedule deliveries in the past.")
)

def _get_contextual_order(self):
"""Return the current and eligible sale order from the context."""
from_sale_order_id = self.env.context.get("from_sale_order_id")
order = self.env["sale.order"].browse(from_sale_order_id).exists()
if order and order.state not in ("sale", "done", "cancel"):
return order

def _selection_option(self):
options = [
("manual", "Manual"),
("automatic", "Automatic / As soon as possible"),
]
if self.env.context.get("from_sale_order_id"):
order = self._get_contextual_order()
if order:
options.append(("contextual", "Based on current order"))
return options

Expand All @@ -68,10 +76,9 @@ def default_get(self, fields_list):
res = super().default_get(fields_list)
active_model = self.env.context.get("active_model")
active_ids = self.env.context.get("active_ids")
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()
from_sale_order = self._get_contextual_order()
if from_sale_order:
res["order_id"] = from_sale_order_id
res["order_id"] = from_sale_order.id
if active_model == "sale.order.line" and active_ids:
res["order_line_ids"] = [(6, 0, active_ids)]
if active_model == "stock.move" and active_ids:
Expand Down

0 comments on commit 6a6dd72

Please sign in to comment.