Odoo如何使用产品主数据中的所有数据为产品主数据创建新模型 [英] Odoo How to create a new model for Product Master with all the data in the product master
问题描述
我想为Product Master创建一个单独的视图.我创建了一个新模型并进行了这样的尝试.但是,当我签入database
时,新模型中没有数据.
I want to create a separate view for Product Master.I created a new model and tried like this.But when I checked in database
no data is present in my new model.
代码
class QuotationCreation(models.Model):
_name='quotation.creation'
xn_product_id = fields.Many2one('product.template')
product=fields.Char(related = 'xn_product_id.name',string='Product')
如何将所有数据从产品主数据转移到此模型. 我想用现有数据创建一个新模型,该怎么做? 在此先感谢
How can I tranfer all the data from product master to this model. I want to create a new model with existing data.How can I do that ? Thanks in Advance
推荐答案
要使用现有的product.template
表记录填充新模型,必须在odoo shell
中运行for循环,因为这是现有数据您不能在create
方法上触发任何事件.例如:
For populating your new model with your existing product.template
table records, you have to run a for loop in your odoo shell
, because this are existing data that you cannot fire any event on create
method. For example:
ProductTemplates = env['product.template'].search([])
for pt in ProductTemplates:
env['quotation.creation'].create({'xn_product_id': pt.id})
env.cr.commit()
或者,您甚至可以从产品模板列表视图中导出所有数据库ID,然后将其导入到quotation.creation
列表视图中,而没有其他字段将在新表中创建所有记录.
OR you can even export all database id from product template list view and import that on quotation.creation
list view with no other field which will create all the records in your new table.
对于将来的记录,您可以仅继承product.template
模型create()
方法并在其中创建相应的quotation.creation
记录.
For future records, you can just inherit product.template
models create()
method and create a corresponding quotation.creation
record in it.
这篇关于Odoo如何使用产品主数据中的所有数据为产品主数据创建新模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!