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

How to compare date in domain from model?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
invoiceoverdue_paymentodoo12
3 Respostes
12761 Vistes
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
Descartar
Avatar
thanhps
Autor 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
Descartar
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
Descartar
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...

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
Descartar
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!

Registrar-se
Related Posts Respostes Vistes Activitat
Open an invoice using XMLRPC
invoice odoo12
Avatar
Avatar
2
de maig 20
5790
How to modify validated invoice?
invoice odoo12
Avatar
Avatar
Avatar
2
de nov. 18
4962
How to control auto post for journal entry comes from invoices in Odoo12?
invoice journal_entry odoo12
Avatar
0
de gen. 22
4200
Odoo12: TypeError: post() got an unexpected keyword argument 'invoice' Solved
invoice typeerror odoo12
Avatar
Avatar
3
de febr. 20
17316
[v12] propagate custom field from invoice to invoice report
invoice invoicereport odoo12
Avatar
Avatar
3
de des. 19
5445
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