콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
6950 화면

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.

아바타
취소
작성자 베스트 답변

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)
아바타
취소
베스트 답변

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

아바타
취소
베스트 답변
아바타
취소
관련 게시물 답글 화면 활동
3
5월 21
3278
0
5월 24
1730
0
10월 24
1263
2
9월 21
22565
0
12월 15
6380