Hi. I want to get rid of the first field when creating a new object. Similar to how invoices are automatically assigned an ID, I'd like to do that to some custom models I have created.
Please help!
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
Hi Salomon Cohen,
Yes, you can achieve it using sequence for your custom model
=> For that first of create a field for the storing sequence of custom model
Please find code in comment.
Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari
Please find code here :-
sequence_no = fields.Char(string='Sequence', required=True,readonly=True,
default=lambda self: _('New'))
=> Add function for the sequence in the following code
@api.model
def create(self, vals):
if vals.get('sequence_no', ('New')) == ('New'):
vals['sequence_no'] = self.env['ir.sequence'].next_by_code(
'custom.model') or _('New')
res = super(CustomModel, self).create(vals)
return res
=> And create a record for that and create an XML file
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="seq_custom_model" model="ir.sequence">
<field name="name">Custom Model Sequence</field>
<field name="code">custom.model</field>
<field name="prefix">CM</field>
<field name="padding">3</field>
<field name="company_id" eval="False"/>
</record>
</odoo>
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อRelated Posts | ตอบกลับ | มุมมอง | กิจกรรม | |
---|---|---|---|---|
|
1
ก.ย. 24
|
1544 | ||
|
2
ก.ค. 24
|
1689 | ||
|
1
เม.ย. 24
|
4668 | ||
|
0
ม.ค. 24
|
1332 | ||
|
0
ต.ค. 23
|
1306 |