Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3863 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
paź 19
2231
1
sie 18
7985
0
lis 17
38
3
gru 24
4271
5
lip 22
6030