Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

How to compare date in domain from model?

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
invoiceoverdue_paymentodoo12
3 Răspunsuri
12765 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
thanhps
Autor Cel mai bun răspuns

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
Imagine profil
Abandonează
Imagine profil
Jainesh Shah(Aktiv Software)
Cel mai bun răspuns

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
Imagine profil
Abandonează
thanhps
Autor

@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...

Imagine profil
faOtools
Cel mai bun răspuns

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
Imagine profil
Abandonează
thanhps
Autor

@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
Autor

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!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Open an invoice using XMLRPC
invoice odoo12
Imagine profil
Imagine profil
2
mai 20
5793
How to modify validated invoice?
invoice odoo12
Imagine profil
Imagine profil
Imagine profil
2
nov. 18
4964
How to control auto post for journal entry comes from invoices in Odoo12?
invoice journal_entry odoo12
Imagine profil
0
ian. 22
4201
Odoo12: TypeError: post() got an unexpected keyword argument 'invoice' Rezolvat
invoice typeerror odoo12
Imagine profil
Imagine profil
3
feb. 20
17319
[v12] propagate custom field from invoice to invoice report
invoice invoicereport odoo12
Imagine profil
Imagine profil
3
dec. 19
5447
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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