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

How display field form inherit class

By
panmarcin
on 7/26/13, 10:35 AM 2,607 views

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?

0

Grover Menacho

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 7/26/13, 10:58 AM

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.

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

0 follower(s)

Stats

Asked: 7/26/13, 10:35 AM
Seen: 2607 times
Last updated: 3/16/15, 8:10 AM