跳至内容

odoo获取文件路径“get_resource_path”

可以利用get_resource_path来获取:



# -*- coding: utf-8 -*-



from odoo import models, fields, api

import base64

import xlwt

import xlrd

from io import BytesIO


import os

import openpyxl


from odoo.modules.module import get_resource_path


from datetime import datetime


import logging


_logger = logging.getLogger(__name__)


class edostock_toexcel(models.Model):

    '''

        指标数据

    '''

    _name = 'edostock.toexcel'

    _inherit = ['mail.thread']  # 添加操作记录,还有需要在__manifest__.py中添加 'depends': ['base','mail'],

    _description = '指标档案'


    _rec_name = 'name'

    _order = 'fnumber'


    fnumber=fields.Char(string='文件代码',tracking=True)

    name= fields.Char(string='文件名称', tracking=True)

    myfile = fields.Binary('文件')



    def generate_excel_mo(self, task_ids):

        #利用最常用的openpyxl库

        # 读取标准模板文件

        #module_name模块名称

        module_name = 'edostock'

        template_relative_path = 'static/src/excel/my_template.xlsx'

        #获取文件路径

        template_path= get_resource_path(module_name, template_relative_path)

        #打印文件路径

        print(template_path)

博客
ODOO在安装模块时自动设置系统参数