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

hello all,

requirement: want to have same zone to select Rider the Customer is in. (both are in same table) --in below code, last line contains rider_id field, first condition is working fine--

it is showing error as below (searched here and google for "Invalid composed field" but no luck):

Invalid composed field user_id.zone_id in field rider_id default domain ([('category_id.name','ilike','rider'),('zone_id','=',user_id.zone_id)])

definitely i am doing wrong here, please help to correct it.

my model:

class Orders(models.Model):
    _name = 'tests.testsorders'
    _rec_name = 'name'
    _description = "Tests Orders"
    order_date = fields.Date(string="Order Date", required=True, default=datetime.today())
    name = fields.Char(string="Description")
    customer_id = fields.Many2one('res.partner', string="Customer",
                              domain="[['category_id.name','ilike','customer']]", 
                                required=True)
     status = fields.Selection([
        ('pending', 'Pending'),
        ('incomplete', 'InComplete'),
        ('complete', 'Complete')
    ], required=True, string="Order Status", default='pending')
    rider_id = fields.Many2one('res.partner', string="Rider",
                               domain="[('category_id.name','ilike','rider'),
                                ('zone_id','=',customer_id.zone_id)]", required=True)

regards

Avatar
Discard
Best Answer

I think you're getting this error because you're using zone_id which is the field in the customer_id which is in res.partner table not tests.testsorders.
Adding a onchange on customer_id will solve the issue.

@api.onchange("customer_id")
def _onchange_customer_id(self):
res = {
'domain': {
'rider_id': [('zone_id', '=', self.customer_id.zone_id.id)]
}
}
return res


I hope this works for you.

Karan BK

Junior Odoo Developer

Tel: +353 1 886 5684 (IE) +44 121 285 5684 (UK)  +91 964 381 7554 (IN)

Target Integration | CRM • ERP • Cloud

Website LinkedIn | Twitter Facebook YouTube Instagram

Avatar
Discard
Author

thanks @Karan BK for help, but my domain filter contains 2 filters, first is ('category_id.name','ilike','rider') , can i use it as is with what you have mentioned or something to modify? i knew it is very very basic but i am from Oracle, python framework is very new for me, various things i still failed to understand.

Author

also this change not worked as it is showing all entries from res.partner ( not from same Zone as Customer's )

Author

sorry, it works... my fault spelling mistake :)

Author

all done now... thanks again for your help :)

In odoo 14 ,domain on onchange is deprecated.

Related Posts Replies Views Activity
2
Apr 23
1451
2
May 24
35801
2
Nov 22
1475
1
Feb 22
6687
2
Dec 21
2704