diff --git a/CHANGELOG b/CHANGELOG index 9de887ed07..09f33f5728 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Merge supply into one wizard * Do not create production request if other order point exists Version 4.2.0 - 2016-11-28 diff --git a/__init__.py b/__init__.py index 594cae588b..0e08b0301a 100644 --- a/__init__.py +++ b/__init__.py @@ -13,9 +13,8 @@ def register(): LocationLeadTime, Configuration, Production, - CreateProductionRequestStart, Product, module='stock_supply_production', type_='model') Pool.register( - CreateProductionRequest, + StockSupply, module='stock_supply_production', type_='wizard') diff --git a/doc/index.rst b/doc/index.rst index 6b8ca25441..c09c4954b1 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -22,6 +22,6 @@ It adds a new type of Order Point: quantity is reached at any time on the warehouse it will result in a production request. -The production requests are created by the schedulers with respect to stock +The production requests are created by the supply wizard with respect to stock levels and existing requests. The stock levels are computed on the supply period define in the production configuration. diff --git a/production.py b/production.py index 08deb5f747..41eb115c71 100644 --- a/production.py +++ b/production.py @@ -3,14 +3,12 @@ import datetime from collections import defaultdict -from trytond.model import ModelView, fields +from trytond.model import fields from trytond.pool import Pool, PoolMeta from trytond.transaction import Transaction -from trytond.wizard import Wizard, StateView, StateAction, Button from trytond.tools import grouped_slice -__all__ = ['Configuration', 'Production', - 'CreateProductionRequestStart', 'CreateProductionRequest'] +__all__ = ['Configuration', 'Production'] class Configuration: @@ -119,8 +117,6 @@ class Production: req.save() req.set_moves() requests.append(req) - if requests: - cls.generate_requests(False, warehouses) return requests @classmethod @@ -211,52 +207,3 @@ class Production: current_qties[product_id] += qty return shortages - - -class CreateProductionRequestStart(ModelView): - 'Create Production Request' - __name__ = 'production.create_request.start' - - -class CreateProductionRequest(Wizard): - 'Create Production Requests' - __name__ = 'production.create_request' - start = StateView('production.create_request.start', - 'stock_supply_production.production_create_request_start_view_form', [ - Button('Cancel', 'end', 'tryton-cancel'), - Button('Create', 'create_', 'tryton-ok', default=True), - ]) - create_ = StateAction('stock_supply_production.act_production_request') - - @classmethod - def __setup__(cls): - super(CreateProductionRequest, cls).__setup__() - cls._error_messages.update({ - 'late_productions': 'There are some late productions.', - }) - - @property - def _requests_parameters(self): - return {} - - def do_create_(self, action): - pool = Pool() - Date = pool.get('ir.date') - Move = pool.get('stock.move') - Production = pool.get('production') - - today = Date.today() - if Move.search([ - ('from_location.type', '=', 'production'), - ('to_location.type', '=', 'storage'), - ('state', '=', 'draft'), - ('planned_date', '<', today), - ], order=[]): - self.raise_user_warning('%s@%s' % (self.__name__, today), - 'late_productions') - - Production.generate_requests(**self._requests_parameters) - return action, {} - - def transition_create_(self): - return 'end' diff --git a/production.xml b/production.xml index b648768c33..381ea47765 100644 --- a/production.xml +++ b/production.xml @@ -11,18 +11,6 @@ this repository contains the full copyright notices and license terms. --> production_configuration_form - - Create Production Requests - production.create_request - - - - production.create_request.start - form - production_create_request_start_form - - Request Productions production @@ -42,34 +30,5 @@ this repository contains the full copyright notices and license terms. --> - - - - user_cron_production_request - Cron Production Request - - - - - - - - - - Generate Production Requests - - - - - days - - - production - generate_requests - - diff --git a/stock.py b/stock.py index 3a1f5d607f..9f916be930 100644 --- a/stock.py +++ b/stock.py @@ -4,8 +4,9 @@ import datetime from trytond.pyson import Eval, If from trytond.pool import PoolMeta, Pool +from trytond.wizard import StateAction -__all__ = ['OrderPoint', 'LocationLeadTime'] +__all__ = ['OrderPoint', 'LocationLeadTime', 'StockSupply'] class OrderPoint: @@ -61,3 +62,49 @@ class LocationLeadTime: extra = super(LocationLeadTime, cls)._get_extra_lead_times() extra.append(datetime.timedelta(Configuration(1).supply_period or 0)) return extra + + +class StockSupply: + __metaclass__ = PoolMeta + __name__ = 'stock.supply' + + production = StateAction('stock_supply_production.act_production_request') + + @classmethod + def __setup__(cls): + super(StockSupply, cls).__setup__() + cls._error_messages.update({ + 'late_productions': 'There are some late productions.', + }) + + @classmethod + def types(cls): + return super(StockSupply, cls).types() + ['production'] + + def transition_create_(self): + pool = Pool() + Date = pool.get('ir.date') + Move = pool.get('stock.move') + today = Date.today() + if Move.search([ + ('from_location.type', '=', 'production'), + ('to_location.type', '=', 'storage'), + ('state', '=', 'draft'), + ('planned_date', '<', today), + ], order=[]): + self.raise_user_warning('%s@%s' % (self.__name__, today), + 'late_productions') + return super(StockSupply, self).transition_create_() + + @property + def _production_parameters(self): + return {} + + def generate_production(self, clean): + pool = Pool() + Production = pool.get('production') + return Production.generate_requests( + clean=clean, **self._production_parameters) + + def transition_production(self): + return self.next_action('production') diff --git a/tests/scenario_stock_supply_production.rst b/tests/scenario_stock_supply_production.rst index ea37a130dc..a123c095a3 100644 --- a/tests/scenario_stock_supply_production.rst +++ b/tests/scenario_stock_supply_production.rst @@ -63,7 +63,7 @@ The is no production request:: Create production request:: - >>> create_pr = Wizard('production.create_request') + >>> create_pr = Wizard('stock.supply') >>> create_pr.execute('create_') There is now a production request:: diff --git a/view/production_create_request_start_form.xml b/view/production_create_request_start_form.xml deleted file mode 100644 index a464c143d6..0000000000 --- a/view/production_create_request_start_form.xml +++ /dev/null @@ -1,8 +0,0 @@ - - -
- -