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

How to compare date in domain from model?

Subscribe

Get notified when there's activity on this post

This question has been flagged
invoiceoverdue_paymentodoo12
3 Replies
12760 Views
Avatar
thanhps

Hi,

I would like to display list of overdue invoices inside a tab (notebook/page) but it didn't work. 

The problem is the domain statement cannot calculate today value.

I moved the domain to view but it did not work also.

Please help me to resolve this issue. Thank you!

Here is my code

_inherit = 'res.partner'

overdue_invoice_ids = fields.One2many('account.invoice', 'partner_id', 'Overdue Invoices', readonly=True,
domain=[('state', 'in', ['open']), ('type', 'in', ['out_invoice']),
('date_due', '<', fields.Date.context_today)])
<field name="overdue_invoice_ids" nolabel="1">
<tree string="Invoice">
<field name="date_invoice"/>
<field name="number"/>
<field name="commercial_partner_id" invisible="1"/>
<field name="reference" invisible="1"/>
<field name="name" invisible="1"/>
<field name="date_due"/>
<field name="origin"/>
<field name="amount_untaxed" string="Tax Excluded" sum="Total"/>
<field name="amount_tax" sum="Total"/>
<field name="amount_total_signed" string="Total" sum="Total"/>
<field name="residual_signed" string="Amount Due" sum="Amount Due"/>
<field name="currency_id" invisible="1"/>
<field name="company_currency_id" invisible="1"/>
<field name="state"/>
<field name="type" invisible="context.get('type',True)"/>
</tree>
</field>
0
Avatar
Discard
Avatar
thanhps
Author Best Answer

I tried to resolve it by myself and luckily it works.

Here is my solution in model, with nothing change in view:

_inherit = 'res.partner'

@api.model
def _get_overdue_invoices(self):
today = fields.Date.context_today(self).strftime('%Y-%m-%d')
self.overdue_invoice_ids = self.env['account.invoice'].search(
[['state', '=', 'open'], ['type', '=', 'out_invoice'], ['date_due', '<', today]])

overdue_invoice_ids = fields.One2many('account.invoice', 'partner_id', 'Overdue Invoices',
compute='_get_overdue_invoices')

Thanks all for your help!


0
Avatar
Discard
Avatar
Jainesh Shah(Aktiv Software)
Best Answer

Hello @ThanhPs,

You can use this,

domain=[('state', 'in', ['open']), ('type', 'in', ['out_invoice']),('date_due', '<', context_today().strftime('%Y-%m-%d'))]

Regards,




Email: odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

0
Avatar
Discard
thanhps
Author

@Aktiv software,

Thank you for your quick response! I already tried it but it seems valid in view only.

I am trying to add these domain in a model then it showed an error.

NameError: name 'context_today' is not defined

I also tried with ('date_due', '<', fields.Date.context_today) but it showed a SQL error:

ERROR: invalid input syntax for type date: "<function Date.context_today at 0x00000228D18407B8>"

LINE 1: ...invoice'))) AND ("account_invoice"."date_due" < '<function...

Avatar
faOtools
Best Answer

context_today is a method, you should add '()'. Otherwise you compare string to built-in method. So:

('date_due', '<', fields.Date.context_today())

UPDATE:
yes, context_today requires a record to check timezone. Hence, it might be used only 
in methods where you have self (recordset). In domain you can do it through lambda, like lamda self: self.env.user
(not sure about syntax here)

However, I guess it is better to use  today() instead of context_today, which doesn't require timezone.
I guess, timezone is not a big deal in your case:
('date_due', '<', fields.Date.today())

0
Avatar
Discard
thanhps
Author

@Odoo Tools

I tried it and still got an error, because I don't have something like 'self' as an argument:

This below is the error message:

('date_due', '<', fields.Date.context_today())])

TypeError: context_today() missing 1 required positional argument: 'record'

faOtools

Have a look at the answer update

thanhps
Author

Thank you so much for your help!

However, I prefer to use date with timezone in my case.

I updated my answer, take a look at it, pls.

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
Open an invoice using XMLRPC
invoice odoo12
Avatar
Avatar
2
May 20
5789
How to modify validated invoice?
invoice odoo12
Avatar
Avatar
Avatar
2
Nov 18
4962
How to control auto post for journal entry comes from invoices in Odoo12?
invoice journal_entry odoo12
Avatar
0
Jan 22
4199
Odoo12: TypeError: post() got an unexpected keyword argument 'invoice' Solved
invoice typeerror odoo12
Avatar
Avatar
3
Feb 20
17314
[v12] propagate custom field from invoice to invoice report
invoice invoicereport odoo12
Avatar
Avatar
3
Dec 19
5444
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