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

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

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

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


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 10 19
2236
1
thg 8 18
8009
0
thg 11 17
38
3
thg 12 24
4286
5
thg 7 22
6053