Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastien Robin
erp5
Commits
d49ced68
Commit
d49ced68
authored
Feb 22, 2019
by
Sebastien Robin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inventory: fixed cases where an inventory forget to remove previous corrections
parent
b418885f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
162 additions
and
24 deletions
+162
-24
product/ERP5/Document/Inventory.py
product/ERP5/Document/Inventory.py
+25
-12
product/ERP5/tests/testInventoryModule.py
product/ERP5/tests/testInventoryModule.py
+137
-12
No files found.
product/ERP5/Document/Inventory.py
View file @
d49ced68
...
...
@@ -149,6 +149,8 @@ class Inventory(Delivery):
stock_object_list
=
[]
stock_append
=
stock_object_list
.
append
to_delete_stock_uid_set
=
set
()
to_delete_stock_uid_add
=
to_delete_stock_uid_set
.
add
for
inventory_calculation_dict
in
default_inventory_calculation_list
:
...
...
@@ -200,6 +202,8 @@ class Inventory(Delivery):
return
value
for
movement
in
method
():
# Make sure we remove any any value
to_delete_stock_uid_add
(
movement
.
getUid
())
if
movement
.
getResourceValue
()
is
not
None
and
\
movement
.
getInventoriatedQuantity
()
not
in
(
None
,
''
):
...
...
@@ -325,18 +329,27 @@ class Inventory(Delivery):
disable_archive
=
disable_archive
,
immediate_reindex_archive
=
immediate_reindex_archive
)
# Do deletion for everything first, even if there is no need to apply correction,
# in case we need to remove previous corrections
to_delete_stock_uid_add
(
self
.
getUid
())
to_delete_list
=
[]
to_delete_list_append
=
to_delete_list
.
append
for
uid
in
to_delete_stock_uid_set
:
temp_line
=
temp_constructor
(
self
,
inventory_id
)
temp_line
.
setUid
(
uid
)
to_delete_list_append
(
temp_line
)
catalog_kw
=
dict
(
sql_catalog_id
=
sql_catalog_id
,
disable_cache
=
1
,
check_uid
=
0
,
disable_archive
=
disable_archive
,
immediate_reindex_archive
=
immediate_reindex_archive
)
method_id_list
=
[
'z0_uncatalog_stock'
]
if
portal
.
portal_catalog
.
getSQLCatalog
(
sql_catalog_id
)
\
.
hasObject
(
'SQLCatalog_trimInventoryCacheOnCatalog'
):
method_id_list
.
append
(
'SQLCatalog_trimInventoryCacheOnCatalog'
)
# Delete existing stock records and old inventory_cache first.
portal
.
portal_catalog
.
catalogObjectList
(
to_delete_list
[:],
method_id_list
=
method_id_list
,
**
catalog_kw
)
if
stock_object_list
:
kw
=
dict
(
sql_catalog_id
=
sql_catalog_id
,
disable_cache
=
1
,
check_uid
=
0
,
disable_archive
=
disable_archive
,
immediate_reindex_archive
=
immediate_reindex_archive
)
method_id_list
=
[
'z0_uncatalog_stock'
]
if
portal
.
portal_catalog
.
getSQLCatalog
(
sql_catalog_id
)
\
.
hasObject
(
'SQLCatalog_trimInventoryCacheOnCatalog'
):
method_id_list
.
append
(
'SQLCatalog_trimInventoryCacheOnCatalog'
)
# Delete existing stock records and old inventory_cache first.
portal
.
portal_catalog
.
catalogObjectList
(
stock_object_list
[:],
method_id_list
=
method_id_list
,
**
kw
)
# Then insert new records without delete.
portal
.
portal_catalog
.
catalogObjectList
(
stock_object_list
,
method_id_list
=
(
'z_catalog_stock_list_without_delete_for_inventory_virtual_movement'
,
),
**
kw
)
stock_object_list
[:]
,
method_id_list
=
(
'z_catalog_stock_list_without_delete_for_inventory_virtual_movement'
,
),
**
catalog_
kw
)
\ No newline at end of file
product/ERP5/tests/testInventoryModule.py
View file @
d49ced68
...
...
@@ -53,6 +53,15 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
def
getInventoryModule
(
self
):
return
getattr
(
self
.
getPortal
(),
'inventory_module'
,
None
)
def
deliverPackingList
(
self
,
packing_list
):
"""step through all steps of packing list workflow."""
packing_list
.
confirm
()
packing_list
.
setReady
()
packing_list
.
start
()
packing_list
.
stop
()
packing_list
.
deliver
()
self
.
assertEqual
(
packing_list
.
getSimulationState
(),
'delivered'
)
def
stepCreateInitialMovements
(
self
,
sequence
=
None
,
**
kw
):
"""Create movements before this inventory.
"""
...
...
@@ -60,15 +69,6 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
splm
=
self
.
getPortal
().
sale_packing_list_module
iplm
=
self
.
getPortal
().
internal_packing_list_module
def
deliverPackingList
(
pl
):
"""step through all steps of packing list workflow."""
pl
.
confirm
()
pl
.
setReady
()
pl
.
start
()
pl
.
stop
()
pl
.
deliver
()
self
.
assertEqual
(
pl
.
getSimulationState
(),
'delivered'
)
# we create content :
# 1 purchase packing list
# 1 sale packing list
...
...
@@ -85,7 +85,7 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
resource_value
=
sequence
.
get
(
'resource'
),
quantity
=
month
*
10
)
# dummy quantity, it will be
# replaced by inventory
deliverPackingList
(
ppl
)
self
.
deliverPackingList
(
ppl
)
spl
=
splm
.
newContent
(
portal_type
=
'Sale Packing List'
,
...
...
@@ -97,7 +97,7 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
spl
.
newContent
(
portal_type
=
'Sale Packing List Line'
,
resource_value
=
sequence
.
get
(
'resource'
),
quantity
=
month
*
10
)
deliverPackingList
(
spl
)
self
.
deliverPackingList
(
spl
)
ipl
=
iplm
.
newContent
(
portal_type
=
'Internal Packing List'
,
...
...
@@ -109,7 +109,7 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
ipl
.
newContent
(
portal_type
=
'Internal Packing List Line'
,
resource_value
=
sequence
.
get
(
'resource'
),
quantity
=
month
*
10
)
deliverPackingList
(
ipl
)
self
.
deliverPackingList
(
ipl
)
def
createInventory
(
self
,
start_date
=
None
,
sequence
=
None
,
**
kw
):
...
...
@@ -619,6 +619,131 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
sequence_list
.
play
(
self
)
def
createInitialDeliveryForCheckingUselessCorrection
(
self
,
sequence
=
None
):
organisation
=
sequence
.
get
(
'organisation1'
)
from_organisation
=
sequence
.
get
(
'organsation2'
)
delivery
=
self
.
getPortal
().
internal_packing_list_module
.
newContent
(
portal_type
=
'Internal Packing List'
,
specialise
=
self
.
business_process
,
source_value
=
from_organisation
,
destination_value
=
organisation
,
start_date
=
DateTime
(
2019
,
02
,
20
),
)
resource_value
=
sequence
.
get
(
'resource'
)
delivery
.
newContent
(
portal_type
=
'Internal Packing List Line'
,
resource_value
=
resource_value
,
quantity
=
2
)
self
.
deliverPackingList
(
delivery
)
self
.
tic
()
return
delivery
def
stepCheckInventoryDoesNotKeepUselessCorrectionAtInventoryLevel
(
self
,
sequence
=
None
):
organisation
=
sequence
.
get
(
'organisation1'
)
resource_value
=
sequence
.
get
(
'resource'
)
delivery
=
self
.
createInitialDeliveryForCheckingUselessCorrection
(
sequence
=
sequence
)
def
getInventoryQuantity
():
return
self
.
getSimulationTool
().
getCurrentInventory
(
node_uid
=
organisation
.
getUid
(),
resource
=
resource_value
.
getRelativeUrl
())
self
.
assertEqual
(
2
,
getInventoryQuantity
())
inventory
=
self
.
getInventoryModule
().
newContent
()
inventory
.
edit
(
start_date
=
DateTime
(
2019
,
02
,
21
),
destination_value
=
organisation
,
full_inventory
=
True
)
inventory
.
deliver
()
self
.
tic
()
self
.
assertEqual
(
0
,
getInventoryQuantity
())
delattr
(
delivery
,
'workflow_history'
)
self
.
assertEqual
(
'draft'
,
delivery
.
getSimulationState
())
delivery
.
reindexObject
()
self
.
tic
()
inventory
.
reindexObject
()
self
.
tic
()
self
.
assertEqual
(
0
,
getInventoryQuantity
())
def
test_06_InventoryDoesNotKeepUselessCorrectionAtInventoryLevel
(
self
):
"""
We will create a movement, then a full inventory setting all stock to 0.
This will insert a correction line in stock table with uid of inventory.
But then, if initial movement is cancelled, a reindex of inventory must remove the correction
"""
sequence_list
=
SequenceList
()
# Test with a simple inventory without cell
sequence_string
=
'stepCreateNotVariatedResource
\
stepCreateOrganisation1
\
stepTic
\
stepCheckInventoryDoesNotKeepUselessCorrectionAtInventoryLevel'
sequence_list
.
addSequenceString
(
sequence_string
)
sequence_list
.
play
(
self
)
def
stepCheckInventoryDoesNotKeepUselessCorrectionAtLineLevel
(
self
,
sequence
=
None
):
organisation
=
sequence
.
get
(
'organisation1'
)
resource_value
=
sequence
.
get
(
'resource'
)
delivery
=
self
.
createInitialDeliveryForCheckingUselessCorrection
(
sequence
=
sequence
)
def
getInventoryQuantity
():
return
self
.
getSimulationTool
().
getCurrentInventory
(
node_uid
=
organisation
.
getUid
(),
resource
=
resource_value
.
getRelativeUrl
())
self
.
assertEqual
(
2
,
getInventoryQuantity
())
inventory
=
self
.
getInventoryModule
().
newContent
()
inventory
.
edit
(
start_date
=
DateTime
(
2019
,
02
,
21
),
destination_value
=
organisation
,
full_inventory
=
True
)
inventory_line
=
inventory
.
newContent
(
portal_type
=
'Inventory Line'
,
resource_value
=
resource_value
,
quantity
=
3
)
inventory
.
deliver
()
self
.
tic
()
self
.
assertEqual
(
3
,
getInventoryQuantity
())
delattr
(
delivery
,
'workflow_history'
)
self
.
assertEqual
(
'draft'
,
delivery
.
getSimulationState
())
delivery
.
reindexObject
()
self
.
tic
()
inventory
.
reindexObject
()
self
.
tic
()
self
.
assertEqual
(
3
,
getInventoryQuantity
())
# Even though this scenario might not really, happen, make sure the code does not
# keep a correction line for a resource which is not set any more
inventory_line
.
setResourceValue
(
None
)
inventory
.
reindexObject
()
self
.
tic
()
self
.
assertEqual
(
0
,
getInventoryQuantity
())
inventory_line
.
setResourceValue
(
resource_value
)
inventory
.
reindexObject
()
self
.
tic
()
self
.
assertEqual
(
3
,
getInventoryQuantity
())
# last safety check, make sure deletion of line of inventory has really an impact
inventory
.
manage_delObjects
(
ids
=
[
inventory_line
.
getId
()])
inventory
.
reindexObject
()
self
.
tic
()
self
.
assertEqual
(
0
,
getInventoryQuantity
())
def
test_07_InventoryDoesNotKeepUselessCorrectionAtLineLevel
(
self
):
"""
We will create a movement, then a full inventory changing stock value.
This will insert a correction line in stock table with uid of inventory line.
But then, if initial movement is cancelled, a reindex of inventory must remove the correction
"""
sequence_list
=
SequenceList
()
# Test with a simple inventory without cell
sequence_string
=
'stepCreateNotVariatedResource
\
stepCreateOrganisation1
\
stepTic
\
stepCheckInventoryDoesNotKeepUselessCorrectionAtLineLevel'
sequence_list
.
addSequenceString
(
sequence_string
)
sequence_list
.
play
(
self
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment