Python 为什么主窗体中的“创建”按钮不起作用?

Python 为什么主窗体中的“创建”按钮不起作用?,python,odoo,Python,Odoo,当我点击“附加PDF”按钮时,列表表单打开,但是 “创建”按钮不起作用。但是当我从 主菜单,然后一切都好。有什么问题 model.py from odoo import models, fields, api class AttachPDF(models.Model): _name = 'attach.pdf' product_id = fields.Many2one('product.template', string='Product', required=True)

当我点击“附加PDF”按钮时,列表表单打开,但是 “创建”按钮不起作用。但是当我从 主菜单,然后一切都好。有什么问题

model.py

from odoo import models, fields, api


class AttachPDF(models.Model):
    _name = 'attach.pdf'

    product_id = fields.Many2one('product.template', string='Product', required=True)
    product_attribute_value_id = fields.Many2one('product.attribute.value', string='Attribute Value',
                                                 required=True, ondelete='cascade', index=True)
    file = fields.Binary(string="Upload file")
    file_name = fields.Char("File Name")
views.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
  <data>  
    <record id="attach_pdf_view_form" model="ir.ui.view">
      <field name="name">Attach PDF Form</field>
      <field name="model">attach.pdf</field>
      <field name="arch" type="xml">
        <form>
          <group>
            <field name="product_id"/>
            <field name="product_attribute_value_id"/>
          </group>
          <group>
            <field name="file" widget="binary" filename="file_name" string="Binary"/>
          </group>
        </form>
      </field>
    </record>

    <record id="attach_pdf_view_tree" model="ir.ui.view">
      <field name="name">Attach PDF List</field>
      <field name="model">attach.pdf</field>
      <field name="arch" type="xml">
        <tree>
          <field name="product_id"/>
          <field name="product_attribute_value_id"/>
          <field name="file_name" readonly="1"/>
        </tree>
      </field>
    </record>

    <record id="attach_file_wizard" model="ir.actions.act_window">
      <field name="name">Attach PDF</field>
      <field name="type">ir.actions.act_window</field>
      <field name="res_model">attach.pdf</field>
      <field name="view_type">form</field>
      <field name="view_mode">tree,form</field>
      <field name="domain" > [('product_id', '=', context.get('product_name'))]</field>
      <field name="view_id" ref="attach_pdf_view_tree"/>

    </record>

    <record id="view_form_product_attr_pdf" model="ir.ui.view">
      <field name="name">attach_pdf_attribute_product_product_template_only_form_view</field>
      <field name="model">product.template</field>
      <field name="inherit_id" ref="product.product_template_form_view"/>
      <field name="arch" type="xml">
        <xpath expr="//header/button[@name='121']" position="after">
          <button name="%(attach_pdf_attribute.attach_file_wizard)d" context="{'product_name': name}" string="Attach PDF" type="action" class="oe_highlight"/>
        </xpath>
      </field>
    </record>

  </data>
</odoo>

附上PDF表格
附件.pdf
附上PDF列表
附件.pdf
附上PDF
ir.actions.act\u窗口
附件.pdf
形式
树
[('product_id','=',context.get('product_name'))]
附加\ pdf\属性\产品\产品\模板\仅表单\视图
产品模板
**我是超级用户权限 奥多12*


感谢您的回答***

创建按钮应该可以工作。应过滤所有与当前产品id不同的
产品id
记录

使用操作
对记录进行筛选,如果在树状视图中看不到记录,则表示这些记录已隐藏

如果需要在按钮上下文中用当前产品传递默认值填充
product_id

context="{'default_product_id': active_id}"
要在树状视图中筛选记录并仅显示与当前产品相关的记录,您可以像以前一样使用上下文中的值,但这不是必需的,因为您可以在操作域中使用
active\u id

<field name="domain"> [('product_id', '=', active_id)]</field>
  • 或者,您可以添加一个2任意关系(
    inverse\u name==product\u id
    ),将文档添加到产品模板中

    示例:

    添加One2many关系:

    class ProductTemplate(models.Model):
        _inherit = "product.template"
    
        document_ids = fields.One2many('attach.pdf', 'product_id', 'Documents')
    
    XPath
    表达式之后添加以下代码

    <notebook>
        <page string="Documents">
            <field name="document_ids" widget="one2many_list">
                <tree editable="bottom">
                    <field name="product_attribute_value_id"/>
                    <field name="file_name" invisible="1"/>
                    <field name="file" widget="binary" filename="file_name"/>
                </tree>
            </field>
        </page>
    </notebook>
    
    
    

  • P.S.我也不能更改记录(以列表形式),很明显,当我单击“创建”时,表单不会打开;(当您将目标字段设置为
    new
    时会发生这种情况,请检查我的编辑。Kenly非常感谢!非常有效!为了让我更好地理解Odoo,请阅读哪本书?我很乐意提供帮助,抱歉,我不知道一本书,但我强烈建议您在每次添加一些逻辑时检查,并且毫不犹豫地检查源代码文档。
    <notebook>
        <page string="Documents">
            <field name="document_ids" widget="one2many_list">
                <tree editable="bottom">
                    <field name="product_attribute_value_id"/>
                    <field name="file_name" invisible="1"/>
                    <field name="file" widget="binary" filename="file_name"/>
                </tree>
            </field>
        </page>
    </notebook>