Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

dynamically add new fields to a osv model depending on the number of records of another osv model in openerp?

By
Omal Bastin
on 10/29/13, 10:59 AM 1,754 views

How to dynamically add new fields to a osv model depending on the number of records of another osv model in openerp? For example I have a model which is for planning purchases. I need to show total order qty that came in each shop.so i need to add new field each time a new record in sale.shop is created.

0

Omal Bastin

--Omal Bastin--
1146
| 6 6 8
Kochi, Kerala, India
--Omal Bastin--

Swiming deep into openERP/ODOO

Omal Bastin
On 12/9/13, 9:13 AM

Use __init__ function of your class to dynamically add the sales shop to _columns.

class planning(osv.osv):
    def __init__(self, pool, cr):
        shop_ids = pool.get('sale.shop').search(cr,SUPERUSER_ID,[])
        for shop in pool.get('sale.shop').browse(cr, SUPERUSER_ID,shop_ids):
            self._columns['shop_qty_%s'%shop.id] = fields.float(
                                                                '%s Order Qty'%shop.name)
        return super(planning,self).__init__(pool, cr)
1
Torsten Francke
On 10/29/13, 11:21 AM

This is impossible with the current osv model. And it is bad software design.

Better, add a new model: purchase_shop_quantity and make a one2many relation from your current model to the new one

0

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 10/29/13, 10:59 AM
Seen: 1754 times
Last updated: 3/16/15, 8:10 AM