Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Issue: Return dynamic domain for field with on change method In Odoo 17

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
domainonchangeodoo17
7 Replies
14114 Rodiniai
Portretas
Long Duong Nhat
I'm having a problem with returning the domain for the field when executing onchange method.
For the code below, it works fine on odoo version 14. But on odoo version 17, it doesn't work. Can you guys give me a solution to do this?
I want the service_request_ids field to display only according to the selected service_id.

service_id = fields.Many2one('ahamove.service', string='Service')
service_request_ids = fields.Many2many('ahamove.service.request', 'estimate_request_rel','choose_id', 'request_id', string='Request Type')

@api.onchange('service_id')
def _onchange_service_id(self):
for rec in self:
if rec.service_id:
return {'domain': {'service_request_ids': [('service_id', '=', rec.service_id.id)]}}
1
Portretas
Atmesti
Portretas
Kiran K
Best Answer

Hi  Long Duong Nhat,

@api.onchange functions that return a domain have been deprecated from v17.

Check this alternative method,
https://github.com/odoo/odoo/blob/26239b2d0bdbc2f06d50f7739d61c490248b65bb/addons/account/models/account_tax.py#L1633C5-L1633C154


3
Portretas
Atmesti
Long Duong Nhat
Autorius

Hi Kiran K, thank you for your response. I will try your solution now.

Portretas
Long Duong Nhat
Autorius Best Answer

Hi Dương Nguyễn, Kiran K,  Cybrosys Techno Solutions Pvt.Ltd,
Thank you very much for assisting me with different solutions. 
After testing all the solutions, I solved the problem most suitably (By compiling your solutions).

class ChooseDeliveryCarrier(models.TransientModel):
_inherit = 'choose.delivery.carrier'

​service_id = fields.Many2one('ahamove.service', string='Service')
​service_request_domain = fields.Binary(default=[])
​service_request_ids = fields.Many2many('ahamove.service.request', ​'estimate_request_rel','choose_id', 'request_id', string='Request Type')

@api.onchange('service_id')
​def _onchange_service_id(self):
​ ​for rec in self:
​ ​if rec.service_id:
​ ​rec.service_request_domain = [('service_id', '=', rec.service_id.id)]

widget="many2many_tags"
options="{'no_create': True}"
invisible="delivery_type != 'ahamove'"
domain="service_request_domain"
/>

Best regards,
Long Duong Nhat


1
Portretas
Atmesti
Portretas
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,


You can use the compute function instead like this:

service_id = fields.Many2one('ahamove.service', string='Service')

service_request_ids = fields.Many2many('ahamove.service.request', 'estimate_request_rel',

'choose_id', 'request_id', string='Request Type',                       compute='_compute_service_request_ids', store=True)

@api.depends('service_id')

def _compute_service_request_ids(self):

for rec in self:

if rec.service_id:

rec.service_request_ids = self.env['ahamove.service.request'].search([('service_id', '=', rec.service_id.id)])


Hope it helps


1
Portretas
Atmesti
Long Duong Nhat
Autorius

