Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
30220 Lượt xem

Im a new guy in odoo, so if i have some stupid Ques please forgive me. Tks you

My code is: 

From odoo import models, fields

Class khachhang(models.Model):

      _name ='khachhang.duan'

       id = field.Integer ( string="STT" )

I want my id to become auto increment from 1. What should i do now? 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You should rename your variable to something else. id is already used for database records and incremented by default.

your_field = field.Integer(string="SST", default=lambda self: self.env['ir.sequence'].next_by_code('increment_your_field')

with : 

<record id="increment_your_field_sequence" model="ir.sequence">
    <field name="name">Field Incrementation</field>
    <field name="code">increment_your_field</field>
    <field name="prefix"></field>
    <field name="padding">3</field>
    <field name="company_id" eval="False"/>
</record>

Padding may be changed to a higher number, it's based on how records you may have ( in this case, you will get 001,002,003,004,005,006...999)

Ảnh đại diện
Huỷ bỏ

Sir what is the purpose of prefix field?

I have done the auto increment but i want a default string to be shown before the sequence number so how can i do it? Kindly guid me

Câu trả lời hay nhất

Dear LaoThai,

Pls Check This link.

https://www.odoo.com/forum/help-1/question/two-sequance-for-one-object-134383


I Hope It Help you ...

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
9
thg 6 23
12152
2
thg 1 22
3166
2
thg 12 21
6927
0
thg 6 21
1393
0
thg 2 21
1973