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
Xiaowu Zhang
erp5
Commits
60860972
Commit
60860972
authored
Nov 20, 2024
by
Xiaowu Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_core: support date on line
idea is do a loop for different stop date
parent
78171b2c
Pipeline
#38210
failed with stage
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
176 additions
and
158 deletions
+176
-158
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.Inventory.py
...TemplateItem/portal_components/document.erp5.Inventory.py
+176
-158
No files found.
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.Inventory.py
View file @
60860972
...
...
@@ -143,12 +143,11 @@ class Inventory(Delivery):
if
method
is
not
None
:
default_inventory_calculation_list
=
method
()
if
temp_constructor
is
None
:
temp_constructor
=
lambda
self
,
id
,
*
args
,
**
kw
:
self
.
newContent
(
temp_object
=
True
,
portal_type
=
'Movement'
,
id
=
id
,
*
args
,
**
kw
)
stop_date
=
self
.
getStopDate
()
#
stop_date = self.getStopDate()
stock_object_list
=
[]
stock_append
=
stock_object_list
.
append
...
...
@@ -158,176 +157,189 @@ class Inventory(Delivery):
to_delete_list_append
=
to_delete_list
.
append
for
inventory_calculation_dict
in
default_inventory_calculation_list
:
# build a dict containing all inventory for this node
# group by resource/variation and then subvariation
current_inventory_list
=
\
portal
.
portal_simulation
.
getCurrentInventoryList
(
to_date
=
stop_date
,
connection_id
=
connection_id
,
**
inventory_calculation_dict
[
'inventory_params'
]
)
current_inventory_dict
=
{}
current_inventory_key_id_list
=
[
x
[
"key"
]
for
x
in
inventory_calculation_dict
[
'first_level'
]]
for
line
in
current_inventory_list
:
current_inventory_key
=
[
line
[
x
]
for
x
in
current_inventory_key_id_list
]
for
x
in
xrange
(
len
(
current_inventory_key
)):
if
current_inventory_key
[
x
]
is
None
:
current_inventory_key
[
x
]
=
""
current_inventory_key
=
tuple
(
current_inventory_key
)
if
"second_level"
in
inventory_calculation_dict
:
# two level of variation
try
:
current_inventory_by_sub_variation
=
\
current_inventory_dict
[
current_inventory_key
]
except
KeyError
:
current_inventory_by_sub_variation
=
\
current_inventory_dict
[
current_inventory_key
]
=
{}
second_level_key_id_list
=
[
x
[
'key'
]
for
x
in
inventory_calculation_dict
[
'second_level'
]]
second_level_key
=
tuple
([
line
[
x
]
for
x
in
second_level_key_id_list
])
current_inventory_by_sub_variation
[
second_level_key
]
=
line
[
'total_quantity'
]
else
:
# only one level of variation
current_inventory_dict
[
current_inventory_key
]
=
line
[
'total_quantity'
]
# Browse all movements on inventory and create diff line when necessary
if
self
.
isFullInventory
():
not_used_inventory_dict
=
current_inventory_dict
else
:
not_used_inventory_dict
=
{}
inventory_id
=
self
.
getId
()
stop_date_list
=
[]
list_method
=
inventory_calculation_dict
[
'list_method'
]
method
=
getattr
(
self
,
list_method
)
__order_id_counter_list
=
[
0
]
def
getOrderIdCounter
():
value
=
__order_id_counter_list
[
0
]
# pylint: disable=cell-var-from-loop
__order_id_counter_list
[
0
]
=
value
+
1
# pylint: disable=cell-var-from-loop
return
value
for
movement
in
method
():
if
movement
.
getResourceValue
()
is
not
None
and
\
movement
.
getInventoriatedQuantity
()
not
in
(
None
,
''
):
movement_quantity
=
movement
.
getInventoriatedQuantity
(
)
# construct key to retrieve inventory into dict
getter_list
=
[
x
[
'getter'
]
for
x
in
inventory_calculation_dict
[
'first_level'
]]
key_list
=
[]
for
getter
in
getter_list
:
method
=
getattr
(
movement
,
getter
,
None
)
if
method
is
not
None
:
key_list
.
append
(
method
())
inventory_value
=
current_inventory_dict
.
get
(
tuple
(
key_list
),
0
)
second_key_list
=
[]
if
'second_level'
in
inventory_calculation_dict
:
if
inventory_value
==
0
:
inventory_value
=
{}
# two level
second_getter_list
=
[
x
[
'getter'
]
for
x
in
inventory_calculation_dict
[
'second_level'
]]
for
getter
in
second_getter_list
:
method
=
getattr
(
movement
,
getter
,
None
)
if
method
is
not
None
:
second_key_list
.
append
(
method
())
second_key_list
=
tuple
(
second_key_list
)
if
second_key_list
in
inventory_value
:
total_quantity
=
inventory_value
.
pop
(
second_key_list
)
# Put remaining subvariation in a dict to know which one
# to removed at end
not_used_inventory_dict
[
tuple
(
key_list
)]
=
inventory_value
diff_quantity
=
movement_quantity
-
total_quantity
else
:
# Inventory for new resource/variation/sub_variation
diff_quantity
=
movement_quantity
# Put remaining subvariation in a dict to know which one
# to removed at end
not_used_inventory_dict
[
tuple
(
key_list
)]
=
inventory_value
if
(
movement
.
getResourceValue
()
is
not
None
)
and
(
movement
.
getInventoriatedQuantity
()
not
in
(
None
,
''
)):
stop_date
=
movement
.
getStopDate
()
if
stop_date
not
in
stop_date_list
:
stop_date_list
.
append
(
stop_date
)
stop_date_list
=
sorted
(
stop_date_list
)
for
stop_date
in
stop_date_list
:
# build a dict containing all inventory for this node
# group by resource/variation and then subvariation
current_inventory_list
=
\
portal
.
portal_simulation
.
getCurrentInventoryList
(
to_date
=
stop_date
,
connection_id
=
connection_id
,
**
inventory_calculation_dict
[
'inventory_params'
]
)
current_inventory_dict
=
{}
current_inventory_key_id_list
=
[
x
[
"key"
]
for
x
in
inventory_calculation_dict
[
'first_level'
]]
for
line
in
current_inventory_list
:
current_inventory_key
=
[
line
[
x
]
for
x
in
current_inventory_key_id_list
]
for
x
in
xrange
(
len
(
current_inventory_key
)):
if
current_inventory_key
[
x
]
is
None
:
current_inventory_key
[
x
]
=
""
current_inventory_key
=
tuple
(
current_inventory_key
)
if
"second_level"
in
inventory_calculation_dict
:
# two level of variation
try
:
current_inventory_by_sub_variation
=
\
current_inventory_dict
[
current_inventory_key
]
except
KeyError
:
current_inventory_by_sub_variation
=
\
current_inventory_dict
[
current_inventory_key
]
=
{}
second_level_key_id_list
=
[
x
[
'key'
]
for
x
in
inventory_calculation_dict
[
'second_level'
]]
second_level_key
=
tuple
([
line
[
x
]
for
x
in
second_level_key_id_list
])
current_inventory_by_sub_variation
[
second_level_key
]
=
line
[
'total_quantity'
]
else
:
# we got the quantity from first level key
diff_quantity
=
movement_quantity
-
inventory_value
# Create tmp movement
kwd
=
{
'uid'
:
movement
.
getUid
(),
'start_date'
:
stop_date
,
'order_id'
:
getOrderIdCounter
(),
'mirror_order_id'
:
getOrderIdCounter
()
}
temp_delivery_line
=
temp_constructor
(
self
,
inventory_id
)
# set category on it only if quantity not null
# thus line with same uid will be deleted but we
# don't insert line with null quantity as we test
# some categories like resource/destination/source
# before insert but not before delete
if
diff_quantity
!=
0
:
kwd
[
'quantity'
]
=
diff_quantity
category_list
=
self
.
getCategoryList
()
setter_list
=
[
x
[
'setter'
]
for
x
in
inventory_calculation_dict
[
'first_level'
]]
if
"second_level"
in
inventory_calculation_dict
:
setter_list
.
extend
([
x
[
'setter'
]
for
x
in
inventory_calculation_dict
[
'second_level'
]])
value_list
=
list
(
key_list
)
+
list
(
second_key_list
)
for
x
in
xrange
(
len
(
setter_list
)):
value
=
value_list
[
x
]
setter
=
setter_list
[
x
]
base_category
=
""
if
isinstance
(
setter
,
(
tuple
,
list
)):
base_category
=
setter
[
1
]
setter
=
setter
[
0
]
method
=
getattr
(
self
,
setter
,
None
)
if
method
is
not
None
:
method
(
category_list
,
value
,
base_category
)
# only one level of variation
current_inventory_dict
[
current_inventory_key
]
=
line
[
'total_quantity'
]
kwd
[
'category_list'
]
=
category_list
temp_delivery_line
.
edit
(
**
kwd
)
stock_append
(
temp_delivery_line
)
to_delete_list_append
(
temp_delivery_line
)
# Browse all movements on inventory and create diff line when necessary
if
self
.
isFullInventory
():
not_used_inventory_dict
=
current_inventory_dict
else
:
# Make sure we remove any any value
to_delete_stock_uid_add
(
movement
.
getUid
())
# Now create line to remove some subvariation text not present
# in new inventory
if
len
(
not_used_inventory_dict
):
inventory_uid
=
self
.
getUid
()
for
first_level_key
in
not_used_inventory_dict
.
keys
():
inventory_value
=
\
not_used_inventory_dict
[
tuple
(
first_level_key
)]
# XXX-Aurel : this code does not work with only one level of variation
for
second_level_key
in
inventory_value
.
keys
():
diff_quantity
=
-
inventory_value
[
tuple
(
second_level_key
)]
kwd
=
{
'uid'
:
inventory_uid
,
not_used_inventory_dict
=
{}
inventory_id
=
self
.
getId
()
list_method
=
inventory_calculation_dict
[
'list_method'
]
method
=
getattr
(
self
,
list_method
)
__order_id_counter_list
=
[
0
]
def
getOrderIdCounter
():
value
=
__order_id_counter_list
[
0
]
# pylint: disable=cell-var-from-loop
__order_id_counter_list
[
0
]
=
value
+
1
# pylint: disable=cell-var-from-loop
return
value
for
movement
in
method
():
if
movement
.
getResourceValue
()
is
not
None
and
\
movement
.
getInventoriatedQuantity
()
not
in
(
None
,
''
):
if
movement
.
getStopDate
()
!=
stop_date
:
continue
movement_quantity
=
movement
.
getInventoriatedQuantity
()
# construct key to retrieve inventory into dict
getter_list
=
[
x
[
'getter'
]
for
x
in
inventory_calculation_dict
[
'first_level'
]]
key_list
=
[]
for
getter
in
getter_list
:
method
=
getattr
(
movement
,
getter
,
None
)
if
method
is
not
None
:
key_list
.
append
(
method
())
inventory_value
=
current_inventory_dict
.
get
(
tuple
(
key_list
),
0
)
second_key_list
=
[]
if
'second_level'
in
inventory_calculation_dict
:
if
inventory_value
==
0
:
inventory_value
=
{}
# two level
second_getter_list
=
[
x
[
'getter'
]
for
x
in
inventory_calculation_dict
[
'second_level'
]]
for
getter
in
second_getter_list
:
method
=
getattr
(
movement
,
getter
,
None
)
if
method
is
not
None
:
second_key_list
.
append
(
method
())
second_key_list
=
tuple
(
second_key_list
)
if
second_key_list
in
inventory_value
:
total_quantity
=
inventory_value
.
pop
(
second_key_list
)
# Put remaining subvariation in a dict to know which one
# to removed at end
not_used_inventory_dict
[
tuple
(
key_list
)]
=
inventory_value
diff_quantity
=
movement_quantity
-
total_quantity
else
:
# Inventory for new resource/variation/sub_variation
diff_quantity
=
movement_quantity
# Put remaining subvariation in a dict to know which one
# to removed at end
not_used_inventory_dict
[
tuple
(
key_list
)]
=
inventory_value
else
:
# we got the quantity from first level key
diff_quantity
=
movement_quantity
-
inventory_value
# Create tmp movement
kwd
=
{
'uid'
:
movement
.
getUid
(),
'start_date'
:
stop_date
,
'stop_date'
:
stop_date
,
'order_id'
:
getOrderIdCounter
(),
'mirror_order_id'
:
getOrderIdCounter
()
}
# create the tmp line and set category on it
temp_delivery_line
=
temp_constructor
(
self
,
inventory_id
)
kwd
[
'quantity'
]
=
diff_quantity
category_list
=
self
.
getCategoryList
()
setter_list
=
[
x
[
'setter'
]
for
x
in
inventory_calculation_dict
[
'first_level'
]]
if
"second_level"
in
inventory_calculation_dict
:
setter_list
.
extend
([
x
[
'setter'
]
for
x
in
inventory_calculation_dict
[
'second_level'
]])
value_list
=
list
(
first_level_key
)
+
list
(
second_level_key
)
for
x
in
xrange
(
len
(
setter_list
)):
value
=
value_list
[
x
]
setter
=
setter_list
[
x
]
base_category
=
""
if
isinstance
(
setter
,
(
tuple
,
list
)):
base_category
=
setter
[
1
]
setter
=
setter
[
0
]
method
=
getattr
(
self
,
setter
,
None
)
if
method
is
not
None
:
method
(
category_list
,
value
,
base_category
)
kwd
[
'category_list'
]
=
category_list
# set category on it only if quantity not null
# thus line with same uid will be deleted but we
# don't insert line with null quantity as we test
# some categories like resource/destination/source
# before insert but not before delete
if
diff_quantity
!=
0
:
kwd
[
'quantity'
]
=
diff_quantity
category_list
=
self
.
getCategoryList
()
setter_list
=
[
x
[
'setter'
]
for
x
in
inventory_calculation_dict
[
'first_level'
]]
if
"second_level"
in
inventory_calculation_dict
:
setter_list
.
extend
([
x
[
'setter'
]
for
x
in
inventory_calculation_dict
[
'second_level'
]])
value_list
=
list
(
key_list
)
+
list
(
second_key_list
)
for
x
in
xrange
(
len
(
setter_list
)):
value
=
value_list
[
x
]
setter
=
setter_list
[
x
]
base_category
=
""
if
isinstance
(
setter
,
(
tuple
,
list
)):
base_category
=
setter
[
1
]
setter
=
setter
[
0
]
method
=
getattr
(
self
,
setter
,
None
)
if
method
is
not
None
:
method
(
category_list
,
value
,
base_category
)
kwd
[
'category_list'
]
=
category_list
temp_delivery_line
.
edit
(
**
kwd
)
stock_append
(
temp_delivery_line
)
to_delete_list_append
(
temp_delivery_line
)
else
:
# Make sure we remove any any value
to_delete_stock_uid_add
(
movement
.
getUid
())
# Now create line to remove some subvariation text not present
# in new inventory
if
len
(
not_used_inventory_dict
):
inventory_uid
=
self
.
getUid
()
for
first_level_key
in
not_used_inventory_dict
.
keys
():
inventory_value
=
\
not_used_inventory_dict
[
tuple
(
first_level_key
)]
# XXX-Aurel : this code does not work with only one level of variation
for
second_level_key
in
inventory_value
.
keys
():
diff_quantity
=
-
inventory_value
[
tuple
(
second_level_key
)]
kwd
=
{
'uid'
:
inventory_uid
,
'start_date'
:
stop_date
,
'stop_date'
:
stop_date
,
'order_id'
:
getOrderIdCounter
(),
'mirror_order_id'
:
getOrderIdCounter
()
}
# create the tmp line and set category on it
temp_delivery_line
=
temp_constructor
(
self
,
inventory_id
)
kwd
[
'quantity'
]
=
diff_quantity
category_list
=
self
.
getCategoryList
()
setter_list
=
[
x
[
'setter'
]
for
x
in
inventory_calculation_dict
[
'first_level'
]]
if
"second_level"
in
inventory_calculation_dict
:
setter_list
.
extend
([
x
[
'setter'
]
for
x
in
inventory_calculation_dict
[
'second_level'
]])
value_list
=
list
(
first_level_key
)
+
list
(
second_level_key
)
for
x
in
xrange
(
len
(
setter_list
)):
value
=
value_list
[
x
]
setter
=
setter_list
[
x
]
base_category
=
""
if
isinstance
(
setter
,
(
tuple
,
list
)):
base_category
=
setter
[
1
]
setter
=
setter
[
0
]
method
=
getattr
(
self
,
setter
,
None
)
if
method
is
not
None
:
method
(
category_list
,
value
,
base_category
)
kwd
[
'category_list'
]
=
category_list
temp_delivery_line
.
edit
(
**
kwd
)
stock_append
(
temp_delivery_line
)
# Reindex objects
immediate_reindex_archive
=
sql_catalog_id
is
not
None
...
...
@@ -357,4 +369,10 @@ class Inventory(Delivery):
# 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'
,
),
**
catalog_kw
)
\ No newline at end of file
**
catalog_kw
)
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