[IMP] make resequence field customizable, make sequence number for first record configurable
bzr revid: xmo@openerp.com-20120830121403-82cr13t824jdxcsh
This commit is contained in:
parent
209ff94873
commit
15c7043f56
|
@ -1190,12 +1190,26 @@ class DataSet(openerpweb.Controller):
|
||||||
return req.session.exec_workflow(model, id, signal)
|
return req.session.exec_workflow(model, id, signal)
|
||||||
|
|
||||||
@openerpweb.jsonrequest
|
@openerpweb.jsonrequest
|
||||||
def resequence(self, req, model, ids):
|
def resequence(self, req, model, ids, field='sequence', offset=0):
|
||||||
|
""" Re-sequences a number of records in the model, by their ids
|
||||||
|
|
||||||
|
The re-sequencing starts at the first model of ``ids``, the sequence
|
||||||
|
number is incremented by one after each record and starts at ``offset``
|
||||||
|
|
||||||
|
:param ids: identifiers of the records to resequence, in the new sequence order
|
||||||
|
:type ids: list(id)
|
||||||
|
:param str field: field used for sequence specification, defaults to
|
||||||
|
"sequence"
|
||||||
|
:param int offset: sequence number for first record in ``ids``, allows
|
||||||
|
starting the resequencing from an arbitrary number,
|
||||||
|
defaults to ``0``
|
||||||
|
"""
|
||||||
m = req.session.model(model)
|
m = req.session.model(model)
|
||||||
if not len(m.fields_get(['sequence'])):
|
if not m.fields_get([field]):
|
||||||
return False
|
return False
|
||||||
for i in range(len(ids)):
|
# python 2.6 has no start parameter
|
||||||
m.write([ids[i]], { 'sequence': i })
|
for i, id in enumerate(ids):
|
||||||
|
m.write(id, { field: i + offset })
|
||||||
return True
|
return True
|
||||||
|
|
||||||
class DataGroup(openerpweb.Controller):
|
class DataGroup(openerpweb.Controller):
|
||||||
|
|
Loading…
Reference in New Issue