Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

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

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
invoiceweek_numberfieldpostgresqlreport
11 Besvarelser
8384 Visninger
Avatar
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
Avatar
Kassér
Avatar
Pascal Tremblay
Forfatter Bedste svar

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
Avatar
Kassér
Avatar
Axel Mendoza
Bedste svar

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
Avatar
Kassér
Pascal Tremblay
Forfatter

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
Forfatter

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
Forfatter

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
Forfatter

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
Forfatter

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
Forfatter

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!

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
Show full state on invoice
address invoice field report
Avatar
0
maj 15
3550
report field structured communication
invoice field report bba
Avatar
0
mar. 15
4735
Add Payment Terms in Report (Odoo Studio) Løst
invoice field report payment_terms Studio
Avatar
Avatar
1
jan. 20
4533
[18.0] invoice report looks OK when previewing but fonts scaled up and sections overlap when printed Løst
invoice report
Avatar
Avatar
Avatar
2
jun. 25
3241
Group Invoice Lines by Sales Order
invoice report
Avatar
Avatar
Avatar
Avatar
Avatar
4
maj 24
6916
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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