Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python OpenERP-为什么在记录创建过程中调用create()方法两次?_Python_Openerp_Odoo - Fatal编程技术网

Python OpenERP-为什么在记录创建过程中调用create()方法两次?

Python OpenERP-为什么在记录创建过程中调用create()方法两次?,python,openerp,odoo,Python,Openerp,Odoo,我已在我的product_product和product_template类中重写了create方法。当我对model product.product使用view并尝试通过按Save创建新记录new product时,两种创建方法都会被调用:首先在product\u product中,然后在product\u模板中。由于VAL值不同,这会导致问题。我希望只调用product_product create。以下是代码片段: class product_product(osv.Model):

我已在我的product_product和product_template类中重写了create方法。当我对model product.product使用view并尝试通过按Save创建新记录new product时,两种创建方法都会被调用:首先在product\u product中,然后在product\u模板中。由于VAL值不同,这会导致问题。我希望只调用product_product create。以下是代码片段:

class product_product(osv.Model):
    _inherit = 'product.product'

    def create(self, cr, uid, vals, context=None):
    # ... validation code
    return super(product_product, self).create(cr, uid, vals, context=context)

class product_template(osv.Model):
    _inherit = 'product.template'

    def create(self, cr, uid, vals, context=None):
    # ... validation code
    return super(product_template, self).create(cr, uid, vals, context=context) 

每个产品都有一个必填字段,将其链接到模板产品\u tmpl\u id,因此,如果您没有为其提供现有模板,则必须创建一个新模板Ludwik Trammer 12月10日10:56

每个产品都有一个必填字段,将其链接到模板产品\u tmpl\u id,因此如果您没有为其提供现有模板,则必须创建一个新模板。感谢Ludwik的评论。您能解决您的问题吗?