2016-12-02 67 views
1

我是Odoo的新手,並且仍然試圖獲取它的視圖。Odoo 8顯示stock_move.picking_id.partner_id在視圖中

我需要在標準視圖中爲採購添加一個字段「供應商」 - 傳入產品,其值應該從stock_move.picking_id.partner_id中獲取 我似乎無法弄清楚如何獲取值的視圖xml中,雖然必要的關係似乎被定義,因爲我可以用python代碼這樣得到它。

這裏的標準視圖定義:

 <record id="view_move_tree_receipt_picking" model="ir.ui.view"> 
     <field name="name">stock.move.tree2</field> 
     <field name="model">stock.move</field> 
     <field name="priority" eval="6"/> 
     <field name="arch" type="xml"> 
      <tree colors="grey:state == 'cancel'" string="Moves"> 
       <field name="date" widget="date"/> 
       <field name="picking_id" string="Reference" invisible="1"/> 
       <field name="origin"/> 
       <field name="product_id"/> 
       <field name="product_uom_qty"/> 
       <field name="product_uom" string="Unit of Measure" groups="product.group_uom"/> 
       <field name="location_id" invisible="1"/> 
       <field name="location_dest_id" invisible="1"/> 
       <field name="create_date" invisible="1"/> 
       <field name="date_expected" invisible="1"/> 
       <button name="%(stock.move_scrap)d" 
        string="Scrap Products" type="action" 
        icon="terp-gtk-jump-to-ltr" context="{'scrap': True}" 
        states="draft,waiting,confirmed,assigned" 
        groups="stock.group_stock_user"/> 
       <field name="state"/> 
       <button name="action_done" states="draft,assigned,confirmed" 
        icon="gtk-go-forward" type="object" groups="stock.group_stock_user" 
        class="oe_highlight" help="Done"/> 
      </tree> 
     </field> 
    </record> 

及有關列定義(跳過無關線簡潔)

class stock_move(osv.osv): 
    _name = "stock.move" 
    _description = "Stock Move" 
    _order = 'date_expected desc, id' 

    _columns = { 
     'picking_id': fields.many2one('stock.picking', 'Reference', select=True, states={'done': [('readonly', True)]}), 
    } 


class stock_picking(osv.osv): 
    _name = "stock.picking" 
    _inherit = ['mail.thread'] 
    _description = "Picking List" 
    _order = "priority desc, date asc, id desc" 

    _columns = { 
     'partner_id': fields.many2one('res.partner', 'Partner', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}), 
    } 

回答

1

不需要定義關係,它已經存在,所以你只需要在stock.move中添加相關字段,並通過繼承現有視圖將該合作伙伴字段添加到stock.move的列表視圖或表單視圖中。

class stock_move(osv.osv): 
    _inherit = "stock.move" 

    _columns = { 
     'partner_id': fields.related('picking_id', 'partner_id', 'Supplier', type='many2one', store=True, readonly=True), 
    } 

現在使用繼承在現有視圖中添加此partner_id字段。

基礎視角ID => stock.view_move_form(它可能在你的情況不同)

<record id="new_view_id" model="ir.ui.view"> 
    <field name="name">stock.form</field> 
    <field name="model">stock.move</field> 
    <field name="inherit_id" ref="stock.view_move_form" /> 
    <field name="priority" eval="40"/> 
    <field name="arch" type="xml"> 
     <!-- field name which you specify here after then new field will be added. --> 
     <field name="existing_field_name" position="after"> 
      <field name="partner_id" /> 
     </field> 
    </field> 
</record> 
+0

謝謝您的回答。聽起來很合理,但我得到的是一個空值列。 – dgeorgiev

+0

您需要重新啓動服務器和升級模塊,如果仍然沒有成功,請通過查詢手動從表(stock_move)手動刪除該partner_id,然後重新啓動服務器和升級模塊。 –

+0

好吧,看起來我設法讓它工作。是的,現有的列導致了問題,所以我重新命名了新的字段。還決定不要存儲=真 – dgeorgiev