changeset 21b09ae49100 in modules/stock:default details: https://hg.tryton.org/modules/stock?cmd=changeset;node=21b09ae49100 description: Add cron task to reschedule past shipments
issue9264 review325191002 diffstat: CHANGELOG | 1 + doc/index.rst | 13 ++++ ir.py | 6 ++ shipment.py | 52 ++++++++++++++++++ tests/scenario_stock_shipment_in_return.rst | 81 +++++++++++++++++++++++++++++ tests/scenario_stock_shipment_internal.rst | 14 +++++ tests/scenario_stock_shipment_out.rst | 14 +++++ tests/test_stock.py | 5 + 8 files changed, 186 insertions(+), 0 deletions(-) diffs (268 lines): diff -r a0633af5d79d -r 21b09ae49100 CHANGELOG --- a/CHANGELOG Mon Oct 12 09:42:48 2020 +0100 +++ b/CHANGELOG Mon Oct 12 19:20:33 2020 +0200 @@ -1,3 +1,4 @@ +* Add cron task to reschedule past shipments * Allow lost and found on inventory moves of shipments * Add waste locations on warehouses * Add warning to prevent move in the future diff -r a0633af5d79d -r 21b09ae49100 doc/index.rst --- a/doc/index.rst Mon Oct 12 09:42:48 2020 +0100 +++ b/doc/index.rst Mon Oct 12 19:20:33 2020 +0200 @@ -230,6 +230,13 @@ cancelled at any time. This also cancels all the moves. +Rescheduling Customer Shipments +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +It is possible to setup a cron task to reschedule customer shipments that are +planned for the past. By default they are rescheduled to today. + + Internal Shipment ----------------- @@ -260,6 +267,12 @@ cancelled at any time. This also cancels all the moves. +Rescheduling Internal Shipments +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +It is possible to setup a cron task to reschedule internal shipments that are +planned for the past. By default they are rescheduled to today. + Inventory ********* diff -r a0633af5d79d -r 21b09ae49100 ir.py --- a/ir.py Mon Oct 12 09:42:48 2020 +0100 +++ b/ir.py Mon Oct 12 19:20:33 2020 +0200 @@ -12,4 +12,10 @@ cls.method.selection.extend([ ('product.product|recompute_cost_price_from_moves', "Recompute Cost Price from Moves"), + ('stock.shipment.out|reschedule', + "Reschedule Customer Shipments"), + ('stock.shipment.in.return|reschedule', + "Reschedule Supplier Return Shipments"), + ('stock.shipment.internal|reschedule', + "Reschedule Internal Shipments"), ]) diff -r a0633af5d79d -r 21b09ae49100 shipment.py --- a/shipment.py Mon Oct 12 09:42:48 2020 +0100 +++ b/shipment.py Mon Oct 12 19:20:33 2020 +0200 @@ -834,6 +834,22 @@ cls.assign(shipments) return success + @classmethod + def _get_reschedule_domain(cls, date): + return [ + ('state', '=', 'waiting'), + ('planned_date', '<', date), + ] + + @classmethod + def reschedule(cls, date=None): + pool = Pool() + Date = pool.get('ir.date') + if date is None: + date = Date.today() + shipments = cls.search(cls._get_reschedule_domain(date)) + cls.write(shipments, {'planned_date': date}) + class ShipmentOut(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): "Customer Shipment" @@ -1407,6 +1423,22 @@ else: return False + @classmethod + def _get_reschedule_domain(cls, date): + return [ + ('state', '=', 'waiting'), + ('planned_date', '<', date), + ] + + @classmethod + def reschedule(cls, date=None): + pool = Pool() + Date = pool.get('ir.date') + if date is None: + date = Date.today() + shipments = cls.search(cls._get_reschedule_domain(date)) + cls.write(shipments, {'planned_date': date}) + class ShipmentOutReturn(ShipmentMixin, Workflow, ModelSQL, ModelView): "Customer Return Shipment" @@ -2446,6 +2478,26 @@ if to_write: Move.write(*to_write) + @classmethod + def _get_reschedule_domain(cls, date): + return [ + ('state', '=', 'waiting'), + ('planned_date', '<', date), + ] + + @classmethod + def reschedule(cls, date=None): + pool = Pool() + Date = pool.get('ir.date') + if date is None: + date = Date.today() + shipments = cls.search(cls._get_reschedule_domain(date)) + for shipment in shipments: + shipment.planned_date = date + shipment.planned_start_date = ( + shipment.on_change_with_planned_start_date()) + cls.save(shipments) + class Address(metaclass=PoolMeta): __name__ = 'party.address' diff -r a0633af5d79d -r 21b09ae49100 tests/scenario_stock_shipment_in_return.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/scenario_stock_shipment_in_return.rst Mon Oct 12 19:20:33 2020 +0200 @@ -0,0 +1,81 @@ +================================= +Stock Shipment In Return Scenario +================================= + +Imports:: + + >>> import datetime + >>> from dateutil.relativedelta import relativedelta + >>> from decimal import Decimal + >>> from proteus import Model + >>> from trytond.tests.tools import activate_modules + >>> from trytond.modules.company.tests.tools import create_company, \ + ... get_company + >>> today = datetime.date.today() + >>> yesterday = today - relativedelta(days=1) + +Activate modules:: + + >>> config = activate_modules('stock') + +Create company:: + + >>> _ = create_company() + >>> company = get_company() + +Create supplier:: + + >>> Party = Model.get('party.party') + >>> supplier = Party(name='Supplier') + >>> supplier.save() + +Create product:: + + >>> ProductUom = Model.get('product.uom') + >>> ProductTemplate = Model.get('product.template') + >>> Product = Model.get('product.product') + >>> unit, = ProductUom.find([('name', '=', 'Unit')]) + >>> template = ProductTemplate() + >>> template.name = 'Product' + >>> template.default_uom = unit + >>> template.type = 'goods' + >>> template.list_price = Decimal('20') + >>> template.save() + >>> product, = template.products + +Get stock locations:: + + >>> Location = Model.get('stock.location') + >>> storage_loc, = Location.find([('code', '=', 'STO')]) + >>> supplier_loc, = Location.find([('code', '=', 'SUP')]) + +Create Shipment In:: + + >>> ShipmentInReturn = Model.get('stock.shipment.in.return') + >>> shipment_return = ShipmentInReturn() + >>> shipment_return.planned_date = yesterday + >>> shipment_return.supplier = supplier + >>> shipment_return.from_location = storage_loc + >>> move = shipment_return.moves.new() + >>> move.product = product + >>> move.uom =unit + >>> move.quantity = 1 + >>> move.from_location = storage_loc + >>> move.to_location = supplier_loc + >>> move.company = company + >>> move.unit_price = Decimal('1') + >>> move.currency = company.currency + >>> shipment_return.click('wait') + >>> shipment_return.state + 'waiting' + +Reschedule shipment:: + + >>> Cron = Model.get('ir.cron') + >>> cron = Cron(method='stock.shipment.in.return|reschedule') + >>> cron.interval_number = 1 + >>> cron.interval_type = 'months' + >>> cron.click('run_once') + >>> shipment_return.reload() + >>> shipment_return.planned_date == today + True diff -r a0633af5d79d -r 21b09ae49100 tests/scenario_stock_shipment_internal.rst --- a/tests/scenario_stock_shipment_internal.rst Mon Oct 12 09:42:48 2020 +0100 +++ b/tests/scenario_stock_shipment_internal.rst Mon Oct 12 19:20:33 2020 +0200 @@ -197,3 +197,17 @@ >>> shipment_copy, = shipment.duplicate() >>> len(shipment_copy.moves) 1 + +Reschedule shipment:: + + >>> shipment_copy.planned_date = yesterday + >>> shipment_copy.click('wait') + >>> set_user(1) + >>> Cron = Model.get('ir.cron') + >>> cron = Cron(method='stock.shipment.internal|reschedule') + >>> cron.interval_number = 1 + >>> cron.interval_type = 'months' + >>> cron.click('run_once') + >>> shipment_copy.reload() + >>> shipment_copy.planned_date == today + True diff -r a0633af5d79d -r 21b09ae49100 tests/scenario_stock_shipment_out.rst --- a/tests/scenario_stock_shipment_out.rst Mon Oct 12 09:42:48 2020 +0100 +++ b/tests/scenario_stock_shipment_out.rst Mon Oct 12 19:20:33 2020 +0200 @@ -256,3 +256,17 @@ >>> inventory_move.effective_date == yesterday True +Reschedule shipment:: + + >>> shipment_copy, = shipment_out.duplicate() + >>> shipment_copy.planned_date = yesterday + >>> shipment_copy.click('wait') + >>> set_user(1) + >>> Cron = Model.get('ir.cron') + >>> cron = Cron(method='stock.shipment.out|reschedule') + >>> cron.interval_number = 1 + >>> cron.interval_type = 'months' + >>> cron.click('run_once') + >>> shipment_copy.reload() + >>> shipment_copy.planned_date == today + True diff -r a0633af5d79d -r 21b09ae49100 tests/test_stock.py --- a/tests/test_stock.py Mon Oct 12 09:42:48 2020 +0100 +++ b/tests/test_stock.py Mon Oct 12 19:20:33 2020 +0200 @@ -1557,4 +1557,9 @@ tearDown=doctest_teardown, encoding='utf-8', checker=doctest_checker, optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) + suite.addTests(doctest.DocFileSuite( + 'scenario_stock_shipment_in_return.rst', + tearDown=doctest_teardown, encoding='utf-8', + checker=doctest_checker, + optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) return suite