Skip to Content
Menu
This question has been flagged
1 Odpoveď
4024 Zobrazenia

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

Avatar
Zrušiť
Best Answer

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


Avatar
Zrušiť
Related Posts Replies Zobrazenia Aktivita
0
okt 19
2417
1
aug 18
8239
0
nov 17
38
3
dec 24
4473
5
júl 22
6207