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

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

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

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

thankyou for the response,

can you tell me how?

or what code should I make?

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 25
12080
1
thg 12 19
9780
4
thg 1 19
9470
1
thg 1 19
6414
2
thg 7 18
14588