2017-10-12 33 views
2

我想顯示payroll.adjustment.lines中的employee_id字段,並從payroll.adjustment模型的樹視圖中顯示該字段。可能嗎?他們有關係。在model2的樹視圖中顯示model1中的字段

從payroll.adjustment.lines模型

adj_id = fields.Many2one('payroll.adjustment',string="Payroll 
Adjustment",ondelete='cascade') 

payroll.adjustment模型

adjustment_lines = 
fields.One2many('payroll.adjustment.lines','adj_id',string="Adjustment 
lines") 

,並在我的XML

<record id="payroll_adjustment_tree_view" model="ir.ui.view"> 
     <field name="name">payroll_adjustment.tree</field> 
     <field name="model">payroll.adjustment</field> 
     <field name="arch" type="xml"> 
      <tree string="Payroll Adjustment" colors="red:state == 
      'void';green:state == 'draft';blue:state=='confirm'"> 
       <field name="doc_num"/> 
       <field name="company_id"/> 
       <field name="adjustment_lines"/> 
       <field name="date_from"/> 
       <field name="date_to"/> 
       <field name="state"/> 
      </tree> 
     </field> 
    </record> 

<field name="adjustment_lines"/> 

只顯示(2條記錄)不是員工姓名。請幫助我們。謝謝

我試過下面的答案,這是結果。員工姓名顯示虛假

Result

,這是我的樹視圖,其中i稱爲從線路的現場,並顯示它從我的payroll.adjustment模型樹視圖。

tree view code

,這是我的樹視圖的輸出,這隻能說明(記錄)

tree view output

回答

1

它可以工作,當你重寫模式payroll.adjustment.linename_get()方法。下面的代碼示例是希望自己explanory和你的情況一般的例子:

from odoo import models, fields, api 


class MyModel(models.Model): 
    _name = "my.model" 

    another_model_ids = fields.One2Many(
     comodel_name="another.model", inverse="my_model_id", 
     string="Another Model Entries") 


class AnotherModel(models.Model): 
    _name = "another.model" 

    my_model_id = fields.Many2One(
     comodel_name="my.model", string="My Model") 
    number = fields.Integer(string="A Number") 
    yet_another_model_id = fields.Many2One(
     comodel_name="yet.another.model", string="Yet Another Model") 

    @api.multi 
    def name_get(self): 
     # with context flags you can implement multiple 
     # possibilities of name generation 
     # best example: res.partner 
     res = [] 
     for another_model in self: 
      res.append((another_model.id, "{} {}".format(
       another_model.number, 
       another_model.yet_another_model_id.name))) 
     return res 


class YetAnotherModel(models.Model): 
    _name = "yet.another.model" 

    name = fields.Char(string="Name") 

my.model將是你payroll.adjustmentanother.model行和yet.another.modelhr.employee背後employee_id模型。

+0

好吧,先生讓我試試這個 –

+0

我在XML上調用的字段是another_model_ids(adjustment_lines),其中給了我相同的結果(2記錄)。我在XML上打什麼字段?抱歉,我是Odoo的新成員,或者請給我一些有用的鏈接,以便我瞭解它。感謝您的努力sir –

+0

您能否在您的問題中分享您的樹視圖的屏幕截圖? – CZoellner

相關問題