Odoo How to create a new model for Product Master with all the data in the product master

徘徊边缘 提交于 2020-01-06 06:01:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!