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
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
8063c50a
Commit
8063c50a
authored
Apr 23, 2012
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code simplification
parent
aa3a313d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
63 deletions
+42
-63
product/ERP5/Document/SimulatedDeliveryBuilder.py
product/ERP5/Document/SimulatedDeliveryBuilder.py
+2
-7
product/ERP5/mixin/builder.py
product/ERP5/mixin/builder.py
+11
-26
product/ERP5Type/Base.py
product/ERP5Type/Base.py
+29
-30
No files found.
product/ERP5/Document/SimulatedDeliveryBuilder.py
View file @
8063c50a
...
@@ -348,11 +348,8 @@ class SimulatedDeliveryBuilder(BuilderMixin):
...
@@ -348,11 +348,8 @@ class SimulatedDeliveryBuilder(BuilderMixin):
if
old_delivery
is
None
:
if
old_delivery
is
None
:
# from scratch
# from scratch
new_delivery_id
=
str
(
delivery_module
.
generateNewId
())
new_delivery_id
=
str
(
delivery_module
.
generateNewId
())
delivery
=
delivery_module
.
newContent
(
delivery
=
super
(
SimulatedDeliveryBuilder
,
self
).
_createDelivery
(
portal_type
=
self
.
getDeliveryPortalType
(),
delivery_module
,
movement_list
,
activate_kw
)
id
=
new_delivery_id
,
created_by_builder
=
1
,
activate_kw
=
activate_kw
)
else
:
else
:
# from duplicated original delivery
# from duplicated original delivery
cp
=
tryMethodCallWithTemporaryPermission
(
cp
=
tryMethodCallWithTemporaryPermission
(
...
@@ -383,10 +380,8 @@ class SimulatedDeliveryBuilder(BuilderMixin):
...
@@ -383,10 +380,8 @@ class SimulatedDeliveryBuilder(BuilderMixin):
old_delivery_line
=
None
old_delivery_line
=
None
if
old_delivery_line
is
None
:
if
old_delivery_line
is
None
:
# from scratch
# from scratch
new_delivery_line_id
=
str
(
delivery
.
generateNewId
())
delivery_line
=
delivery
.
newContent
(
delivery_line
=
delivery
.
newContent
(
portal_type
=
self
.
getDeliveryLinePortalType
(),
portal_type
=
self
.
getDeliveryLinePortalType
(),
id
=
new_delivery_line_id
,
variation_category_list
=
[],
variation_category_list
=
[],
activate_kw
=
activate_kw
)
activate_kw
=
activate_kw
)
else
:
else
:
...
...
product/ERP5/mixin/builder.py
View file @
8063c50a
...
@@ -164,7 +164,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -164,7 +164,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
"""
"""
delivery_module_before_building_script_id
=
\
delivery_module_before_building_script_id
=
\
self
.
getDeliveryModuleBeforeBuildingScriptId
()
self
.
getDeliveryModuleBeforeBuildingScriptId
()
if
delivery_module_before_building_script_id
not
in
[
""
,
None
]
:
if
delivery_module_before_building_script_id
:
delivery_module
=
getattr
(
self
.
getPortalObject
(),
self
.
getDeliveryModule
())
delivery_module
=
getattr
(
self
.
getPortalObject
(),
self
.
getDeliveryModule
())
getattr
(
delivery_module
,
delivery_module_before_building_script_id
)()
getattr
(
delivery_module
,
delivery_module_before_building_script_id
)()
...
@@ -369,13 +369,10 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -369,13 +369,10 @@ class BuilderMixin(XMLObject, Amount, Predicate):
Create a new delivery in case where a builder may not update
Create a new delivery in case where a builder may not update
an existing one.
an existing one.
"""
"""
new_delivery_id
=
str
(
delivery_module
.
generateNewId
())
return
delivery_module
.
newContent
(
delivery
=
delivery_module
.
newContent
(
portal_type
=
self
.
getDeliveryPortalType
(),
portal_type
=
self
.
getDeliveryPortalType
(),
id
=
new_delivery_id
,
created_by_builder
=
1
,
created_by_builder
=
1
,
activate_kw
=
activate_kw
)
activate_kw
=
activate_kw
)
return
delivery
def
_processDeliveryGroup
(
self
,
delivery_module
,
movement_group_node
,
def
_processDeliveryGroup
(
self
,
delivery_module
,
movement_group_node
,
collect_order_list
,
movement_group_node_list
=
None
,
collect_order_list
,
movement_group_node_list
=
None
,
...
@@ -453,13 +450,10 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -453,13 +450,10 @@ class BuilderMixin(XMLObject, Amount, Predicate):
Create a new delivery line in case where a builder may not update
Create a new delivery line in case where a builder may not update
an existing one.
an existing one.
"""
"""
new_delivery_line_id
=
str
(
delivery
.
generateNewId
())
return
delivery
.
newContent
(
delivery_line
=
delivery
.
newContent
(
portal_type
=
self
.
getDeliveryLinePortalType
(),
portal_type
=
self
.
getDeliveryLinePortalType
(),
id
=
new_delivery_line_id
,
created_by_builder
=
1
,
created_by_builder
=
1
,
activate_kw
=
activate_kw
)
activate_kw
=
activate_kw
)
return
delivery_line
def
_processDeliveryLineGroup
(
self
,
delivery
,
movement_group_node
,
def
_processDeliveryLineGroup
(
self
,
delivery
,
movement_group_node
,
collect_order_list
,
movement_group_node_list
=
None
,
collect_order_list
,
movement_group_node_list
=
None
,
...
@@ -686,42 +680,33 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -686,42 +680,33 @@ class BuilderMixin(XMLObject, Amount, Predicate):
delivery_movement
.
_edit
(
force_update
=
1
,
**
property_dict
)
delivery_movement
.
_edit
(
force_update
=
1
,
**
property_dict
)
@
UnrestrictedMethod
@
UnrestrictedMethod
def
callAfterBuildingScript
(
self
,
delivery_list
,
movement_list
=
None
,
**
kw
):
def
callAfterBuildingScript
(
self
,
delivery_list
,
movement_list
=
()
,
**
kw
):
"""
"""
Call script on each delivery built.
Call script on each delivery built.
"""
"""
if
not
len
(
delivery_list
):
return
# Parameter initialization
if
movement_list
is
None
:
movement_list
=
[]
delivery_after_generation_script_id
=
\
delivery_after_generation_script_id
=
\
self
.
getDeliveryAfterGenerationScriptId
()
self
.
getDeliveryAfterGenerationScriptId
()
related_simulation_movement_path_list
=
\
if
delivery_after_generation_script_id
:
[
x
.
getPath
()
for
x
in
movement_list
]
related_simulation_movement_path_list
=
\
if
delivery_after_generation_script_id
not
in
[
""
,
None
]:
[
x
.
getPath
()
for
x
in
movement_list
]
for
delivery
in
delivery_list
:
for
delivery
in
delivery_list
:
script
=
getattr
(
delivery
,
delivery_after_generation_script_id
)
script
=
getattr
(
delivery
,
delivery_after_generation_script_id
)
# BBB: Only Python Scripts were used in the past, and they might not
# BBB: Only Python Scripts were used in the past, and they might not
# accept an arbitrary argument. So to keep compatibility,
# accept an arbitrary argument. So to keep compatibility,
# check if it can take the new parameter safely, only when
# check if it can take the new parameter safely, only when
# the callable object is a Python Script.
# the callable object is a Python Script.
safe_to_pass_parameter
=
True
meta_type
=
getattr
(
script
,
'meta_type'
,
None
)
meta_type
=
getattr
(
script
,
'meta_type'
,
None
)
if
meta_type
==
'Script (Python)'
:
if
meta_type
==
'Script (Python)'
:
# check if the script accepts related_simulation_movement_path_list
# check if the script accepts related_simulation_movement_path_list
safe_to_pass_parameter
=
False
for
param
in
script
.
params
().
split
(
','
):
for
param
in
script
.
params
().
split
(
','
):
param
=
param
.
split
(
'='
,
1
)[
0
].
strip
()
param
=
param
.
split
(
'='
,
1
)[
0
].
strip
()
if
param
==
'related_simulation_movement_path_list'
\
if
param
==
'related_simulation_movement_path_list'
\
or
param
.
startswith
(
'**'
):
or
param
.
startswith
(
'**'
):
safe_to_pass_parameter
=
True
break
break
else
:
if
safe_to_pass_parameter
:
script
()
script
(
related_simulation_movement_path_list
=
related_simulation_movement_path_list
)
continue
else
:
script
(
related_simulation_movement_path_list
=
related_simulation_movement_path_list
)
script
()
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getMovementGroupList'
)
'getMovementGroupList'
)
...
...
product/ERP5Type/Base.py
View file @
8063c50a
...
@@ -1436,43 +1436,42 @@ class Base( CopyContainer,
...
@@ -1436,43 +1436,42 @@ class Base( CopyContainer,
# We only change if the value is different
# We only change if the value is different
# This may be very long...
# This may be very long...
if
force_update
:
if
force_update
:
update
=
True
old_value
=
None
old_value
=
None
else
:
else
:
try
:
try
:
old_value
=
getProperty
(
key
,
evaluate
=
0
)
old_value
=
getProperty
(
key
,
evaluate
=
0
)
except
TypeError
:
except
TypeError
:
old_value
=
getProperty
(
key
)
old_value
=
getProperty
(
key
)
update
=
old_value
!=
kw
[
key
]
if
old_value
==
kw
[
key
]:
not_modified_list
.
append
(
key
)
if
update
:
continue
# We keep in a thread var the previous values
# this can be useful for interaction workflow to implement lookup
s
# We keep in a thread var the previous value
s
# XXX If iteraction workflow script is triggered by edit and call
s
# this can be useful for interaction workflow to implement lookup
s
# edit itself, this is useless as the dict will be overwritten
# XXX If iteraction workflow script is triggered by edit and calls
# If the keep_existing flag is set to 1, we do not update properties which are defined
# edit itself, this is useless as the dict will be overwritten
if
not
keep_existing
or
not
hasProperty
(
key
):
# If the keep_existing flag is set to 1, we do not update properties which are defined
if
restricted
:
if
keep_existing
and
hasProperty
(
key
)
:
accessor_name
=
'set'
+
UpperCase
(
key
)
continue
if
accessor_name
in
restricted_method_set
:
if
restricted
:
# will raise Unauthorized when not allowed
accessor_name
=
'set'
+
UpperCase
(
key
)
guarded_getattr
(
self
,
accessor_name
)
if
accessor_name
in
restricted_method_set
:
modified_property_dict
[
key
]
=
old_value
# will raise Unauthorized when not allowed
if
key
!=
'id'
:
guarded_getattr
(
self
,
accessor_name
)
modified_object_list
=
_setProperty
(
key
,
kw
[
key
])
modified_property_dict
[
key
]
=
old_value
# BBB: if the setter does not return anything, assume
if
key
!=
'id'
:
# that self has been modified.
modified_object_list
=
_setProperty
(
key
,
kw
[
key
])
if
modified_object_list
is
None
:
# BBB: if the setter does not return anything, assume
modified_object_list
=
(
self
,)
# that self has been modified.
for
o
in
modified_object_list
:
if
modified_object_list
is
None
:
# XXX using id is not quite nice, but getUID causes a
modified_object_list
=
(
self
,)
# problem at the bootstrap of an ERP5 site. Therefore,
for
o
in
modified_object_list
:
# objects themselves cannot be used as keys.
# XXX using id is not quite nice, but getUID causes a
modified_object_dict
[
id
(
o
)]
=
o
# problem at the bootstrap of an ERP5 site. Therefore,
else
:
# objects themselves cannot be used as keys.
self
.
setId
(
kw
[
'id'
],
reindex
=
reindex_object
)
modified_object_dict
[
id
(
o
)]
=
o
else
:
else
:
not_modified_list
.
append
(
key
)
self
.
setId
(
kw
[
'id'
],
reindex
=
reindex_object
)
return
not_modified_list
return
not_modified_list
unmodified_key_list
=
setChangedPropertyList
(
unordered_key_list
)
unmodified_key_list
=
setChangedPropertyList
(
unordered_key_list
)
...
...
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