2016-07-26 5 views
1

親フィールドに基づいてone2manyフィールドの列を非表示にする必要があります。 account.invoiceモデルを継承することにより、フィールドinv_typeを追加しました。 account_invoice_lineでは、inv_type = 'utility'の場合、目に見えないフィールド 'quantity'を作る必要があります。親フィールドに基づいてフィールドが表示されないOdoo 8

私はコードの下に試してみました:

のxml:

<record id="ams_invoice_form" model="ir.ui.view"> 
     <field name="name">account.invoice.form</field> 
     <field name="model">account.invoice</field> 
     <field name="inherit_id" ref="account.invoice_form"></field> 
     <field name="inherit_id" ref="ams.3e_invoice_form"></field> 
     <field name="arch" type="xml"> 
      <xpath expr="//notebook/page/field/tree/field[@name='quantity']" position="replace"> 
       <field name="quantity" attrs="{'invisible':[('parent.inv_type,'=','utility')]}" /> 
       <field name="consumed_unit"/> 
       <field name="fixed_charge"/> 
      </xpath> 

     </field> 
    </record> 

それはクライアントのエラーをスロー:

Odoo Client Error 

Error: Unknown field parent.invoice_type in domain [["parent.invoice_type","=","utility"]] 

をソリューションを提案してください..ありがとう..

答えて

0

本当に複雑オードー9:

に適用される属性を使用することをお勧めしますそれはfields_view_get機能に影響を与えるために持っている請求書発行モジュールで
<record id="ams_invoice_form" model="ir.ui.view"> 
     <field name="name">account.invoice.form</field> 
     <field name="model">account.invoice</field> 
     <field name="inherit_id" ref="account.invoice_form"></field> 
     <field name="inherit_id" ref="ams.3e_invoice_form"></field> 
     <field name="arch" type="xml"> 
      <xpath expr="//notebook/page/field/tree/field[@name='quantity']" position="replace"> 
       <field name="quantity" invisible="context.get('ok_invisible', False)"/> 
       <field name="consumed_unit"/> 
       <field name="fixed_charge"/> 
      </xpath> 

     </field> 
    </record> 

、私はあなたがそれがaccount.invoice.lineオブジェクトに影響を与える必要がありますので、請求書の製品リストの列を非表示にすることを理解:

class AccountInvoiceLine(models.Model): 

     _inherit = "account.invoice.line" 

     @api.model 
     def fields_view_get(self, view_id=None, view_type=False, toolbar=False, submenu=False): 
      if self.invoice_id.inv_type == 'utility': 
      self = self.with_context(ok_invisible=True) 
      else: 
      self = self.with_context(ok_invisible=False) 

      return super(AccountInvoiceLine, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) 
0

Odoo 8.0では少しだけ他のものを実装しなければなりませんでした。それは同じロジックを持っていますが、私はsale.orderのfields_view_getメソッドを使用しなければならず、その識別子から注文をロードする必要があります:

class SaleOrder(models.Model): 
    _inherit = 'sale.order' 

    @api.model 
    def fields_view_get(self, view_id=None, view_type=False, toolbar=False, 
         submenu=False): 
     order = False 
     params = self.env.context.get('params', False) 
     if params: 
      order_id = params.get('id', False) 
      if order_id: 
       order = self.browse(order_id) 

     if order and not order.is_agreement: 
      self = self.with_context(hide_agreement_cols=False) 

     result = super(SaleOrder, self).fields_view_get(
      view_id=view_id, view_type=view_type, 
      toolbar=toolbar, submenu=submenu 
     ) 
     return result 
関連する問題