2017-07-12 83 views
3

我正在使用Odoo 10-e。我正在研究一個示例模塊。 我有5款(客戶,產品,訂單,訂單明細,運動)Odoo - 在父類中篩選子記錄

Customer :

class Customer(models.Model): 
    _name ="amgl.customer" 
    …… all other fields related to customer 
    product_ids = fields.Many2many('amgl.products', string='Products') 

Products :

class Products(models.Model): 
    _name ="amgl.products" 
    …… all other fields related to product 
    customer_ids = fields.Many2many('amgl.customer', string='Customers') 

Order :

class Order(models.Model): 
    _name ="amgl.order" 
    order_line = fields.One2many('amgl.order_line', 'order_id', string='Order Lines') 
    …… all other fields related to Order 

Order Details :

class OrderLine(models.Model): 
    _name = 'amgl.order_line' 

    order_id = fields.Many2one('amgl.order', string='Orders') 
    products = fields.Many2one('amgl.products', string="Products") 
    …… all other fields related to order details 

Movement

class Movement(models.Model): 
    _name = 'amgl.metal_movement' 

    customer = fields.Many2one("amgl.customer", string="Customer", required=True) 
    order_lines = fields.One2many('amgl.order_line','metal_movement_id') 

    …… all other fields related to movement 

什麼,我試圖做的是,我創建一個運動形式,其中用戶將選擇從客戶的客戶下拉首先用戶將添加order_lines,並且他將能夠添加我想要過濾產品的產品,這些產品是相關的與上面選定的客戶一起。我怎樣才能做到這一點 ?自上個月以來我一直在嘗試。

Movement View

<odoo> 
<data> 
    <record id="action_metal_movement" model="ir.actions.act_window"> 
     <field name="name">Metal Movement Request</field> 
     <field name="type">ir.actions.act_window</field> 
     <field name="res_model">metal.movement</field> 
     <field name="view_mode">tree,form</field> 
     <field name="help" type="html"> 
      <p class="oe_view_nocontent_create"> 
      Click to create 
      </p><p> 
      <!-- More details about what a user can do with this object will be OK --> 
      </p> 
     </field> 
    </record> 
    <record id="form_metal_movement" model="ir.ui.view"> 
     <field name="name">Metal Movement Request </field> 
     <field name="model">metal.movement</field> 
     <field name="arch" type="xml"> 
      <form string="Metal Movement"> 
       <sheet> 
        <group> 
        <group string="Metal Movement Request"> 
         <field name="date_create" string="Date Created"/> 
         <field name="reference"/> 
         <field name="metal_movement_type"/> 
         <field name="first_approve"/> 
         <field name="second_approve" domain="[('id', '!=', first_approve)]"/> 
         <field name="customer"/> 
         <field name="sepcial_instruction" widget="html"/> 
        </group> 
        <group string="Metal Movement From"> 
         <group colspan="6"> 
          <field name="custodian"/> 
          <field name="mmf_name"/> 
          <field name="mmf_account_number"/> 
          <field name="mmf_account_type"/> 
         </group> 
         <group string="Metal Movement To" colspan="6"> 
          <field name="mmt_name"/> 
          <field name="mmt_address" attrs="{'invisible':[('metal_movement_type', '=', 'IT')]}"/> 
          <field name="mmt_account_number" /> 
          <field name="mmt_company" attrs="{'invisible':[('metal_movement_type','not in',('AC','IPPU','IT'))]}"/> 
          <field name="pickup_date" string="Pick up Datetime" attrs="{'invisible':[('metal_movement_type','not in',('AC','IPPU'))]}"/> 
         </group> 
        </group> 
        <group string="Metals To Be Moved" colspan="12"> 
         <field name="order_lines"> 
          <tree editable="bottom"> 
           <field name="quantity" string="Quantity"/> 
           <field name="products" domain="[('customer_ids','in', parent.customer)]" string="Product Name"/> 
           <field name="weight" string="Weight"/> 
           <field name="total_weight" string="Total Weight"/> 
          </tree> 
         </field> 
        </group> 
        </group> 
       </sheet> 
      </form> 
     </field> 
    </record> 
    </data> 
    </odoo> 
+0

你能否用你的「amgl.metal_movement」模型來更新你的問題? –

+0

@VikiChavada請檢查,我更新了問題 – Ancient

+1

我想要在視圖中添加order_lines。 –

回答

2

謝謝你的問題的更新用。

首先在產品領域上下文中添加客戶。

<field name="order_lines"> 
    <tree editable="bottom"> 
     <field name="quantity" string="Quantity"/> 
     <field name="products" context="{'customer_id':parent.customer}" string="Product Name"/> 
     <field name="weight" string="Weight"/> 
     <field name="total_weight" string="Total Weight"/> 
    </tree> 
</field> 

然後在產品的模型中寫入它的name_get方法就像這樣。

@api.multi 
def name_get(self): 
    if self.env.context('customer_id',False): 
     customer = self.env['amgl.customer'].browse(self.env.context('customer_id',False)) 
     for product in customer.product_ids: 
      res.append((product.id,product.name)) 
    else: 
     res=super(product_product,self).name_get() 
    return res 

那就是它。

+0

第二行最後是什麼'product_product'? – Ancient

+0

我做了一些更改和工作,謝謝 – Ancient

+1

這是一個類名。 –