【问题标题】:Filtering data from one menu to another menu将数据从一个菜单过滤到另一个菜单
【发布时间】:2017-10-17 05:45:29
【问题描述】:

我在制造模块-> 产品表单中有一个复选框(命名为“原材料”)

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

如何在 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"/>

提前致谢

【问题讨论】:

  • 欢迎来到stackoverflow。你必须先继承保存按钮@Aravind Mano
  • 但是在那个Products表单中已经有两个复选框,一个用于保存Sales模块-> Products中的数据,另一个用于保存Purchase module-> Products中的数据。当我点击原材料复选框时,我希望执行相同的操作

标签: python xml openerp


【解决方案1】:
  1. 重写 Create 函数
  2. 检查布尔值是否(True/False)
  3. 如果为 true,则创建字典并传递表单值

例如:

@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)

【讨论】:

    【解决方案2】:

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

    <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>
    

    【讨论】:

    • 它不工作。如果我通过单击原材料复选框保存在产品中,它也会保存在产品形式中。但它不应该,而是应该保存在原材料菜单中,这就是我在这里想要实现的目标。
    【解决方案3】:
          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"/>
    

    【讨论】:

      猜你喜欢
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-01
      • 2015-07-13
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      相关资源
      最近更新 更多