Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.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 如何在odoo中在另一个模型中创建记录的同时在模型中创建记录_Python_Odoo 8 - Fatal编程技术网

Python 如何在odoo中在另一个模型中创建记录的同时在模型中创建记录

Python 如何在odoo中在另一个模型中创建记录的同时在模型中创建记录,python,odoo-8,Python,Odoo 8,在我的自定义应用程序中,我想在创建销售订单时在自定义模型中自动创建一条记录 class custom_sale_order(models.Model): _inherit='sale.order' time1 = fields.Date('TIme1') time2 = fields.Date('TIme2') class demo(models.Model): name = 'demo'

在我的自定义应用程序中,我想在创建销售订单时在自定义模型中自动创建一条记录

    class custom_sale_order(models.Model):
        _inherit='sale.order'

        time1 = fields.Date('TIme1')
        time2 = fields.Date('TIme2')

    class demo(models.Model):   
        name = 'demo'

        time3 = fields.Date('TIme1')
        time4 = fields.Date('TIme2')

在创建销售订单时,我想在演示模型中创建一个记录,还应该从sale.order中获取时间字段并保存在演示模型中。我该怎么做?

您需要覆盖
sale.order
类的
create
方法,在该方法中,您可以在演示模型中创建一条记录,并访问当前模型的

例如:

class custom_sale_order(models.Model):
    _inherit='sale.order'

    time1 = fields.Date('TIme1')
    time2 = fields.Date('TIme2')

    @api.model
    def create(self, values):
        # here we call to the parent create method
        res = super(custom_sale_order, self).create(values)

        # here we create a record in the demo model
        # and we can access to the values of the current model
        self.env['demo'].create({
            'time3': values['time1'],
            'time4': values['time2']
        })

        return res