【发布时间】:2015-02-01 18:46:40
【问题描述】:
我尝试在 odoo 中仅显示来自另一个模板的 3 个字段。
我的 pb 是我继承 products_group.py 的所有字段
我只需要那个。 -customers_group_id - price_group_view - products_model_group
我尝试了一些解决方案,但我的 pb 始终相同;
我这样做:
from openerp.osv import fields, osv, orm
from openerp.tools.translate import _
customers_group_id
class product_template(osv.osv):
_inherit = "product.template"
_description = "Product Template"
_columns = {
......
'products_group_id_products': fields.one2many('products.group','customers_group_id', 'Products Group'),
}
class products_group(orm.Model):
_inherit = 'products.group'
# in comment, the result is the same
# _columns = {
# 'customers_group_id': fields.integer('Customer group Id', size=20, help='id of customers group'),
# 'products_model_group': fields.char('Product model group', size=30, help='Model'),
# 'price_group_view': fields.boolean('Price group view', default='1', help='Display Price Group View'),
# 'products_group_view': fields.boolean('Product Group View', default='1', help='Display Group View'),
# 'orders_group_view': fields.boolean('Display Order process', default='1', help='Display order Group View'),
# }
#_order = 'sequence'
我的 products_group.py
from openerp.osv import orm, fields
from openerp.tools.translate import _
class products_group(orm.Model):
_name = 'products.group'
_columns = {
'customers_group_id': fields.integer('Customer group Id', size=20, help='id of customers group'),
'customers_group_price': fields.float('Customers group Price', size=70, help='Price of the product group'),
'products_id': fields.integer('Product Id', size=5, help="Id product must be unique"),
'products_price': fields.float('Products_price',size=70, help='price of the product'),
'price_group_view': fields.boolean('Price group view', default='1', help='Display Price Group View'),
'products_group_view': fields.boolean('Product Group View', default='1', help='Display Group View'),
'orders_group_view': fields.boolean('Display Order process', default='1', help='Display order Group View'),
'products_model_group': fields.char('Product model group', size=30, help='Product model'),
'products_quantity_unit_id_group': fields.integer('product Quantity Unit group', help='Default quantity for this group'),
'products_quantity_fixed_group': fields.integer('product quanty Fixed', help='Default quantity for this group'),
}
我的 xml
<?xml version="1.0" encoding="utf-8" ?>
<openerp>
<data>
<record model="ir.ui.view" id="template_product_form_view">
<field name="name">product.template_product_test</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/> <!-- external_id -->
<field name="priority" eval="16"/>
<field name="arch" type="xml">
<notebook position="inside">
<page string="My product">
<group col="4" colspan="4" string="General">
....
</group>
<separator string="Groups Price B2B"/>
// My page display all my fields ofproducts.group and not the 3
<field name="products_group_id_products" />
</page>
</notebook>
</field>
</record>
</data>
</openerp>
我的产品组的结果
customer group id products id products model group
1 1 model1
2 1 model2
1 3 model3
2 3 model4
我的产品 id = 1 的产品模板上的结果,我必须在树视图中显示
customer group id products id products model group
1 1 model1
2 1 model2
例如,客户组 ID 与另一个表相关(但它是供以后使用的)
1 = 经销商
2 = 小经销商
解决办法
from openerp.osv import fields, osv, orm
from openerp.tools.translate import _
customers_group_id
class product_template(osv.osv):
_inherit = "product.template"
_description = "Product Template"
_columns = {
......
'products_group_id_products': fields.one2many('products.group', 'products_id', 'Products Group'),
}
class products_group(orm.Model):
_inherit = 'products.group'
_columns = {
'sequence' : fields.integer('Sequence', help="Assigns the priority to the list of product groups."),
'customers_group_id': fields.many2one('customers.group', 'Customer group Id', help='id of customers group'),
'products_model_group': fields.char('Product model group', size=30, help='Model'),
'products_id': fields.integer('Product Id', size=5, help="Id product must be unique"),
.....
}
_order = 'sequence'
_defaults = {
'sequence': 1,
}
【问题讨论】:
标签: python templates inheritance tree openerp