Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
1890 Переглядів

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
1253
2
бер. 25
2431
0
трав. 24
1233
1
черв. 24
1894
1
лют. 24
3506