【问题标题】:Choose fields when try to inherit template in Odoo尝试在 Odoo 中继承模板时选择字段
【发布时间】: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


    【解决方案1】:

    product_templateproducts_group 设置了错误的关系。根据one2many我们需要设置many2one的那个类

    更新:

    products_group 类中尝试这些更改:

    'products_id': fields.many2one('product.template', 'Product Id', help="Id product must be unique"),
    

    编辑:

    对于xml端:

    <separator string="Groups Price B2B"/>
    <field name="products_group_id_products">
        <!-- place here field that how many you want like -->
        <field name="customers_group_id"/>
        <field name="price_group_view"/>
        <field name="products_model_group"/>
    </field>
    

    【讨论】:

    • 谢谢,是的,工作,但这不完全是我想要的,我尝试在产品中做与供应商相同的事情。在 products_group 类中,我需要获取一些字段,并在我的产品页面上具有与 product 和 products_group 相同 id 的函数。
    • 尝试更新答案。现在您将在产品中仅获得三个字段
    • 你好,看上面的表格,我想你比我尝试做的更明白。
    • 感谢您的帮助,现在我找到了一个解决方案,但并不完美,因为它写入了所有字段,但它可以工作。你可以在上面看到。
    • 好的,我也在根据你的代码更新我的答案,现在它可以工作了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    相关资源
    最近更新 更多