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

Filter Domain Field on Field

Subscribe

Get notified when there's activity on this post

This question has been flagged
openerp7domain_filter
2 Replies
11476 Views
Avatar
Knuckles

Hi guys i have some code like this

On the .py file

...

'date_received' : fields.date("Received Date")

'date_doc' : fields.date("Invoice Date")

...


On the .xml file i want to create search view on list view with filter domain date_received > date_doc, how can i achieve this?

Code below generate error 'undefined'

...

<filter domain="[('date_received','>', date_doc)]" help="Received Invoice"/>

...


Thanks

0
Avatar
Discard
Avatar
Jignesh Jarsaniya
Best Answer

Hello nuckles, 

I do have another solution to solve your problem. Let's create another boolean field to compare date range and use it on filter instead of using both date fields. You can follow the below things in the v7 coding pattern. 

According to v7 pattern

'is_received_date': fields.function(is_received_date, fnct_search=_func_search_is_received_date, method=True, type='boolean', string='Is Received Late')
def _func_search_is_received_date(self, cr, uid, obj, name, args, context):
match_ids = []
query = 'SELECT id FROM account_invoice ' \
'WHERE date_received > date_doc'
cr.execute(query)
for row in cr.fetchall():
match_ids.append(row[0])
if match_ids:
return [('id', 'in', match_ids)]
else:
return [('id', '=', 0)]


def is_received_date(self, cr, uid, ids, fieldnames, args, context=None):
res = {}
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = line.date_received > line.date_doc
return res



According to Odoo v11 and v12 pattern

​compare_date = fields.Boolean(compute="_compute_compare_date", store=True)

@api.depends('date_received', 'date_doc')
def _compute_compare_date(self):
    for record in self:
        if record.date_received and record.date_doc and record.date_received > record.date_doc:
            record.compare_date = True
        else:
            record.compare_date = False

Add the following in your XML file.

<filter domain="[('compare_date','=', True)]" help="Received Invoice"/>

Hope this will help you. Please vote if you find a solution.

Thanks

1
Avatar
Discard
Knuckles
Author

Thanks for the answer, but if i take this approach then the existing record won't be filtered because it only affecting active form. I have to export all of the existing record and then update the compare_date my self so that the filter can work.

Jignesh Jarsaniya

Whenever we are adding any new compute field in Odoo model. It will automatically compute for existing records.

Knuckles
Author

Yes, but the old record won't have the value

Jignesh Jarsaniya

I meant that Odoo is already doing for old records as well.

Knuckles
Author

I'm using Openerp 7, so i can't use @api.depends. Any other way?

Jignesh Jarsaniya

Add a new field with v7 syntax and update the existing record's value by preparing the Postgres query. It might be super easy to update the value of existing record

Knuckles
Author

I still can't get it to update every record. The active is updated fine. Here's my code

the field:

'is_received_date' : fields.function(is_received_date, method=True, type='boolean', string='Is Received Late', store=True)

the method:

def is_received_date(self, cr, uid, ids, fieldnames, args, context=None):

res = {}

for line in self.browse(cr, uid, ids, context=context):

if line.date_received > line.date_doc:

res[line.id] = bool(True)

else:

res[line.id] = bool(False)

return res

Knuckles
Author

I shorten the method to:

def is_received_date(self, cr, uid, ids, fieldnames, args, context=None):

res = {}

for line in self.browse(cr, uid, ids, context=context):

res[line.id] = line.date_received > line.date_doc

return res

Jignesh Jarsaniya

Sorry, I didn't have v7 environment to test it but at least you have the idea now might be you are doing something wrong in code. Thanks

Knuckles
Author

i got it running, we need another function that search the whole record and place it in the field. Here's the code

the field:

'is_received_date' : fields.function(is_received_date, fnct_search=_func_search_is_received_date, method=True, type='boolean', string='Is Received Late')

the method:

def _func_search_is_received_date(self, cr, uid, obj, name, args, context):

match_ids = []

query = 'SELECT id FROM account_invoice ' \

'WHERE date_received > date_doc'

cr.execute(query)

for row in cr.fetchall():

match_ids.append(row[0])

print match_ids, 'lalalala match ids'

if match_ids:

return [('id', 'in', match_ids)]

else:

return [('id', '=', 0)]

def is_received_date(self, cr, uid, ids, fieldnames, args, context=None):

res = {}

for line in self.browse(cr, uid, ids, context=context):

res[line.id] = line.date_received > line.date_doc

return res

Can you edit your answer to this? and i will mark your answer as a correct one.

Jignesh Jarsaniya

Thanks, I did it.

Avatar
Protagonist
Best Answer

Hi,

Try to follow the below link

Filters using xml

0
Avatar
Discard
Knuckles
Author

Yes, i already know how to use normal filtering. But there is no example in the default module that compares 2 field from the same record.

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
Related Posts Replies Views Activity
How to access logged in user details in domain filter in openerp 7
python2.7 openerp7 domain_filter
Avatar
0
Jun 18
3745
Domain Filter is not working on many2many field in OpenERP 7.0
openerp7 domain_filter odoo
Avatar
0
Oct 15
4790
Dynamic Domain for states
domain_filter
Avatar
Avatar
1
May 24
3324
how can i assgin two different filters two same model but with different menu ? Solved
filter product openerp7 domain_filter
Avatar
Avatar
1
Feb 24
5775
Odoo v16 domain, how to create a domain by user.company_id
domain_filter
Avatar
Avatar
1
Nov 22
5927
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