zoukankan      html  css  js  c++  java
  • Odoo中同步更新模板文件的文件名

    效果:

    PY文件代码:

    class RhwlDataUploadWizard(osv.osv_memory):
        _name = 'rhwl.data.upload.wizard'
    
        _columns = {
            "excel_name": fields.char(u"EXCEL文件名"),
            "excel_file_templet": fields.binary(u"模板下载"),
            "setting_id": fields.many2one("rhwl.lims.base.setting", string=u"检测项目", domain="[('is_product','=',True)]"),
            "operation_type": fields.selection([("1", u"样本信息导入"),
                                                ("2", u"实验结果上传"),
                                                ("3", u"更新样本信息")], u"操作类型", required=True),
            "file_bin": fields.binary(string=u"文件"),
        }
    
    
        _defaults = {
            "operation_type": "1",
        }
    
        def _get_data_templet(self, setting_code, operation_type):
            project_path = os.path.dirname(os.path.dirname(__file__))
            excel_name = ""
            if operation_type == "1":
                excel_name = "Virus_Sample_Templet_HPV"
    
            if operation_type == "2":
                excel_name = "Virus_Result_Templet_Acid"
    
            if operation_type == "3":
                excel_name = "Virus_Update_Sample_Templet"
    
            if not excel_name:
                return False
    
            templet_path = os.path.join(project_path, "templet%s%s.xls" % (os.sep, excel_name))
            with open(templet_path, 'rb') as fp:
                excel_templet = base64.encodestring(fp.read())
    
            return excel_templet
    
        @api.onchange("setting_id", "operation_type")
        def onchange_setting_operation(self):
            if self.operation_type and self.setting_id:
                self.excel_file_templet = self._get_data_templet(self.setting_id, self.operation_type)
                if self.operation_type == "1":
                    self.excel_name = "Create_Sample_Templet.xls"
                elif self.operation_type == "2":
                    self.excel_name = "Sample_Result_Templet.xls"
                elif self.operation_type == "3":
                    self.excel_name = "Update_Sample_Templet.xls"

    XML文件:

    <record id="rhwl_data_upload_wizard_view_form" model="ir.ui.view">
                <field name="name">rhwl data upload wizard</field>
                <field name="model">rhwl.data.upload.wizard</field>
                <field name="arch" type="xml">
                    <form string="Parameters">
                        <group>
                            <field name="excel_name" class="excel_name"   invisible="1"/>
                            <field name="excel_file_templet" class="file_templet" filename="excel_name" readonly="1" />
                            <field name="operation_type"  style='60%' />
                            <field name="setting_id"  style='60%' />
                            <field name="file_bin" />
                        </group>
                        <footer>
                            <button name="action_data_upload" string="上传" type="object"  class="oe_highlight"/>
                            or
                            <button string="Cancel" class="oe_link" special="cancel" />
                        </footer>
                    </form>
    
                </field>
            </record>
    
            <record id="action_rhwl_data_upload" model="ir.actions.act_window">
                <field name="name">数据上传</field>
                <field name="type">ir.actions.act_window</field>
                <field name="res_model">rhwl.data.upload.wizard</field>
                <field name="view_type">form</field>
                <field name="view_mode">form_data_upload_wizard</field>
                <field name="context">{'data_update':'1'}</field>
                <field name="target">new</field>
            </record>

    JS文件:

        instance.web.views.add('form_data_upload_wizard', 'instance.web.rhwl_virus.FormView');
        instance.web.rhwl_virus.FormView = instance.web.FormView.extend({
            init: function () {
                this._super.apply(this, arguments);
                var self = this;
            },
            on_form_changed: function() {
                this._super.apply(this, arguments);
                var self = this;
                var excel_name = self.$el.find(".excel_name").children("input").val();
                if(excel_name){
                    self.$el.find(".file_templet").children(".oe_form_uri").html(excel_name);
                }
            }
        });
  • 相关阅读:
    SpringCloud Alibaba开篇:SpringCloud这么火,为何还要学习SpringCloud Alibaba?
    SpringBoot整合原生OpenFegin的坑(非SpringCloud)
    Git入门教程,详解Git文件的四大状态
    全世界最强的算法平台codeforces究竟有什么魅力?
    设计模式第二篇,链式方法模式
    matplotlib设置颜色、标记、线条,让你的图像更加丰富
    20行代码实现,使用Tarjan算法求解强连通分量
    深入理解SVM,详解SMO算法
    手把手教你配置git和git仓库
    设计模式 | Catalog设计模式,抵御业务方需求变动
  • 原文地址:https://www.cnblogs.com/dancesir/p/14606779.html
Copyright © 2011-2022 走看看