Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
2000 Представления

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

Аватар
Отменить
Автор

any help please...

Автор

nobody knows why it happened??

Лучший ответ

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

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
нояб. 24
1405
2
мар. 25
2640
0
мая 24
1338
1
июн. 24
2030
1
февр. 24
3732