changeset 0fb7b188fb26 in modules/stock_supply:default
details:
https://hg.tryton.org/modules/stock_supply?cmd=changeset&node=0fb7b188fb26
description:
Add warehouses selection to supply stock wizard
issue10532
review353701002
diffstat:
CHANGELOG | 1 +
shipment.py | 9 ++++++++-
stock.py | 31 ++++++++++++++++++++++++++++---
view/supply_start_form.xml | 1 +
4 files changed, 38 insertions(+), 4 deletions(-)
diffs (108 lines):
diff -r 7a18e376bc58 -r 0fb7b188fb26 CHANGELOG
--- a/CHANGELOG Wed Apr 06 23:37:44 2022 +0200
+++ b/CHANGELOG Thu Apr 07 00:06:34 2022 +0200
@@ -1,3 +1,4 @@
+* Add warehouses selection to supply stock wizard
* Add support for Python 3.10
* Remove support for Python 3.6
diff -r 7a18e376bc58 -r 0fb7b188fb26 shipment.py
--- a/shipment.py Wed Apr 06 23:37:44 2022 +0200
+++ b/shipment.py Thu Apr 07 00:06:34 2022 +0200
@@ -13,7 +13,7 @@
__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 @@
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 @@
order_points = OrderPoint.search([
('type', '=', 'internal'),
])
+ order_points = [
+ op for op in order_points if op.location.warehouse in warehouses]
id2product = {}
product2op = {}
id2location = {}
diff -r 7a18e376bc58 -r 0fb7b188fb26 stock.py
--- a/stock.py Wed Apr 06 23:37:44 2022 +0200
+++ b/stock.py Thu Apr 07 00:06:34 2022 +0200
@@ -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 @@
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 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 -r 7a18e376bc58 -r 0fb7b188fb26 view/supply_start_form.xml
--- a/view/supply_start_form.xml Wed Apr 06 23:37:44 2022 +0200
+++ b/view/supply_start_form.xml Thu Apr 07 00:06:34 2022 +0200
@@ -5,4 +5,5 @@
<image name="tryton-question" xexpand="0" xfill="0"/>
<label string="Supply Stock?" id="supply"
yalign="0.0" xalign="0.0" xexpand="1"/>
+ <field name="warehouses" colspan="2"/>
</form>