Skip to Content
Menu
This question has been flagged
5 Replies
5182 Views

Hello World :D

please help, I want to filter values ​​from fields that are in many2one.
I have tried various ways, but still have difficulties in understanding.

so this my code;

zona_parkir=fields.Char('Zona Parkir', related='location_id.zone_id.name', readonly='True')
location_id=fields.Many2one('parking_location', string='Lokasi', required='True')
 class ParkingLocation(models.Model): #parking_location
_name='parking_location'
_rec_name='name'

name=fields.Char('Lokasi')
zone_id=fields.Many2one('parking_zone', string='Zona')
class ParkingZone(models.Model):
_name='parking_zone' #parking zone
_rec_name='name'

name=fields.Char('Zona Parkir')    billing=fields.Float('Tarif')
information=fields.Text('Keterangan')
 parking_log_ids=fields.One2many('parking_log','parking_log_id',string='Log Parkir')class ParkingLog(models.Model):
_name='parking_log'
_rec_name='vehicle_id'
vehicle_id=fields.Many2one('vehicle',string='Nomor Kendaraan')
vehicle_type_id=fields.Char(string='Jenis Kendaraan', related='vehicle_id.vehicle_type.name', readonly='True')
rate_id=fields.Float('Tarif / Jam', related='vehicle_id.vehicle_type.billing')
user_id=fields.Many2one('res.users',string='Juru Parkir', default=lambda self: self.env.user, readonly='true')
parking_log_id=fields.Many2one('parking_session', string='Sesi Parkir', readonly='True')

    total_rate=fields.Float(string='Total Biaya Parkir',states={'in' : [('readonly', 'False')], 'paid' : [('readonly', 'False')]}, store='True', readonly='True', compute='action_close', track_visibility='onchange')
parking_point_id=fields.Many2one('parking_point',string='Titik Parkir')
parking_location_id=fields.Char('Lokasi Parkir', related='parking_log_id.location_id.name',readonly='True')
parking_zone_rate_id=fields.Char('Zona Parkir', related='parking_log_id.zona_parkir',readonly='True')
parking_hours=fields.Float('Lama Parkir', store='True', readonly='True', compute='action_close', track_visibility='onchange')


class Vehicle(models.Model): _name='vehicle' _rec_name='vehicle_number' vehicle_type=fields.Many2one('vehicle_type',string='Jenis Kendaraan',ondelete='cascade')
    vehicle_number=fields.Char(string='Nomor Kendaraan'
class VehicleType(models.Model): _name='vehicle_type'

    name=fields.Char('Jenis Kendaraan')
    billing=fields.Float('Tarif')

so the point is,  when I select ('location_id')

suppose I make 3 zones in that field,
zone X = B = 2 and C = 3
zone Y = B = 1.5 and C = 2.5
zone Z = B = 1 and C = 2

then the value I previously inputted has been recorded in the "billing" field and when I "add item" in the o2m field, the value in it is the filter result from the zone of one of the zones I selected

What do I think I should do?

maybe there is my code that is not supposed to exist / is not suitable.
also ask for advice :D


I will appreciate all forms of answers, thank you very much :-D

Avatar
Discard
Best Answer

Hello, i understand what you need and here i am going to post a code block that i used to filter the products shown to a user on a sale order:

    def _get_products(self):
        ids = []
        res = {}
        for i in self.sale_order_id.order_line:
            ids.append(i.product_id.id)
        res.update({
                'domain': {
                    'call_product_id': [('id', 'in', ids)],

                }
            })

        return res
So here in the code block, only the products that were added on the original sale order, would get shown on my many2one field with name call_product_id to product.template for another model.

i hope that you can use this for your own good, remember to change the model and the field name too, mine is called call_product_id = fields.Many2one('product.template',string = 'Product')

Riste Kabranov

odoo developer at simplify-erp.com

Avatar
Discard
Author

thank you for the response,

my code now ;

def _get_products(self):

ids = []

res = {}

for i in self.parking_zone_rate.name:

ids.append(i.rate_id.id)

res.update({

'domain': {

'parking_zone_rate_id': [('id', 'in', ids)],

}

})

return res

but still have difficulties in understanding :(

if i use domain like this code, can you help how?

Multiple Condition

Simple condition in programming:

if field1 = 5 or (field2 ! = 10 and field3 = 12)

In OpenERP domain filter, it will be written as:

domain = ['|',('field1','=',5),('&',('field2','!=',10),('field3','=','12'))]

thanks before :D

Best Answer

Hi,

You can filter records by using domain in XML.

If this is not worked then try to send many2one I'd in context and use name_search method to filter record

Avatar
Discard
Author

thankyou for the response,

can you tell me how?

or what code should I make?

Related Posts Replies Views Activity
2
Mar 24
10327
1
Dec 19
8411
4
Jan 19
7788
1
Jan 19
5040
2
Jul 18
13145