I would like to reset a sequence number yearly and with another parameters. I don't know how to do this. Plesas someone coan help?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
You can restart sequence numberingby using subsequences. If you select 'Use subsequences per date_range' on your sequence, it will create new subsequences by year, so numbering will reset each year. If you want to set a different range length, you need to do so manually, or you can create an automated action to do it.
For manual subsequences, just add the date ranges you wish to use to the sequence.
A little more complicated: You could also use automated actions to create a custom date range length. To do this, I added a selection field on sequences so I could select 'Monthly', 'Yearly', or 'Daily' on each sequence. Then I created an automated action on the subsequences that used python to change the end date on creation, based on the selection.
Can you please go into more detail on how to create the automated action and what the python code was.
Hi Chris, we needed to have shorter (monthly/weekly) ranges and didn't want to create them manually, so this was my solution. This was done in v12 and I haven't extensively tested on subsequent versions, so take that into consideration.
The sequence will automatically generate a new subsequence for the current calendar year when the sequence is used, if none of the existing subsequences have current dates. So all you need to do is create an automated action on creation of those subsequences to modify the date range to what you need.
I created a custom field (x_time_length) on the sequence for subsequence length with values "Day", "Week", "Month" and "Year".
The I created an automated action on subsequences to run on creation. If the length value is "Day", "Week", or "Month", it modifies the start date and end date of the sequences to match. Since Odoo will always generate a new subsequence once the previous one has ended, you don't need to worry about scheduled actions or generating more than one subseqence at once. This is the action I created - could be optimized but this worked for our purposes.
Model: ir.sequence.date_range
Trigger: on_create
Apply On: ["&",["sequence_id.x_time_length","!=",False],["sequence_id.x_time_length","!=","Year"]]
Python Code:
changes = {}
today = datetime.date.today()
if record.sequence_id.x_time_length == "Day":
changes['date_from'] = today
changes['date_to'] = changes['date_from']
elif record.sequence_id.x_time_length == "Week":
changes['date_from'] = today + dateutil.relativedelta.relativedelta(weekday=dateutil.relativedelta.MO(-1))
changes['date_to'] = changes['date_from'] + dateutil.relativedelta.relativedelta(days=6)
elif record.sequence_id.x_time_length == "Month":
changes['date_from'] = today.replace(day=1)
changes['date_to'] = changes['date_from'] + dateutil.relativedelta.relativedelta(day=31)
record.write(changes)
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up