Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
4 Відповіді
6469 Переглядів

Hello I am trying to make an autoincrement field for the traceability of purchases requests. 

I have called the field 

    code = fields.Char('Code', size=32, required=True,readonly=True, default=_get_default_name, track_visibility='onchange')

Using the function next_by_code for the autoincrement  

    def _get_default_name(self):        return self.env['ir.sequence'].next_by_code('sprogroup.purchase.request') 

 But this method doesn't work. In my idea I would like to make the field CODE a field that is called like RA2020001 for the first then RA2020002 for the second and so on. But I cannot do it. Any suggests?

Have a nice day

Аватар
Відмінити

Please make clear what exactly not working? like are you missing sequence in between or sequence not generated so on. it will be helpful to get your question answered.

Найкраща відповідь

Hello Michele, 

Default value is not working because this field is read only type and while creating any record this field is not updating inside the database.

So you can update your code like that,

code = fields.Char ('Code', size = 32, required = True, readonly = True, default = lambda self: _ ('New'), track_visibility = 'onchange')
then inherit the create method

    @ api.model

    def create (self, waltz):

        if waltz:

            waltz ['code'] = self.env ['ir.sequence']. next_by_code ('sprogroup.purchase.request') or _ ('New')

        return super (YourClass, self) .create (waltz)

I hope your query is resolved by now. 

Thanks

Anisha Bahukhandi

Technical Content Writer

Webkul 

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
4
трав. 24
12572
1
квіт. 24
3211
0
лист. 23
1949
1
вер. 23
2046
2
серп. 23
4431