Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
6581 Vizualizări

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?

Imagine profil
Abandonează
Cel mai bun răspuns

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.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
3
oct. 24
1185
2
nov. 17
6786
0
mar. 25
868
1
aug. 23
1531
1
dec. 21
7713