【问题标题】:HIERARCHICAL VIEW For Product Category odoo V8产品类别 odoo V8 的层次结构视图
【发布时间】:2016-06-09 08:44:55
【问题描述】:

我正在尝试使用分层视图为产品类别创建自己的自定义模块。

我的主要要求是能够创建具有折叠、展开功能的视图。

这是一个例子:

|类别根目录(展开)

 |Category A  (UNFolded)

         |Sub Category A1

 |Category B (UnFolded)

         |Sub Category B1

         |Sub Category B2

         |Sub Category B3

 |Category C (Folded)

如果我点击类别 C 行,我将能够展开它并查看它的子类别。

我尝试了以下方法: 对于班级

 class odepoCategory(models.Model):
        _name = 'odepo.category'
        name = fields.Char(string='Nom Category')
        parentCategory = fields.Many2one('odepo.category', string='Categorie Pére', select=True, ondelete='cascade')
        subCategories = fields.One2many('odepo.category', 'name', string='Sous Categories')

为了风景

<?xml   version="1.0"?>
<openerp>
  <data>

<record model="ir.ui.view" id="enquiry_tree_view_leads">
    <field name="name">view.enquiry.leads.tree</field>
    <field name="model">odepo.category</field>
    <field name="field_parent">subCategories</field>
    <field name="arch" type="xml">
        <tree toolbar="True" string="Enquiry Leads">
        </tree>
    </field>
</record> 

<record model="ir.ui.view" id="enquiry_tree_view_leads">
    <field name="name">view.enquiry.leads.form</field>
    <field name="model">odepo.category</field>
    <field name="type">form</field>
    <field name="arch" type="xml">

    <form string="Shipping Information">            
        <group>
            <field name="parentCategory"/>
            <field name="name"/>
   <!--         <field name="subCategories"/> -->
        </group>
        </form>

    </field>
</record> 

 <record id="product_category_action" model="ir.actions.act_window">
        <field name="name">Products by Category</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">odepo.category</field>
        <field name="domain">[('parentCategory','=',False)]</field>
        <field name="view_type">tree</field>
        <field name="help" type="html">
          <p>
            Here is a list of all your products classified by category. You
            can click a category to get the list of all products linked to
            this category or to a child of this category.
          </p>
        </field>
    </record>

                <!--    Action  to  open    To-do   Task    list    -->
                <act_window id="action_todo_task"
                        name="To-do Task"
                        res_model="odepo.category"
                        view_mode="tree,form"   />
                <!--    Menu    item    to  open    To-do   Task    list    -->
                <menuitem   id="menu    _todo_task"
                        name="To-Do Tasks"
                        parent="mail.mail_feeds"
                        sequence="20"
                        action="action_todo_task"   />
        </data>
</openerp>

但是我不知道如何显示分层视图。

【问题讨论】:

  • 您正在寻找后端或网站
  • Nope.Actually 我正在创建没有继承的自定义产品类别。该模型正在工作。只有视图不起作用。所有类别都显示为通常的 VIew,而不是分层视图。我知道域过滤器是解决方案,但它不适合我

标签: view odoo-8 hierarchical


【解决方案1】:

在您的情况下,您必须在该对象中定义 parentchild relationship。 只需要遵循 Odoo 基础插件中 Product Base Module 中的 product.category 对象

只需检查下面的代码并添加 parent_id 和 child_id 关系。

parent_id 使其成为 many2one 关系类型字段

child_id 设为 one2many 关系类型字段

_name = "product.category"
_description = "Product Category"
_columns = {
    'name': fields.char('Name', required=True, translate=True, select=True),
    'complete_name': fields.function(_name_get_fnc, type="char", string='Name'),
    'parent_id': fields.many2one('product.category','Parent Category', select=True, ondelete='cascade'),
    'child_id': fields.one2many('product.category', 'parent_id', string='Child Categories'),
    'sequence': fields.integer('Sequence', select=True, help="Gives the sequence order when displaying a list of product categories."),
    'type': fields.selection([('view','View'), ('normal','Normal')], 'Category Type', help="A category of the view type is a virtual category that can be used as the parent of another category to create a hierarchical structure."),
    'parent_left': fields.integer('Left Parent', select=1),
    'parent_right': fields.integer('Right Parent', select=1),
}

为产品类别视图 XML 文件添加代码:

    <record id="product_category_tree_view" model="ir.ui.view">
        <field name="name">product.category.tree</field>
        <field name="model">product.category</field>
        <field name="field_parent">child_id</field>
        <field name="arch" type="xml">
            <tree toolbar="True" string="Product Categories">
                <field name="name"/>
            </tree>
        </field>
    </record>
    <record id="product_category_action" model="ir.actions.act_window">
        <field name="name">Products by Category</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">product.category</field>
        <field name="domain">[('parent_id','=',False)]</field>
        <field name="view_type">tree</field>
        <field name="view_id" ref="product_category_tree_view"/>
        <field name="help" type="html">
          <p>
            Here is a list of all your products classified by category. You
            can click a category to get the list of all products linked to
            this category or to a child of this category.
          </p>
        </field>
    </record>

在您的 XML 文件中,您必须在树视图中将 field_parent 设置为 child_id 和 toolbar="True"。 在您的产品类别操作视图中,只需添加域 [('parent_id','=',False)]

如果你配置好,Odoo会自动为你设置父子类型列表视图。

希望我的回答对你有帮助:)

【讨论】:

  • 嘿,DaSaDiYa ChaiTAnYa 感谢您的快速回答。我将您的视图与我的模型结合使用,但是我无法获得所需的分层视图。我需要继承产品类别视图吗?因为我删除了继承视图线。
  • 基本模块已经没有必要继承它,如果你可以自定义一个然后创建一个单独的对象并按照我提到的那样做这些事情
  • 我已经按照你的建议修改了我的代码,但正如我所说的那样。但不幸的是,它不起作用树没有显示在分层视图中
  • 好的,但我提到的做同样的事情并检查正确的视图类型默认值,因为必须在操作中需要表单类型..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-20
  • 2010-09-16
  • 1970-01-01
  • 1970-01-01
  • 2014-04-15
  • 1970-01-01
相关资源
最近更新 更多