Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
1849 Visualizações

i am creating 2 views in a single .py file but its not creating views i checked in pgAdmin, and there is no error in log file, please help. (added this .py file in __init__.py file )

from odoo import fields, models


class EmployeeTenure(models.Model):
    _name = 'employee.tenure'
    _auto = False
    _description = 'Employee Tenure'

    employee_id = fields.Many2one('hr.employee', string='Employee')
    name = fields.Char(related='employee_id', string='Employee Name')
    date_start = fields.Date(string='Date')
    tenure_days = fields.Integer(string='Tenure In Days')

    def init(self):
        self._cr.execute(""" 
        CREATE OR REPLACE VIEW employee_tenure as (
        SELECT e.id employee_id, e.name, c.date_start,  
               current_date - c.date_start as tenure_days
          FROM hr_employee e
          LEFT join hr_contract c on e.contract_id = c.id
         ORDER BY e.id)
        """)

class PayslipLineAmt(models.Model):

    _name = 'payslip.line.amt'
    _auto = False
    _description = 'Payslip Line Amount'

    employee_id = fields.Many2one('hr.employee', string='Employee')
    salary_rule_id = fields.Many2one('hr.payslip.line', string='Line Type')
    pl_amount = fields.Float(string='Line Amount')

    def init(self):
        self._cr.execute(""" 
            CREATE OR REPLACE VIEW payslip_line_amt AS (
            SELECT ps.employee_id,
                    pl.salary_rule_id,
                    sum(COALESCE(pl.amount, 0)) AS pl_amount
              FROM hr_payslip ps
              LEFT JOIN hr_payslip_line pl ON ps.id = pl.slip_id
             GROUP BY ps.employee_id, pl.salary_rule_id)
            """)


regards

Avatar
Cancelar
Autor

any help please...

Autor

nobody knows why it happened??

Melhor resposta

Hi,

Ensure that you have created XML files for views, menu items, and actions.You can refer to the following blog:-
https://www.cybrosys.com/blog/how-to-create-sql-view-odoo


Hope it helps

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
1
nov. 24
1230
2
mar. 25
2408
0
mai. 24
1211
1
jun. 24
1870
1
fev. 24
3446