Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
6593 Lượt xem

Hi,

i have this code

class sprzedaz(osv.osv):



    _name="sprzedaz"
    _defaults = {
                'data': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S') 
                }


    _columns= {
            'produkt_id': fields.many2one('produkt.rodzaj', 'Produkt', required=True),
            'ilosc': fields.integer('Ilość', size=12, required=True),
            'miejsce_id': fields.many2one('miejsce', 'Miejsce', required=True),
            'data': fields.datetime('Data', required=True),
            #'razem': fields.char('Razem', required=True),
           # 'razem': fields.function(suma, 'Razem', type="float"),
            #zrobic funkcje wyliczajaca sume zakupu
               }

    def suma(self, cr, uid, ids,args,name, context=None):

        razem = 0
        return razem


sprzedaz()

class sprzedaz_inh(osv.osv):

    _name = "sprzedaz.inh"
    _inherit="sprzedaz"

    def suma(self, cr, uid, ids,args,name, context=None):
        razem=super(sprzedaz,self).suma(cr,uid,ids,args,name,context)
        print ids
        for id in ids:
            r= self.browse(cr,uid,id)
            c= self.pool.get('sprzedaz').browse(cr,uid,id).produkt_id.cena
            print c.cena
            pom = r.ilosc * c
            razem+=pom
        return razem
    _columns= {
            #'razem': fields.char('Razem', required=True),
            'razem': fields.function(suma, 'Razem', type="float"),
            #zrobic funkcje wyliczajaca sume zakupu
               }



sprzedaz()

and xml

<record model="ir.actions.act_window" id="action_sprzedaz_form">
    <field name="res_model">sprzedaz</field>
</record>

<record model="ir.ui.view" id="sprzedaz_form">
<field name="name">sprzedaz</field>
<field name="model">sprzedaz</field>
<field name="type">tree</field>
<field name="arch" type="xml">
    <tree string="Sprzedaz">
        <field name="produkt_id"/>
        <field name="ilosc"/>
        <field name="miejsce_id"/>
        <field name="data"/>
        <field name="razem"/>

        </tree>
    </field>
</record>

<menuitem name="Sprzedaz" id="menu_action_sprzedaz_form" 
action="action_sprzedaz_form" 
parent="menu_action_oktoberfest"/>

How can i display field razem form class sprzedaz_inh?

I have this error:

View error

Can't find field 'razem' in the following view parts composing the view of object model 'sprzedaz':
 * sprzedaz

Either you wrongly customized this view, or some modules bringing those views are not compatible with your current data model

Anyone can help me?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Actually I don't understand why are you creating two classes when you only need one. Anyways it's because you are giving sprzedaz_inh a name. So you have to delete that name if you want to extend the other class. just leave the inherit.

That's because if you are giving a _name to the inherited class then you are creating another class with the same attributes, but it's another class.

Also the last line must be: sprzedaz_inh()

I hope this can help you.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 10 24
1190
2
thg 11 17
6800
0
thg 3 25
869
1
thg 8 23
1533
1
thg 12 21
7722