Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
1986 Zobrazení

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
Zrušit
Autor

any help please...

Autor

nobody knows why it happened??

Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
lis 24
1388
2
bře 25
2620
0
kvě 24
1306
1
čvn 24
2005
1
úno 24
3702