تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
1900 أدوات العرض

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

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
نوفمبر 24
1262
2
مارس 25
2446
0
مايو 24
1239
1
يونيو 24
1910
1
فبراير 24
3531