Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

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

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
invoiceweek_numberfieldpostgresqlreport
11 Respuestas
8378 Vistas
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
Descartar
Avatar
Pascal Tremblay
Autor Mejor respuesta

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
Descartar
Avatar
Axel Mendoza
Mejor respuesta

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

¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
Show full state on invoice
address invoice field report
Avatar
0
may 15
3549
report field structured communication
invoice field report bba
Avatar
0
mar 15
4716
Add Payment Terms in Report (Odoo Studio) Resuelto
invoice field report payment_terms Studio
Avatar
Avatar
1
ene 20
4524
[18.0] invoice report looks OK when previewing but fonts scaled up and sections overlap when printed Resuelto
invoice report
Avatar
Avatar
Avatar
2
jun 25
3235
Group Invoice Lines by Sales Order
invoice report
Avatar
Avatar
Avatar
Avatar
Avatar
4
may 24
6906
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

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