将数据从一个菜单过滤到另一个菜单

时间:2017-10-17 05:45:30

标签: python xml openerp

我在制造模块中有一个复选框 - >产品形式(命名为"原材料")

如果我选中复选框并保存数据,则不应将其保存在产品表单中,否则应将其保存在我在“制造”模块中手动创建的名为“原材料”的单独菜单中。

如何在Odoo v10中实现这一目标?

这是我的xml文件......

<record id="raw_materials" model="ir.ui.view">
            <field name="name">raw.form.inherit.button</field>
            <field name="model">product.template</field>
            <field name="inherit_id" ref="product.product_template_only_form_view"/>
            <field name="arch" type="xml" >
            <xpath expr="//field[@name='name']" position="after">
                     <div name="options" groups="base.group_user">
                            <div>
                                <field name="raw"/>
                                <label for="raw"/>
                            </div>
                      </div>    

             </xpath>
             </field>
</record>



<record id="product_template_view" model="ir.ui.view">
        <field name="name">product.template.search</field>
        <field name="model">product.template</field>
        <field name="arch" type="xml">
            <search string="Product">
                <separator/>
                <filter string="Raw Materials" name="filter_to_raw" domain="[('raw','=',True)]"/>
                <separator/>
            </search>
        </field>
</record>

<record id="product_raw_materials" model="ir.actions.act_window">
            <field name="name">Raw Materials</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">product.template</field>
            <field name="view_mode">kanban,tree,form</field>
            <field name="view_type">form</field>
            <field name="context">{"search_default_filter_to_raw":1}</field>
            <field name="view_id" ref="product.product_template_kanban_view"/>
            <field name="search_view_id" ref="product.product_template_search_view"/>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to define a new product.
              </p><p>
                You must define a product for everything you sell, whether it's
                a physical product, a consumable or a service you offer to
                customers.
              </p><p>
                The product form contains information to simplify the Raw Materials: price, notes in the quotation, accounting data,
                procurement methods, etc.
              </p>
            </field>
        </record>



       <menuitem id="menu_mrp_product_form" name="Raw Materials" action="mrp.product_template_action"
                 parent="mrp.menu_mrp_bom" sequence="8"/>

提前致谢

3 个答案:

答案 0 :(得分:0)

  1. 覆盖创建功能
  2. 检查是否是boolen(真/假)
  3. 如果为true,则创建一个字典传递表单值
  4. 前:

    @api.model
    def create(self, vals):
        if vals.get('boolean_field') == True:
            product_data= {
                        'name':vals.get('partner_name'),
                        'size':vals.get('size'),
                        'price':vals.get('price'),
                         }
            self.env['your.model'].create(product_data)
       else:
          # some code
    
    return super(YourClass, self).create(vals)
    

答案 1 :(得分:0)

只需在原材料操作中添加域,如下所示:

<record id="product_raw_materials" model="ir.actions.act_window">
        <field name="name">Raw Materials</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">product.template</field>
        <field name="view_mode">kanban,tree,form</field>
        <field name="view_type">form</field>
        <field name="context">{"search_default_filter_to_raw":1}</field>
        <field name="domain">[('raw','=',True)]</field>
        <field name="view_id" ref="product.product_template_kanban_view"/>
        <field name="search_view_id" ref="product.product_template_search_view"/>
        <field name="help" type="html">
          <p class="oe_view_nocontent_create">
            Click to define a new product.
          </p><p>
            You must define a product for everything you sell, whether it's
            a physical product, a consumable or a service you offer to
            customers.
          </p><p>
            The product form contains information to simplify the Raw Materials: price, notes in the quotation, accounting data,
            procurement methods, etc.
          </p>
        </field>
    </record>

答案 2 :(得分:0)

      I have found the answer for my question 

     <record id="raw_materials" model="ir.ui.view">
                <field name="name">raw.form.inherit.button</field>
                <field name="model">product.template</field>
                <field name="inherit_id" ref="product.product_template_only_form_view"/>
                <field name="arch" type="xml" >

                    <xpath expr="//field[@name='name']" position="after">

                            <div name="options" groups="base.group_user">
                                <div>
                                    <field name="raw"/>
                                    <label for="raw"/>
                                </div>
                            </div>    

                    </xpath>

                </field>
            </record>

            <record id="***raw_search_view***" model="ir.ui.view"> 
            <field name="name">***raw.product.search***</field>
            <field name="model">product.template</field>
            ***<field name="inherit_id" ref="product.product_template_search_view"/>***
            <field name="arch" type="xml">
                ***<xpath expr="//filter[@name='consumable']" position="after">
                    <seperator/>
                    <filter string="Raw Materials" name="filter_to_raw" domain="[('raw','=',True)]"/>
                </xpath>***
            </field>
            </record>

            <record id="product_raw_materials" model="ir.actions.act_window">
                <field name="name">Raw Materials</field>
                <field name="type">ir.actions.act_window</field>
                <field name="res_model">product.template</field>
                <field name="view_mode">kanban,tree,form</field>
                <field name="view_type">form</field>
                ***<field name="context">{"search_default_filter_to_raw":True,"default_sale_ok":False}</field>***
                <field name="domain">[('raw','=',True)]</field>
                <field name="view_id" ref="product.product_template_kanban_view"/>
                <field name="search_view_id" ref="product.product_template_search_view"/>
                <field name="help" type="html">
                  <p class="oe_view_nocontent_create">
                    Click to define a new product.
                  </p><p>
                    You must define a product for everything you sell, whether it's
                    a physical product, a consumable or a service you offer to
                    customers.
                  </p><p>
                    The product form contains information to simplify the Raw Materials: price, notes in the quotation, accounting data,
                    procurement methods, etc.
                  </p>
                </field>
            </record>



           <menuitem id="menu_mrp_product_form" name="Raw Materials" action="***product_raw_materials***"
                     parent="mrp.menu_mrp_bom" sequence="8"/>