This question has been flagged

Hi,  I want to display customers according to the selected branch. Some customers have empty branches, and some have branches. if it's empty it means it can be used in all branches

so what is displayed is the customer's name according to the selected branch but at the same time you can also search for customers with empty branches


I've tried this but it only displays the name of the customer based on the selected branch, and can't search customers name with an empty branch 


domain= {'domain': {'partner_id': ['|',('branch_id', '=', self.branch_id.id)]}}


And if like this, i can search customer with empty branch, but the name that appears when the branch is selected becomes random again and what appears is not the name of the customer with the selected branch 


domain= {'domain': {'partner_id': ['|',('branch_id', '=', self.branch_id.id),('branch_id', '=', False) ]}}


how can i display customer names based on the selected branch, while at the same time being able to search for customer names with empty branches?

is there any suggestion to solve this problem?


Thanks!

Avatar
Discard
Best Answer

Returning a domain using onchange method has been deprecated in Odoo 14.

I'm using this OCA module to filter field depend on another field.

Web Domain Field | The Odoo Community Organisation | OCA (odoo-community.org)

Avatar
Discard
Best Answer

Hello someone,

You can use below example.

Please find code in comment.

I hope this helps.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

class ResPartner(models.Model):
_inherit = "res.partner"

branch_id = fields.Many2one('branch.branch', "Branch")

class SaleOrderInherit(models.Model):
_inherit = "sale.order"

partner_id = fields.Many2one('res.partner', "Partner")
branch_id = fields.Many2one('branch.branch', "Branch")

@api.onchange('branch_id')
def _get_partner_domain(self):
for rec in self:
return {
'domain': {'partner_id': [('branch_id', '=', rec.branch_id.id)]},
}

Returning a domain using onchange method has been deprecated in Odoo 14.