2016-06-09 73 views
0

我試圖用分層視圖爲產品類別創建我自己的自定義模塊。分類查看產品分類odoo V8

我的主要要求是,我將能夠創建一個與摺疊,展開能力的觀點。

下面是一個例子:

|分類根(展開)

|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> 

Howerver我沒有關於如何顯示層次視圖的線索。

+0

你lookinf的後端或網站 – prakash

+0

Nope.Actually我創建沒有繼承我的自定義產品類別。該模型正在工作。只有視圖不起作用。所有類別都顯示爲通常的VIew,而不是分層視圖。我明白,域名過濾器是解決方案,但它不適合我 –

回答

0

你的情況,你必須有定義對象中的孩子關係。 只需要按照產品基本模塊中的產品基本模塊的Odoo基本插件

只需檢查下面的代碼並添加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自動設置你的父和子類型列表視圖。

我希望我的回答可以有助於您:)

+0

嘿DaSaDiYa柴泰亞感謝您的快速答案。我用你的觀點與我的模型相結合,但我無法得到所需的分層視圖。我是否需要繼承產品類別視圖?因爲我刪除了繼承視圖行。 –

+0

基本模塊已經不存在需要繼承它,如果你可以做一個自定義,然後創建一個單獨的對象,做事情正如我所說 –

+0

我已經修改了我在上面的代碼,你勸我但我很遺憾說。但它不是工作樹不顯示在層次結構視圖 –