Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

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

Subscribe

Get notified when there's activity on this post

This question has been flagged
3 Replies
4004 Views
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
Discard
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
Discard
"Vincent DUBREIL"
Author

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"
Author

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"
Author

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
Discard
Avatar
"Vincent DUBREIL"
Author 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
Discard
"Vincent DUBREIL"
Author

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!

Sign up
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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