Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
3846 มุมมอง

I have selected field in table one2many.

can i make selection field it to auto increment when i click add item or change selected field to Char ?

in my case i want make position tire being increment

iam using odoo 11


my py code :

class FleetOperations(models.Model):
_inherit = 'fleet.vehicle'

tire_detail = fields.One2many('tire.detail','tire_detail_id',string='Tire Detail')

class TireDetail(models.Model):
_name = 'tire.detail'

tire_detail_id = fields.Many2one('fleet.vehicle', string='Tire Detil')
tire_kmdi = fields.Char(string='KMDI Tire S/N', size=64)
is_tire_kmdi_set = fields.Boolean(string='Is KMDI Tire Srno set?')
position_tire = fields.Selection([('pos_1', 'Posisi 1'), ('pos2', 'Posisi 2'), ('pos3', 'Posisi 3'),
('pos4', 'Posisi 4'), ('pos5', 'Posisi 5'), ('pos6', 'Posisi 6'),
('pos7', 'Posisi 7'), ('posa', 'Posisi A'), ('posb', 'Posisi B'),
('posc', 'Posisi C'), ('posd', 'Posisi D'), ('pose', 'Posisi E'),
('posf', 'Posisi F'), ('posg', 'Posisi G'), ('posh', 'Posisi H'),
('posi', 'Posisi I'), ('posj', 'Posisi J'), ('posk', 'Posisi K'),
('posl', 'Posisi L'), ('posm', 'Posisi M')], string='Posisi Ban')
tire_size = fields.Char(string='Tire Size', size=64)
tire_srno = fields.Char(string='Tire S/N', size=64)
tire_issuance_date = fields.Date(string='Tire Issuance Date')

and xml

<xpath expr="///notebook/page[2]/notebook/page[2]" position="after">
<page string="Tire Detail">
<field name="tire_detail">
<tree editable="top">
<field name="position_tire"/>
<field name="tire_size"/>
<field name="tire_srno"/>
<field name="tire_kmdi"/>
<field name="tire_issuance_date"/>
</tree>
</field>
</page>
</xpath>

can anyone help me

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You can create a list variable for selection field and on create / write method append your list in that variable which will add the value to the selection field.

Try following code:

POSITION_TIRE = [('pos_1', 'Posisi 1'), ('pos2', 'Posisi 2'), ('pos3', 'Posisi 3'),
('pos4', 'Posisi 4'), ('pos5', 'Posisi 5'), ('pos6', 'Posisi 6'),
('pos7', 'Posisi 7'), ('posa', 'Posisi A'), ('posb', 'Posisi B'),
('posc', 'Posisi C'), ('posd', 'Posisi D'), ('pose', 'Posisi E'),
('posf', 'Posisi F'), ('posg', 'Posisi G'), ('posh', 'Posisi H'),
('posi', 'Posisi I'), ('posj', 'Posisi J'), ('posk', 'Posisi K'),
('posl', 'Posisi L'), ('posm', 'Posisi M')]

class TireDetail(models.Model):
...
position_tire = fields.Selection(POSITION_TIRE, string='Posisi Ban')

POSITION_TIRE.append(('xyz', '123')) # append the value to the selection field in create / write method


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ต.ค. 19
2219
1
ส.ค. 18
7960
0
พ.ย. 17
38
3
ธ.ค. 24
4250
One2many domain on the selection แก้ไขแล้ว
5
ก.ค. 22
6003