我尝试在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,
}
答案 0 :(得分:0)
表product_template
和products_group
设置错误关系。根据{{1}},我们需要设置one2many
更新:
尝试在课程many2one
中进行这些更改:
products_group
编辑:
for xml side:
'products_id': fields.many2one('product.template', 'Product Id', help="Id product must be unique"),