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

Do I imperatively have to create a new field on the account.invoice model to display this postgresql view?

Abonare

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

Această întrebare a fost marcată
invoiceweek_numberfieldpostgresqlreport
11 Răspunsuri
8379 Vizualizări
Imagine profil
Pascal Tremblay

Hello all,

I have created a new postgresql view which has the same code than account.invoice.report (totally duplicated). We took the code on Odoo 8. So this report is in the old api.

I want to create a new column in the graph associated to this view : invoice week. Invoice_week is the week in the year of the date_invoice for each invoice.

<record id="view_account_invoice_report_graph_vtm2" model="ir.ui.view">
         <field name="name">account.invoice.report.graph.vtm2</field>
         <field name="model">account.invoice.report.vtm2</field>
         <field name="arch" type="xml">
             <graph string="Invoices Analysis" type="pivot">
                 <field name="fiscal_position" type="row"/>
                 <field name="invoice_week" type="col"/>
                 <field name="price_total" type="measure"/>
                 <field name="nbr" type="measure"/>
             </graph>
         </field>
    </record>


So, I have created a new computed field on the report model. I wanted the invoice_week computed on the fly when the report is generated. My function _finddate is ok and can extract the week of an invoice according to his date_invoice :

'invoice_week' : fields.function(_finddate, string="Semaine de la facture", type='char', readonly=True),


But I get this error :

AssertionError: Fields in 'groupby' must be regular database-persisted fields (no function or
 related fields), or function fields with store=True


My question is : do I have to imperatively create a new stored field on the account.invoice model or it is possible to calculate the invoice_week on the fly according to the date_invoice?

Or : Do postgresql views really work only with stored field somewhere in the database?

EDIT #1

If I add a new field 'invoice_week' on account.invoice model, it would be computed like this. So it would be the week of the year calculated with the date_invoice :

from openerp import models, fields, api, _

from datetime import datetime
class account_invoice(models.Model):
    _inherit = "account.invoice"
    invoice_week = fields.Char(compute='_findweek',string="Semaine de la facture", readonly=True, store=True)
       
    @api.one
    @api.depends('date_invoice')
    def _findweek(self):
        for invoice in self:
            if invoice.date_invoice:
                invoice.invoice_week = datetime.strptime(invoice.date_invoice, "%Y-%m-%d").strftime('%U')




0
Imagine profil
Abandonează
Imagine profil
Pascal Tremblay
Autor Cel mai bun răspuns

After 24 hours... We have found an EASY solution.

I'm sorry if somebody has lost time to help us on this post.

No need to add a new field on account.invoice. No need to add a new field to the account.invoice.report.2.

Just use interval="week" in the column field....

I will remember this one for long time.

We will use this code for the graph view :

<record id="view_account_invoice_report_period_graph_vtm2" model="ir.ui.view">
         <field name="name">account.invoice.report.period.graph.vtm2</field>
         <field name="model">account.invoice.report.vtm2</field>
         <field name="arch" type="xml">
             <graph string="Invoices Analysis" type="pivot">
                 <field name="fiscal_position" type="row"/>
                 <field name="date" interval="week" type="col"/>
                 <field name="price_total" type="measure"/>
             </graph>
         </field>
    </record>
1
Imagine profil
Abandonează
Imagine profil
Axel Mendoza
Cel mai bun răspuns

Hi Pascal

No need to be a persisted since there is no persistence table on the model because this is a model with an sql view behind, not a table, but also include it on the sql query that create the view just like a dummy value. So you could define a new regular field on your model like you did but not as a computed field. Also I think that you may need to redefine the read_group method of that model to include the values for your field.

There is a very complete example of how to include values in the read_group at the product_margin module, you can check it to build your

1
Imagine profil
Abandonează
Pascal Tremblay
Autor

Thanks for all these words.

When you say to 'redefine the read_group method of that model', do you talk about the 'account.invoice.report' model or the 'account.invoice' model?

Axel Mendoza

in the account.invoice.report model

Pascal Tremblay
Autor

So, you say to me that the account.invoice.report model use the read_group method even if it is a postgresql view?

Will give it a try.

Axel Mendoza

Yes, that's were the error came on the first time, from read_group

Pascal Tremblay
Autor

You are right. I have a defined a new method read_group in my new model account.invoice.report.2. And like you said, the read_group method is trigerred when I display my report. Will now try to compute the invoice_week value. THanks

Pascal Tremblay
Autor

I won't be able to realize this project overriding the read_group method. The original account.invoice.report is very complicated. The SQL query is long long long. I'm totally lost in it. I think I will create a new stored field 'invoice_week' on the account.invoice model.

Axel Mendoza

post how you calculate the invoice_week for give you a solution about that in the read_group

Pascal Tremblay
Autor

If you make a move, don't forget that our account.invoice.report.2 new report is in the old api. We took the code in odoo 8. We are on odoo 8.

Pascal Tremblay
Autor

My post has been updated. Thanks

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
Show full state on invoice
address invoice field report
Imagine profil
0
mai 15
3549
report field structured communication
invoice field report bba
Imagine profil
0
mar. 15
4717
Add Payment Terms in Report (Odoo Studio) Rezolvat
invoice field report payment_terms Studio
Imagine profil
Imagine profil
1
ian. 20
4524
[18.0] invoice report looks OK when previewing but fonts scaled up and sections overlap when printed Rezolvat
invoice report
Imagine profil
Imagine profil
Imagine profil
2
iun. 25
3235
Group Invoice Lines by Sales Order
invoice report
Imagine profil
Imagine profil
Imagine profil
Imagine profil
Imagine profil
4
mai 24
6906
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