2017-10-12 7 views
2

私はemployee_idであるpayroll.adjustment.linesからフィールドを表示し、それをpayroll.adjustmentモデルのツリービューから表示したいと考えています。出来ますか?彼らは関係があります。 payroll.adjustment.linesモデルmodel2のツリービューにmodel1のフィールドを表示

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

を表示する従業員の名前とこれは私がラインからフィールドと呼ばれ、私のpayroll.adjustmentモデルからツリービューに表示する私のツリービューです。

tree view code

、これはあなたがモデルpayroll.adjustment.linename_get()メソッドをオーバーライドするときは、仕事ができる私のツリービューの出力であり、それだけのショー(記録)

tree view output

答えて

1

。コード例に従うと、うまくいけば、あなたのケースのための自己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.employeeemployee_idの背後にあるモデルになります。

+0

私はこの1つを試してみましょう –

+0

私がXMLを呼び出したフィールドはanother_model_ids(adjustment_lines)ですが、同じ結果(2レコード)が与えられています。私はXMLのどのフィールドを呼びましたか?申し訳ありません。私はOdooで新しいです、または私にそれを学ぶために私にいくつかの有用なリンクを与えてください。あなたの努力に感謝します –

+0

あなたの質問にあなたのツリービューのスクリーンショットを共有できますか? – CZoellner

関連する問題