主细节关系,变量& OpenERP 7中的XML

时间:2014-02-06 10:55:56

标签: python xml openerp openerp-7

我正在尝试在OpenERP 7中创建一个产品规范模块。已经完成了一些工作。但与Master-detail关系混淆,Variables& XML。

看一下这张照片

enter image description here

需要从此.py&创建此下半部分.xml文件。

product_pspec.py

from openerp.osv import osv, fields

class product_pspec(osv.osv):

  _name = "product.pspec"

  _columns = {
    'prototype': fields.char('Prototype#', size=20),
    'style': fields.char('Style#', size=20),
    'customer': fields.char('Customer', size=20),
    'body_type': fields.char('Body Type', size=20),
    'program_brand': fields.char('Program/Brand', size=20),
    'color_asstmnt': fields.char('Color Asstmnt', size=200),
    'size_info': fields.integer('Size Info', size=20),
    'description': fields.char('Description', size=500),
    'designer': fields.char('Designer', size=20),
    'factory': fields.char('factory', size=20),
    'pcs_hanger': fields.integer('Pcs/Hanger', size=20),
    'developed_sold': fields.char('Developed/Sold', size=20),

  }


class product_pspec_details(osv.osv):

  _name = "product.pspec.details"

  _columns = {
       'product_pspec_id' : fields.many2one('product.pspec', 'Product Pspec', required=True),
       'product_product_id' : fields.many2one('product.product', 'Product Product', required=True),
       'supplier_name': fields.char('Supplier Name', size=20),
       'style_number': fields.char('Style Number', size=20),
       'where_used': fields.char('Where Used', size=20),
       'est_yield': fields.char('Est. Yield', size=20),
       'price': fields.char('Price', size=20),
       'cost_dz': fields.char('Cost Dz', size=20),
  }
  _sql_constraints = [
        ('uniq_name', 'unique(product_product_id, supplier_name, where_used)', "Already Added"),
  ]

product_pspec()
product_pspec_details()

product_pspec.py.xml

    <?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="product_pspec_product">
<field name="name">product.pspec</field>
<field name="model">product.pspec</field>
<field name="arch" type="xml">
  <form string="Create product Specification" version="7.0">
    <group>
    <field name="prototype"/>
    <field name="style"/>
    <field name="customer"/>
    <field name="body_type"/>
    <field name="program_brand"/>
    <field name="color_asstmnt"/>
    <field name="size_info"/>
    <field name="description"/>
    <field name="designer"/>
    <field name="factory"/>
    <field name="pcs_hanger"/>
    <field name="developed_sold"/>
    <field colspan="4" name="product_pspec_id" widget="many2one_list">
        <tree string="Materials" editable="bottom">
     <field name="product_product_id"/>
     <field name="Supplier Name"/>
     <field name="Style number"/>
     <field name="Where Used"/>
        </tree>
    </field>
    </group>
   </form>
</field>
</record>
<record id="product_specification_product_act_window" model="ir.actions.act_window">
        <field name="name">Product Specification</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">product.pspec</field>
        <field name="view_type">form</field>
        <field name="view_id" ref="product_pspec_product"/>
</record>
 <menuitem
        name="Product Specification"
        id="menu_product_specification"
        parent="base.menu_mrp_root"
        sequence="16"
        />


 <menuitem
        name="Product Pspec"
        id="menu_product_pspec"
        parent="menu_product_specification"
     action="product_specification_product_act_window"
        />


</data>
</openerp>

如何创建下部/标记部分。

**组件部分是我需要仅创建的示例。上部&amp;菜单部分已经完成。

1 个答案:

答案 0 :(得分:1)

<强>编辑:

据我所知,您希望在pspec和pspec.details之间创建一个one2many关系。在你的细节方面似乎都很好,但在你的pspec方面,你需要额外的one2many字段作为你的详细信息:

from openerp.osv import orm, fields

class product_pspec(orm.Model):

  _name = "product.pspec"

  _columns = {
    'prototype': fields.char('Prototype#', size=20),
    'style': fields.char('Style#', size=20),
    'customer': fields.char('Customer', size=20),
    'body_type': fields.char('Body Type', size=20),
    'program_brand': fields.char('Program/Brand', size=20),
    'color_asstmnt': fields.char('Color Asstmnt', size=200),
    'size_info': fields.integer('Size Info', size=20),
    'description': fields.char('Description', size=500),
    'designer': fields.char('Designer', size=20),
    'factory': fields.char('factory', size=20),
    'pcs_hanger': fields.integer('Pcs/Hanger', size=20),
    'developed_sold': fields.char('Developed/Sold', size=20),
    'details_ids':fields.one2many("product.pspec.details","product_pspec_id", string="Details") #new field

  }


class product_pspec_details(osv.osv):

  _name = "product.pspec.details"

  _columns = {
       'product_pspec_id' : fields.many2one('product.pspec', 'Product Pspec', required=True),
       'product_product_id' : fields.many2one('product.product', 'Product Product', required=True),
       'supplier_name': fields.char('Supplier Name', size=20),
       'style_number': fields.char('Style Number', size=20),
       'where_used': fields.char('Where Used', size=20),
       'est_yield': fields.char('Est. Yield', size=20),
       'price': fields.char('Price', size=20),
       'cost_dz': fields.char('Cost Dz', size=20),
  }
  _sql_constraints = [
        ('uniq_name', 'unique(product_product_id, supplier_name, where_used)', "Already Added"),
  ]

然后你必须在视图中使用这个新字段(xml):

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="product_pspec_product">
<field name="name">product.pspec</field>
<field name="model">product.pspec</field>
<field name="arch" type="xml">
  <form string="Create product Specification" version="7.0">
    <group>
    <field name="prototype"/>
    <field name="style"/>
    <field name="customer"/>
    <field name="body_type"/>
    <field name="program_brand"/>
    <field name="color_asstmnt"/>
    <field name="size_info"/>
    <field name="description"/>
    <field name="designer"/>
    <field name="factory"/>
    <field name="pcs_hanger"/>
    <field name="developed_sold"/>
    <field colspan="4" name="details_ids">
        <tree string="Materials" editable="bottom">
             <field name="product_product_id"/>
             <field name="supplier_name"/>
             <field name="style_number"/>
             <field name="where_used"/>
        </tree>
    </field>
    </group>
   </form>
</field>
</record>