Skip to Content
Menu
This question has been flagged
1 Reply
11183 Views

Hi,
I need help in coding.
first I have a selection type field with 3 choices in the field ('a', 'b', 'c') and 3 fields of Char type.

I need help in coding, for example, the selection field is selected by input 'a', then the 3 char type fields are automatically filled with values ​​that have been set before, for example, the value is:
field1 = 2000
field2 = 3000
field3 = 5000

and for the selection field 'b' or 'c' is the same but with different values.
for another example, I select the selection field to 'b', the value changes immediately according to the value that has been set, as the case when I select 'a'.

My Code:

class ParkingPoint(models.Model):
    _name='parking_point'
        
    parking_zone=fields.Selection([('a','Zona Pusat'),
                                   ('b','Zona Menengah'),
                                   ('c','Zona Pinggiran'),
                                   ],string='Zona parkir', copy='False' ,default='a')
    two_wheels = fields.Integer(string='Motor')
    four_wheels = fields.Integer(string='Mobil Umum')
    box_car = fields.Integer(string='Mobil Box')
    big_car = fields.Integer(string='Bus / Truk')
    
    @api.depends
    def harga(self):
        _default= {
                'two_wheels' : '2000'
                }


Beforehand, any answer I would appreciate. Thanks you 😃

Avatar
Discard
Best Answer

Example for you:

  @api.onchange('parking_zone')
def harga(self):
for rec in self:
if rec.parking_zone == 'a':
rec.two_wheels = 2000
rec.four_wheels = False
elif rec.parking_zone == 'b':
rec.two_wheels = False
rec.four_wheels = 3000
else:
....



Avatar
Discard
Related Posts Replies Views Activity
0
Dec 24
44
2
Oct 24
217
1
Aug 24
577
2
Jul 24
267
1
Jul 24
289