Hi Cybrosys, thank you for the solution. It seems to work, the service_request_ids are all loaded according to the correct service_id. However, service_request_ids is not selectable (it's read-only).

Portretas
Dương Nguyễn
Best Answer

Does adding domain in field definition not work ?

service_request_ids = fields.Many2many(domain="[('service_id', '=', service_id)]")

This assume that service_request_ids containt service_id in it as m2o field

1
Portretas
Atmesti
Long Duong Nhat
Autorius

Hi Duong Nguyen, thank you for your response.
It (domain="[('service_id', '=', service_id)]") doesn't work. When I select it, it cannot load the record

Long Duong Nhat
Autorius

The relationship between service_id and service_request_ids are One2Many.
class AhamoveService(models.Model):
_name = 'ahamove.service'
request_ids = fields.One2many('ahamove.service.request', 'service_id', 'Requests')

class AhamoveServiceRequest(models.Model):
_name = 'ahamove.service.request'
service_id = fields.Many2one('ahamove.service', string='Service')

Dương Nguyễn

Which mean when user choose service_id on form view it will automatically load all related record of 'ahamove.service.request' which have that 'service_id'
If that so, i suggest using compute store with readonly=False

Long Duong Nhat
Autorius

Yes, that's right,
But as far as I understand,
domain="[('service_id', '=', service_id)]" and compute method is a form of the static domain. This means that every time you access the form, it will work as expected. But when you onchange service_id it will not work. I have tried doing this.

Dương Nguyễn

No, i haven't seen any one implement onchange method like you did.
Normally , when implement onchange , it will be used to change some other field value and the most important thing of onchange is not store on the database level.
So i guest u should remove your onchange method and do something like this
@api.depends('service_id')
def _compute_request_ids(self):
all_ahamove_service_request = self.env["ahamove.service.request"].search([("service_id", "in", self.service_id.ids)])
for r in self:
if r.service_id:
r.request_ids = all_ahamove_service_request.filtered(lambda req: req.service_id == r.service_id )
else:
r.request_ids = False

Long Duong Nhat
Autorius

Thanks Duong, I will try your solution now.

Portretas
Adil Akbar
Best Answer

Hi, you can follow this: https://youtu.be/f3mq5fHRPT0

Hope it helps, Thanks

0
Portretas
Atmesti
Long Duong Nhat
Autorius

Thanks so much, Adil Akbar

Portretas
Parth Tilokani
Best Answer

Why are you using binary field to store domain and do you think in xml it will render it in correct format and work? I have not tried the solution but I am curious about why take a binary field?

​service_request_domain = fields.Binary(default=[])
0
Portretas
Atmesti
Portretas
Nicolás
Best Answer

Hi Long,
Thank you so much. I've been searching for days on how to implement this in Odoo 17.
I only added this to my "service_requests_ids" field in the XML view:

widget="many2many_tags"
options="{'no_create': True}"
domain="service_request_domain"

It is important to note that the "service_request_domain" must be included in the XML view file and set to invisible.

Best regards,
Nicolás

0
Portretas
Atmesti
Long Duong Nhat
Autorius

Hi Nicolás,
#python-code
class ChooseDeliveryCarrier(models.TransientModel):
_inherit = 'choose.delivery.carrier'

​service_id = fields.Many2one('ahamove.service', string='Service')
​service_request_domain = fields.Binary(default=[])
​service_request_ids = fields.Many2many('ahamove.service.request', ​'estimate_request_rel','choose_id', 'request_id', string='Request Type')

@api.onchange('service_id')
​def _onchange_service_id(self):
​ ​for rec in self:
​ ​if rec.service_id:
​ ​rec.service_request_domain = [('service_id', '=', rec.service_id.id)]

#xml-code
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_choose_delivery_carrier_form_with_provider" model="ir.ui.view">
<field name="name">view.choose.delivery.carrier.form.with.provider</field>
<field name="model">choose.delivery.carrier</field>
<field name="inherit_id" ref="delivery.choose_delivery_carrier_view_form" />
<field name="arch" type="xml">
<field name="carrier_id" position="after">
<field name="service_id"/>
<field name="service_request_ids" widget="many2many_tags" domain="service_request_domain"/>
<field name="service_request_domain" invisible="1"/>
</field>
</field>
</record>
</odoo>

Thanks and best regards,

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registracija
Related Posts Replies Rodiniai Veikla
How i can Apply onchange method on one2many field ?
domain onchange
Portretas
Portretas
1
rugs. 19
5206
Dynamic domain with Onchange doesn't show value when creating
domain onchange domain_filter
Portretas
Portretas
Portretas
Portretas
3
geg. 24
6518
How to return a domain on field on onchange action ? Solved
domain onchange context
Portretas
Portretas
Portretas
Portretas
3
lapkr. 24
46465
How to return domain on one2many field so that seleted values are not shown in next line
domain one2many onchange
Portretas
1
bal. 23
5943
onchange return domain for one2many product ID Field Solved
domain one2many onchange
Portretas
Portretas
Portretas
Portretas
7
bal. 23
19888
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now