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

Generate report from Python by given user and data range

Suscribirse

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

Se marcó esta pregunta
pythonreportingodooV8
1 Responder
7008 Vistas
Avatar
Marcus

I need to generate timesheets report for a given user in a given data range.
I also need to sum the timesheets hours by date so each row in the report has unique date.

I have simple report ready as well as wizard for picking particular user and dates. But I'm having trouble with passing data to the report. When I click the print button on my wizard I get this error:

ProgrammingError: relation "hr_timesheet_karty_wizard" does not exist
LINE 1: INSERT INTO "hr_timesheet_karty_wizard" ("id", "date_from", ...

I'm not really sure what to do with `records`. Should I put them in 'doc_ids' or 'doc_ids'?

I'm also not sure how to sum the records by date.

I'm using Odoo 8.


Here is my python code:

from openerp import api, models, fields
from datetime import datetime

class hr_timesheet_karty_wizard(models.AbstractModel):
    _name = 'hr.timesheet.karty.wizard'
    
    employee_id = fields.Many2one(comodel_name="hr.employee", required=True)
    date_from = fields.Date(default=fields.Datetime.now, required=True)
    date_to = fields.Date(default=fields.Datetime.now, required=True)

    @api.multi
    def print_report(self, data=None):
        
        records = self.env['hr.analytic.timesheet'].search([('employee_id', '=', self.employee_id),('date_from', '>=', self.date_from),('date_to', '<=', self.date_to)])   
        # sum records hours if date is the same (group by date)

        report_obj = self.env['report']
        report = report_obj._get_report_from_name('hr_timesheet_karty.template_hr_timesheet_karty')
        docargs = {
            'doc_ids': self._ids,
            'doc_model': report.model,
            'docs': records,
        }
        return report_obj.render('hr_timesheet_karty.template_hr_timesheet_karty', docargs)



Here is my wizard:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>

    <record id="view_hr_timesheet_karty_wizard" model="ir.ui.view">
        <field name="name">hr.timesheet.karty.wizard.form</field>
        <field name="model">hr.timesheet.karty.wizard</field>
        <field name="arch" type="xml">
        <form string="Leaves by Department">
            <group>
                <field name="employee_id"/>
                <field name="date_from"/>
                <field name="date_to"/>
            </group>
            <footer>
                <button name="print_report" string="Print" type="object" class="oe_highlight"/> or
                <button string="Cancel" special="cancel" class="oe_link"/>
            </footer>
        </form>
        </field>
    </record>

    <record id="action_hr_timesheet_karty_wizard" model="ir.actions.act_window">
        <field name="name">Time sheet report</field>
        <field name="res_model">hr.timesheet.karty.wizard</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="view_hr_timesheet_karty_wizard"/>
        <field name="target">new</field>
    </record>

    <menuitem id="menu_hr_timesheet_karty_wizard"
        name="Time sheet report"
        parent="hr.menu_hr_reporting_timesheet"
        action="action_hr_timesheet_karty_wizard"
        sequence="1"
        icon="STOCK_PRINT"/>
        
  </data>
</openerp>



And here is my report:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <report
        id="action_hr_timesheet_karty"
        string="Time sheet report"
        model="hr.analytic.timesheet"
        report_type="qweb-pdf"
        name="hr_timesheet_karty.template_report_hr_timesheet_karty"
    />
        
    <template id="template_hr_timesheet_karty">
        <t t-call="report.html_container">
            <t t-call="report.external_layout">
                <div class="page">

                    <table class="table table-condensed">
                        <thead>
                            <tr>
                                <th>User</th>
                                <th>Date</th>
                                <th>Time</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr t-foreach="docs" t-as="o">
                                <td><span t-field="o.user_id.name"/></td>
                                <td><span t-field="o.date"/></td>
                                <td class="text-right"><span t-field="o.unit_amount"/> h</td>
                            </tr>
                        </tbody>
                    </table>

                </div>

            </t>
        </t>
    </template>

  </data>
</openerp>



Please help


0
Avatar
Descartar
Avatar
Jainesh Shah(Aktiv Software)
Mejor respuesta

Hello Andrzej,

In v8 , AbstractModel model define with osv.AbstractModel 

Please find following example of AbstractModel:

class hr_timesheet_karty_wizard(osv.AbstractModel)


For searching timesheet records, 

sheet_obj = self.pool['hr.analytic.timesheet']

sheet_ids = sheet_obj.search(cr, uid,

            [('employee_id', '=', self.employee_id),

            ('date_from', '>=', self.date_from),

           ('date_to', '<=', self.date_to)])

Can you please try above object for found timesheet records ?

Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   ​

0
Avatar
Descartar
¿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
[8.0]How to confirm an element's state from: action_confirm (MRP_REPAIR)
python odooV8
Avatar
1
may 21
4939
Odoo8 - Custom pdf name when printing
reporting odooV8
Avatar
Avatar
1
abr 20
4040
How to save data in readonly field in openerp?
python odooV8
Avatar
Avatar
Avatar
Avatar
4
oct 19
10832
How to multiply sequence by non-int Resuelto
python odooV8
Avatar
Avatar
1
ene 18
10266
Employee commission in salary rules
python odooV8
Avatar
Avatar
1
feb 17
5938
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