问题
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.
Code
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
回答1:
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()
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.
For future records, you can just inherit product.template
models create()
method and create a corresponding quotation.creation
record in it.
来源:https://stackoverflow.com/questions/54703551/odoo-how-to-create-a-new-model-for-product-master-with-all-the-data-in-the-produ