diff --git a/CHANGELOG b/CHANGELOG
index d1b0274d3c..15ad2dc8c4 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+* Add warehouses selection to supply stock wizard
* Add support for Python 3.10
* Remove support for Python 3.6
diff --git a/shipment.py b/shipment.py
index 3983730f04..25bc648b7a 100644
--- a/shipment.py
+++ b/shipment.py
@@ -13,7 +13,7 @@ class ShipmentInternal(ModelSQL, ModelView):
__name__ = 'stock.shipment.internal'
@classmethod
- def generate_internal_shipment(cls, clean=True):
+ def generate_internal_shipment(cls, clean=True, warehouses=None):
"""
Generate internal shipments to meet order points defined on
non-warehouse location.
@@ -29,6 +29,11 @@ class ShipmentInternal(ModelSQL, ModelView):
Move = pool.get('stock.move')
LeadTime = pool.get('stock.location.lead_time')
+ if warehouses is None:
+ warehouses = Location.search([
+ ('type', '=', 'warehouse'),
+ ])
+
user_record = User(Transaction().user)
today = Date.today()
lead_time = LeadTime.get_max_lead_time()
@@ -43,6 +48,8 @@ class ShipmentInternal(ModelSQL, ModelView):
order_points = OrderPoint.search([
('type', '=', 'internal'),
])
+ order_points = [
+ op for op in order_points if op.location.warehouse in warehouses]
id2product = {}
product2op = {}
id2location = {}
diff --git a/stock.py b/stock.py
index f9de0d9898..e5dfd8c8b6 100644
--- a/stock.py
+++ b/stock.py
@@ -1,7 +1,7 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.i18n import gettext
-from trytond.model import ModelView
+from trytond.model import ModelView, fields
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.wizard import (
@@ -91,14 +91,24 @@ class Supply(Wizard):
def generate_internal(self, clean):
pool = Pool()
ShipmentInternal = pool.get('stock.shipment.internal')
- return ShipmentInternal.generate_internal_shipment(clean=clean)
+ # Use getattr because start is empty when run by cron
+ if getattr(self.start, 'warehouses', None):
+ warehouses = self.start.warehouses
+ else:
+ warehouses = None
+ return ShipmentInternal.generate_internal_shipment(
+ clean=clean, warehouses=warehouses)
def transition_internal(self):
return self.next_action('internal')
@property
def _purchase_parameters(self):
- return {}
+ parameters = {}
+ # Use getattr because start is empty when run by cron
+ if getattr(self.start, 'warehouses', None):
+ parameters['warehouses'] = self.start.warehouses
+ return parameters
def generate_purchase(self, clean):
pool = Pool()
@@ -113,3 +123,18 @@ class Supply(Wizard):
class SupplyStart(ModelView):
"Supply Stock"
__name__ = 'stock.supply.start'
+
+ warehouses = fields.Many2Many(
+ 'stock.location', None, None, "Warehouses",
+ domain=[
+ ('type', '=', 'warehouse'),
+ ],
+ help="If empty all warehouses are used.")
+
+ @classmethod
+ def default_warehouses(cls):
+ pool = Pool()
+ Location = pool.get('stock.location')
+ warehouse = Location.get_default_warehouse()
+ if warehouse:
+ return [warehouse]
diff --git a/view/supply_start_form.xml b/view/supply_start_form.xml
index d5d4cf9964..b7310246dc 100644
--- a/view/supply_start_form.xml
+++ b/view/supply_start_form.xml
@@ -5,4 +5,5 @@ this repository contains the full copyright notices and license terms. -->
+