Files
app-odoo/app_saas/report/model_new_report.py
2024-12-06 21:37:11 +08:00

78 lines
2.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
##############################################################################
# Copyright (C) 2009-TODAY odooai.cn Ltd. https://www.odooai.cn
# Author: Ivan Deng300883@qq.com
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
# See <http://www.gnu.org/licenses/>.
#
# It is forbidden to publish, distribute, sublicense, or sell copies
# of the Software or modified copies of the Software.
# Create on 2023-10-06
##############################################################################
from odoo import fields, models, tools, api
class ModelNewReport(models.Model):
# Model New Analysis
_name = 'model.new.report'
_auto = False
_description = 'Model New Analysis'
_rec_name = 'name'
# Base field
name = fields.Char(string='Name', readonly=True)
ref = fields.Char(string='Reference', readonly=True)
amount = fields.Float(string="Amount", readonly=True)
date = fields.Datetime(string="Date", readonly=True)
user_id = fields.Many2one('res.users', string='User', readonly=True)
user_login = fields.Char(string='User Login', readonly=True)
company_id = fields.Many2one('res.company', 'Company', readonly=True)
active = fields.Boolean(string="Active", readonly=True)
@api.model
def _select(self):
return '''
SELECT
m.id,
m.name,
m.ref,
m.amount,
m.date,
m.user_id,
u.login AS user_login,
m.company_id,
m.active
'''
@api.model
def _from(self):
return '''
FROM model_new AS m
'''
@api.model
def _join(self):
return '''
JOIN res_users AS u ON m.user_id = u.id
'''
@api.model
def _where(self):
return ''
def init(self):
tools.drop_view_if_exists(self._cr, self._table)
sql = '''
CREATE OR REPLACE VIEW %s AS (
%s
%s
%s
%s
)
''' % (self._table, self._select(), self._from(), self._join(), self._where())
self._cr.execute(sql)