Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

v13 : Tree/Many2one add dynamic domain according value in parent.field

Subscriure's

Get notified when there's activity on this post

This question has been flagged
3 Respostes
4013 Vistes
Avatar
"Vincent DUBREIL"

Hello,

Here is my problem

In account.move form, there is an invisible field Type wich can take values (in_invoice, out_invoice,...)

In the one2many field invoie_line_ids, there is a column "analytic_account_id"

I need to change the domain of this column according i'm in an in_invoice type or out_invoice type.


I tried with a syntax like ('parent.type', '=', 'in_invoice') but it seems that parent can be used only on the right of the '='


How can i do that?

0
Avatar
Descartar
Avatar
Malay Khamar (Serpent Consulting Services Pvt. Ltd.)
Best Answer

Hi Vincent DUBREIL,

Can you please share your full requirement. Because yes in the domain, you can not use parent in the left side of the domain arguments, but in the attrs yes you can use. You can try the below two options that might be work for you.

If you are going specific to the domain then you can try the Many2one field (move_id) of your One2many field (invoie_line_ids) just like ('move_id.type', '=', 'in_invoice'). 

Another one is the related field. You can create the related field of the parent type field in the invoie_line_ids model and try with that related field insted of the parent type : ('related_field_type', '=', 'in_invoice').

Hope it will help you.

Updated Answer:
Ok as per your requirement, you can add this domain on the analytic account field in invoice lines tree view: 

              domain="context.get('default_move_type') in ('out_invoice', 'out_refund', 'out_receipt') and [('name', 'ilike', 'FCT_')]"


Hope it will help you.

2
Avatar
Descartar
"Vincent DUBREIL"
Autor

Hi Malay,
could you, please, give me more informations according my last answer because i still haven't found the solution!

Malay Khamar (Serpent Consulting Services Pvt. Ltd.)

Hi Vincent DUBREIL,

Ok as per Your requirement, you can add this domain into the analytic account field in invoice lines tree view.

domain="context.get('default_move_type') in ('out_invoice', 'out_refund', 'out_receipt') and [('name', 'ilike', "FCT_")]"

"Vincent DUBREIL"
Autor

Hi Malay,

Sorry for the delay
I tried your solution but it doesn't works
error : TypeError: CreateListFromArrayLike called on non-object

Are you sure of this syntax because every similar examples i found, context.get is always on the right side of the domain arguments.
Like : domain="[('id', 'in', context.get('product_ids', []))]"

"Vincent DUBREIL"
Autor

Find part of the problem.
I'm always on version 13 of Odoo and the field is type, not move_type.
But the error is always the same.

I tried to change the syntax like that :
[(context.get('default_type'), 'in', ['in_invoice', 'in_refund', 'in_receipt'])]

But i've got the following error :
ValueError: Invalid field 'in_invoice' in leaf "<osv.ExtendedLeaf: ('in_invoice', 'in', ['in_invoice', 'in_refund', 'in_receipt']) on account_analytic_account (ctx: )>"

Malay Khamar (Serpent Consulting Services Pvt. Ltd.)

Hi Vincent DUBREIL,

Ok, As i see, you have added the condition in the list of tuple , Please try with direct condition as we use it in the domain like this instead of the list of tuple :

domain="context.get('default_type') in ('in_invoice', 'in_refund', 'in_receipt')"

Yes you can add the domain list of tuples after the conditions like:

domain="context.get('default_type') in ('in_invoice', 'in_refund', 'in_receipt') and [('name', 'ilike', 'FCT_')]"

If you pass the domain with list and tuple type, then yes you need the field exist in the domain field model. But you can also add the condition and the domain combination as well .

For reference please check this:

(field name="product_id"
domain="context.get('default_type') in ('out_invoice', 'out_refund', 'out_receipt')
and [('sale_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]
or [('purchase_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]
"/)

Hope it will help you.

Avatar
Adil Akbar
Best Answer

You can follow this: https://youtu.be/XGqXEL2qQmE

Hope it helps,

Thanks

0
Avatar
Descartar
Avatar
"Vincent DUBREIL"
Autor Best Answer

Hi Malay,

thank you for your answer.

Here is my full requirement :

In the view, account.view_move_form, there is the field "invoice_line_ids" with the many2one column "account_analytic_id" linked to the model account.account.

This view is the same used for customer invoices or vendors bills (and refund, receipt,...)

But i need, according the type of the account.move record, to fill this m2o 'account_analytic_id" with differents values.

for types in ("out_invoice","out_refund","out_receipt"), fill with account.account start with "FCT_"

for all other types, fill with all others account_account (except "FCT_")


Hope it is clear enough.

0
Avatar
Descartar
"Vincent DUBREIL"
Autor

Finally i found a solution with a dynamic domain return by python function with @onchange like :

@api.onchange('product_id')
def onchange_product_id(self):
if self.move_id.type in ('in_invoice','in_refund','in_receipt'):
res = {
'domain' : {
'analytic_account_id' : [('name', 'ilike', "FCT_")],
}
}
else:
res = {}

return res

Malay Khamar (Serpent Consulting Services Pvt. Ltd.)

Hi Vincent DUBREIL,
Please check the updated andwer to add domain.

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

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

Registrar-se
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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