基于第一选择框从DB动态加载第二选择框

时间:2014-03-13 05:59:10

标签: openerp

请更正代码,以便根据第一次选择加载第二个选择框。

          type_id        choice_id
            fruit          orange
            fruit          apple
            drinks         coffee
            drinks         tea

现在作为用户从选择框中选择水果的要求的一部分,其他选择框'选择'应该仅用橙色和苹果动态加载。当用户选择饮料作为类型时,应该加载咖啡和茶。

.py文件

         from osv import osv
         from osv import fields
         class solid_base(osv.osv):
              _name='solid.base'
              _columns={

                       'type_id':fields.many2one('solid.type','type'),
                       'choice_id':fields.many2one('solid.choice','choice'),

                       }
         solid_base()

         class solid_type(osv.osv):
             _rec_name='type_id'
             _name='solid.type'
             _columns={

                       'type_id':fields.char('Type :'),

                      }

        solid_type()


      class solid_choice(osv.osv):
           _rec_name='choice_id'
          _name='solid.choice'
          _columns={
                 'choice_id':fields.char('Choice :'),
                 'type_id':fields.many2one('solid.type','Type :'),

                   }

      solid_choice()

XML

    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
     <data>

   <record model="ir.ui.view" id="solid_base_form">
       <field name="name">solid.base.form</field>
           <field name="model">solid.base</field>
           <field name="type">form</field>
           <field name="arch" type="xml">
        <form string="Solid Base">                     
          <field name="type_id" widget="selection"/>
          <field name="choice_id"  domain="[('type_id','=',type_id)]" widget="selection"/>
     </form>
         </field>
    </record>
    <record model="ir.ui.view" id="solid_base_tree">
        <field name="name">solid.base.tree</field>
        <field name="model">solid.base</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="Solid Base">              
       <field name="type_id"/>
       <field name="choice_id"/>
            </tree>
       </field>
    </record>
    <record model="ir.ui.view" id="solid_choice_form">
           <field name="name">solid.choice.form</field>
           <field name="model">solid.choice</field>
           <field name="type">form</field>
           <field name="arch" type="xml">
               <form string="solid.choice">                    
                   <field name="type_id" />
               <field name="choice_id" />

     </form>
          </field>
    </record>



        <record model="ir.actions.act_window" id="action_solid_seq7">
        <field name="name">solid choice</field>
        <field name="res_model">solid.choice</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>

    <record model="ir.actions.act_window" id="action_solid_seq6">
        <field name="name">solid base</field>
        <field name="res_model">solid.base</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>


    <menuitem id="menu_solid_base_super_main"  name="Solid Base"/>
    <menuitem id="menu_solid_base_main" parent="menu_solid_base_super_main" name="New Solid Base"/>
    <menuitem id="menu_solid_base1" parent="menu_solid_base_main"
              name="New Solid Base1" action="action_solid_seq6"/>
              <menuitem id="menu_solid_base2" parent="menu_solid_base_main"
              name="New Solid Base2" action="action_solid_seq7"/>

</data>

错误日志:

 OpenERP Server Error
Client Traceback (most recent call last):
File "C:\Program Files\OpenERP 7.0-20131006-    231029\Server\server\openerp\addons\web\http.py", line 204, in dispatch
File "C:\Program Files\OpenERP 7.0-20131006- 231029\Server\server\openerp\addons\web\controllers\main.py", line 1132, in call_button
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\openerp\addons\web\controllers\main.py", line 1120, in _call_kw
   File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\openerp\addons\web\session.py", line 42, in proxy
   File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\openerp\addons\web\session.py", line 30, in proxy_method
   File "C:\Program Files\OpenERP 7.0-20131006-  231029\Server\server\openerp\addons\web\session.py", line 103, in send


   Server Traceback (most recent call last):
   File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\openerp\addons\web\session.py", line 89, in send
   File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\netsvc.py", line 292, in dispatch_rpc
   File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\service\web_services.py", line 622, in dispatch
   File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\service\security.py", line 40, in check
   File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\pooler.py", line 49, in get_pool
   File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\pooler.py", line 33, in get_db_and_pool
   File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\modules\registry.py", line 192, in get
  File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\modules\registry.py", line 218, in new
  File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\modules\loading.py", line 350, in load_modules
  File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\modules\loading.py", line 256, in load_marked_modules
  File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\modules\loading.py", line 187, in load_module_graph
  File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\modules\loading.py", line 74, in <lambda>
  File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\modules\loading.py", line 124, in _load_data
  File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\tools\convert.py", line 954, in convert_xml_import
  File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\tools\convert.py", line 847, in parse
  File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\tools\convert.py", line 814, in _tag_record
File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\openerp\addons\base\ir\ir_model.py", line 937, in _update
  File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\openerp\addons\base\ir\ir_ui_view.py", line 214, in write
  File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\osv\orm.py", line 4205, in write
  File "C:\Program Files\OpenERP 7.0-20131006-231029\Server\server\.\openerp\osv\orm.py",  line 1548, in _validate
  except_orm: ('ValidateError', u'Error occurred while validating the field(s) arch:  Invalid XML for View Architecture!')

1 个答案:

答案 0 :(得分:0)

选择字段有一个静态列表。在您的情况下,您应该在视图中使用带有widget ='selection'的many2one字段,以便您可以将一个字段的值传递给其他字段以进行过滤 例如,创建用于选择和类型的表。对于这些表,名称字段就足够了。在选择表中,为类型表添加一个many2one关系(比如type_id),这是一个必填字段。然后在new.base表中将这些字段添加为多个2字段(比如type_id和choice_id),并在字段<field name="type_id" widget='selection'/><field name="choice_id" domain="[('type_id','=',type_id)]" widget='selection'/>的视图中添加