Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Coopdevs OCB mirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Odoo
Coopdevs OCB mirror
Commits
dc993b50
Commit
dc993b50
authored
13 years ago
by
Vo Minh Thu
Browse files
Options
Downloads
Patches
Plain Diff
[IMP] ir_sequence: change API, deprecate old one.
bzr revid: vmt@openerp.com-20110929122753-19middna4b782tcy
parent
b917742f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openerp/addons/base/ir/ir_sequence.py
+47
-28
47 additions, 28 deletions
openerp/addons/base/ir/ir_sequence.py
with
47 additions
and
28 deletions
openerp/addons/base/ir/ir_sequence.py
+
47
−
28
View file @
dc993b50
...
...
@@ -19,10 +19,13 @@
#
##############################################################################
import
logging
import
time
import
openerp
_logger
=
logging
.
getLogger
(
'
ir_sequence
'
)
class
ir_sequence_type
(
openerp
.
osv
.
osv
.
osv
):
_name
=
'
ir.sequence.type
'
_order
=
'
name
'
...
...
@@ -39,9 +42,6 @@ def _code_get(self, cr, uid, context={}):
cr
.
execute
(
'
select code, name from ir_sequence_type
'
)
return
cr
.
fetchall
()
IMPLEMENTATION_SELECTION
=
\
[(
'
standard
'
,
'
Standard
'
),
(
'
no_gap
'
,
'
No gap
'
)]
class
ir_sequence
(
openerp
.
osv
.
osv
.
osv
):
"""
Sequence model.
...
...
@@ -56,7 +56,8 @@ class ir_sequence(openerp.osv.osv.osv):
'
name
'
:
openerp
.
osv
.
fields
.
char
(
'
Name
'
,
size
=
64
,
required
=
True
),
'
code
'
:
openerp
.
osv
.
fields
.
selection
(
_code_get
,
'
Code
'
,
size
=
64
,
required
=
True
),
'
implementation
'
:
openerp
.
osv
.
fields
.
selection
(
# TODO update the view
IMPLEMENTATION_SELECTION
,
'
Implementation
'
,
required
=
True
,
[(
'
standard
'
,
'
Standard
'
),
(
'
no_gap
'
,
'
No gap
'
)],
'
Implementation
'
,
required
=
True
,
help
=
"
Two sequence object implementations are offered: Standard
"
"
and
'
No gap
'
. The later is slower than the former but forbids any
"
"
gap in the sequence (while they are possible in the former).
"
),
...
...
@@ -144,53 +145,71 @@ class ir_sequence(openerp.osv.osv.osv):
'
sec
'
:
time
.
strftime
(
'
%S
'
,
t
),
}
# TODO rename 'test' to 'code_or_id' in account/sequence.
def
next_by_id
(
self
,
cr
,
uid
,
sequence_id
,
context
=
None
):
"""
Draw an interpolated string using the specified sequence.
"""
self
.
check_read
(
cr
,
uid
)
res
=
self
.
_select_by_code_or_id
(
cr
,
uid
,
sequence_id
,
'
id
'
,
False
,
context
)
return
self
.
_next
(
cr
,
uid
,
res
,
context
)
def
next_by_code
(
self
,
cr
,
uid
,
sequence_code
,
context
=
None
):
"""
Draw an interpolated string using the specified sequence.
"""
self
.
check_read
(
cr
,
uid
)
res
=
self
.
_select_by_code_or_id
(
cr
,
uid
,
sequence_code
,
'
code
'
,
False
,
context
)
return
self
.
_next
(
cr
,
uid
,
res
,
context
)
def
get_id
(
self
,
cr
,
uid
,
sequence_code_or_id
,
code_or_id
=
'
id
'
,
context
=
None
):
"""
Draw an interpolated string using the specified sequence.
The sequence to use is specified by the ``sequence_code_or_id``
argument, which can be a code or an id (as controlled by the
``code_or_id`` argument.
``code_or_id`` argument.
This method is deprecated.
"""
self
.
check_read
(
cr
,
uid
)
res
=
self
.
_select_by_code_or_id
(
cr
,
uid
,
sequence_code_or_id
,
code_or_id
,
False
,
context
)
_logger
.
warning
(
"
ir_sequence.get() and ir_sequence.get_id() are deprecated.
"
"
Please use ir_sequence.next_by_code() or ir_sequence.next_by_id().
"
)
if
code_or_id
==
'
id
'
:
return
self
.
next_by_id
(
cr
,
uid
,
sequence_code_or_id
,
context
)
else
:
return
self
.
next_by_code
(
cr
,
uid
,
sequence_code_or_id
,
context
)
def
get
(
self
,
cr
,
uid
,
code
,
context
=
None
):
"""
Draw an interpolated string using the specified sequence.
if
not
res
:
The sequence to use is specified by its code. This method is
deprecated.
"""
return
self
.
get_id
(
cr
,
uid
,
code
,
'
code
'
,
context
)
def
_next
(
self
,
cr
,
uid
,
sequence
,
context
=
None
):
if
not
sequence
:
return
False
if
res
[
'
implementation
'
]
==
'
standard
'
:
if
sequence
[
'
implementation
'
]
==
'
standard
'
:
cr
.
execute
(
"""
SELECT nextval(
'
ir_sequence_%03d
'
)
"""
%
res
[
'
id
'
])
res
[
'
number_next
'
]
=
cr
.
fetchone
()
"""
%
sequence
[
'
id
'
])
sequence
[
'
number_next
'
]
=
cr
.
fetchone
()
else
:
# Read again with FOR UPDATE NO WAIT.
res
=
self
.
_select_by_code_or_id
(
cr
,
uid
,
sequence
_code_or_id
,
code_or_
id
,
True
,
context
)
sequence
=
self
.
_select_by_code_or_id
(
cr
,
uid
,
sequence
[
'
id
'
]
,
'
id
'
,
True
,
context
)
cr
.
execute
(
"""
UPDATE ir_sequence
SET number_next=number_next+number_increment
WHERE id=%s
"""
,
(
res
[
'
id
'
],))
"""
,
(
sequence
[
'
id
'
],))
d
=
self
.
_interpolation_dict
()
interpolated_prefix
=
self
.
_interpolate
(
res
[
'
prefix
'
],
d
)
interpolated_suffix
=
self
.
_interpolate
(
res
[
'
suffix
'
],
d
)
if
res
[
'
number_next
'
]:
return
interpolated_prefix
+
'
%%0%sd
'
%
res
[
'
padding
'
]
%
\
res
[
'
number_next
'
]
+
interpolated_suffix
interpolated_prefix
=
self
.
_interpolate
(
sequence
[
'
prefix
'
],
d
)
interpolated_suffix
=
self
.
_interpolate
(
sequence
[
'
suffix
'
],
d
)
if
sequence
[
'
number_next
'
]:
return
interpolated_prefix
+
'
%%0%sd
'
%
sequence
[
'
padding
'
]
%
\
sequence
[
'
number_next
'
]
+
interpolated_suffix
else
:
# TODO what is this case used for ?
return
interpolated_prefix
+
interpolated_suffix
def
get
(
self
,
cr
,
uid
,
code
,
context
=
None
):
"""
Draw an interpolated string using the specified sequence.
The sequence to use is specified by its code.
"""
return
self
.
get_id
(
cr
,
uid
,
code
,
'
code
'
,
context
)
def
_select_by_code_or_id
(
self
,
cr
,
uid
,
sequence_code_or_id
,
code_or_id
,
for_update_no_wait
,
context
=
None
):
"""
Read a sequence object.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment