Fill shipment number only in waiting state

Closes #12905
This commit is contained in:
Dimitrios Josef Moustos committed 2024-02-19 22:51:55 +01:00
1 parent a327edd0a5
commit 6206ef7bb0
7 files changed
+41 -60

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Fill shipment number only in waiting state
* Manage assignation for customer shipment with same picking and output location
* Add pblc argument to assign_try
+22 -55
View File
@@ -85,6 +85,23 @@ class ShipmentMixin:
table, _ = tables[None]
return [Coalesce(table.effective_date, table.planned_date)]
@classmethod
def set_number(cls, shipments):
'''
Fill the number field from sequence
'''
pool = Pool()
Config = pool.get('stock.configuration')
config = Config(1)
sequence = cls.__name__[len('stock.'):].replace('.', '_')
for shipment in shipments:
if not shipment.number:
shipment.number = config.get_multivalue(
sequence + '_sequence',
company=shipment.company.id).get()
cls.save(shipments)
def get_delay(self, name):
pool = Pool()
Date = pool.get('ir.date')
@@ -604,18 +621,8 @@ class ShipmentIn(
@classmethod
def create(cls, vlist):
pool = Pool()
Config = pool.get('stock.configuration')
vlist = [x.copy() for x in vlist]
config = Config(1)
default_company = cls.default_company()
for values in vlist:
if values.get('number') is None:
values['number'] = config.get_multivalue(
'shipment_in_sequence',
company=values.get('company', default_company)).get()
shipments = super(ShipmentIn, cls).create(vlist)
cls.set_number(shipments)
cls._set_move_planned_date(shipments)
return shipments
@@ -961,17 +968,6 @@ class ShipmentInReturn(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
@classmethod
def create(cls, vlist):
pool = Pool()
Config = pool.get('stock.configuration')
vlist = [x.copy() for x in vlist]
config = Config(1)
default_company = cls.default_company()
for values in vlist:
if values.get('number') is None:
values['number'] = config.get_multivalue(
'shipment_in_return_sequence',
company=values.get('company', default_company)).get()
shipments = super(ShipmentInReturn, cls).create(vlist)
cls._set_move_planned_date(shipments)
return shipments
@@ -1032,6 +1028,7 @@ class ShipmentInReturn(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
else:
assert all(m.shipment in shipments for m in moves)
Move.draft(moves)
cls.set_number(shipments)
cls._set_move_planned_date(shipments)
@classmethod
@@ -1508,6 +1505,7 @@ class ShipmentOut(
to_create.append(inventory_move)
if to_create:
Move.save(to_create)
cls.set_number(shipments)
def _get_inventory_move(self, move):
'Return inventory move for the outgoing move if necessary'
@@ -1742,17 +1740,6 @@ class ShipmentOut(
@classmethod
def create(cls, vlist):
pool = Pool()
Config = pool.get('stock.configuration')
vlist = [x.copy() for x in vlist]
config = Config(1)
default_company = cls.default_company()
for values in vlist:
if values.get('number') is None:
values['number'] = config.get_multivalue(
'shipment_out_sequence',
company=values.get('company', default_company)).get()
shipments = super(ShipmentOut, cls).create(vlist)
cls._set_move_planned_date(shipments)
return shipments
@@ -2140,18 +2127,8 @@ class ShipmentOutReturn(
@classmethod
def create(cls, vlist):
pool = Pool()
Config = pool.get('stock.configuration')
vlist = [x.copy() for x in vlist]
config = Config(1)
default_company = cls.default_company()
for values in vlist:
if values.get('number') is None:
values['number'] = config.get_multivalue(
'shipment_out_return_sequence',
company=values.get('company', default_company)).get()
shipments = super(ShipmentOutReturn, cls).create(vlist)
cls.set_number(shipments)
cls._set_move_planned_date(shipments)
return shipments
@@ -2624,17 +2601,6 @@ class ShipmentInternal(
@classmethod
def create(cls, vlist):
pool = Pool()
Config = pool.get('stock.configuration')
vlist = [x.copy() for x in vlist]
config = Config(1)
default_company = cls.default_company()
for values in vlist:
if values.get('number') is None:
values['number'] = config.get_multivalue(
'shipment_internal_sequence',
company=values.get('company', default_company)).get()
shipments = super().create(vlist)
cls._set_move_planned_date(shipments)
return shipments
@@ -2841,6 +2807,7 @@ class ShipmentInternal(
moves.append(move)
Move.save(moves)
cls.set_number(shipments)
cls._set_transit(shipments)
cls._sync_moves(shipments)
@@ -8,7 +8,7 @@ Imports::
>>> from proteus import Model, Report
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules
>>> from trytond.tests.tools import activate_modules, assertNotEqual
Activate modules::
@@ -59,6 +59,7 @@ Create a shipment::
>>> move.unit_price = Decimal('5')
>>> move.currency = company.currency
>>> shipment.save()
>>> assertNotEqual(shipment.number, None)
>>> len(shipment.incoming_moves)
1
@@ -9,7 +9,7 @@ Imports::
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules, assertEqual
>>> from trytond.tests.tools import activate_modules, assertEqual, assertNotEqual
>>> today = dt.date.today()
>>> yesterday = today - dt.timedelta(days=1)
@@ -65,9 +65,12 @@ Create Shipment In::
>>> move.company = company
>>> move.unit_price = Decimal('1')
>>> move.currency = company.currency
>>> shipment_return.save()
>>> shipment_return.number
>>> shipment_return.click('wait')
>>> shipment_return.state
'waiting'
>>> assertNotEqual(shipment_return.number, None)
Reschedule shipment::
@@ -9,7 +9,8 @@ Imports::
>>> from proteus import Model, Report
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules, assertEqual, set_user
>>> from trytond.tests.tools import (
... activate_modules, assertEqual, assertNotEqual, set_user)
>>> today = dt.date.today()
>>> yesterday = today - dt.timedelta(days=1)
@@ -82,12 +83,14 @@ Create Internal Shipment::
>>> move.to_location = storage_loc
>>> move.currency = company.currency
>>> shipment.save()
>>> shipment.number
>>> shipment.assigned_by
>>> shipment.done_by
>>> shipment.click('wait')
>>> shipment.state
'waiting'
>>> assertNotEqual(shipment.number, None)
>>> shipment.click('assign_try')
>>> shipment.state
'waiting'
@@ -9,7 +9,8 @@ Imports::
>>> from proteus import Model, Report
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules, assertEqual, set_user
>>> from trytond.tests.tools import (
... activate_modules, assertEqual, assertNotEqual, set_user)
>>> today = dt.date.today()
>>> yesterday = today - dt.timedelta(days=1)
@@ -96,6 +97,7 @@ Add two shipment lines of same product::
... move.unit_price = Decimal('1')
... move.currency = company.currency
>>> shipment_out.save()
>>> shipment_out.number
>>> shipment_out.picked_by
>>> shipment_out.packed_by
>>> shipment_out.done_by
@@ -103,6 +105,9 @@ Add two shipment lines of same product::
Set the shipment state to waiting::
>>> shipment_out.click('wait')
>>> shipment_out.state
'waiting'
>>> assertNotEqual(shipment_out.number, None)
>>> len(shipment_out.outgoing_moves)
2
>>> len(shipment_out.inventory_moves)
@@ -8,7 +8,7 @@ Imports::
>>> from proteus import Model, Report
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules
>>> from trytond.tests.tools import activate_modules, assertNotEqual
Activate modules::
@@ -62,6 +62,7 @@ Create Shipment Out Return::
>>> move.unit_price = Decimal('20')
>>> move.currency = company.currency
>>> shipment.save()
>>> assertNotEqual(shipment.number, None)
>>> len(shipment.incoming_moves)
1