Skip to Content
Menu
This question has been flagged
1 Reply
3692 Views

I'm trying to implement sequences on my custom modules, so I've created a sequence through the menu configuration>sequences & identificators. Now I'm trying to assing the sequence to my model but I don't know how to do it, reading some documentation get the model name for sequences is ir.sequence.

How can I handle the sequence on my model? need to add a m2o field to ir.sequence?

Avatar
Discard
Best Answer

Hi,

have a look at the 'sale' app for the example. Find the file 'sale.py' and the function 'create' for a 'sale.order'. Here you may see:

@api.model
    def create(self, vals):
        if vals.get('name', 'New') == 'New':
            vals['name'] = self.env['ir.sequence'].next_by_code('sale.order') or 'New'

 

This method adds sequence to sale order name. You may do the same


Avatar
Discard
Author

Thanks, I will install the module and check the code, I've created a sequence through the sequence submenu in the config menu, the code you posted will recognize my sequence on the .next_by_code('sequence.name')?

If you define a proper object, it should

Related Posts Replies Views Activity
1
Sep 21
2825
4
Aug 20
7739
1
Aug 23
982
2
Mar 19
5695
3
Aug 24
5509