Мастер Odoo записывает в модель, но получение значений из моделей не заполняет поля мастера

У меня есть мастер ниже, который записывает в базу данных, но не читает значения, записанные в базу данных и отображаемые в представлении. Я использую get_opinion для чтения мнений и get_notes для чтения заметок, но когда я нажимаю на кнопки, они просто исчезают без ошибок, где я ошибаюсь?

Q2, в этом коде, который является частью кода ниже, почему я не получаю имя_модели?

if context is None: context = {}
model_name=context.get('active_model')
print  model_name #gives  NONE  why  ?

Q3 Как я могу перечислить все поля в контексте?

Код модуля, как показано ниже

class opinion(models.TransientModel):
_name='opinion'
opinion_emission   = fields.Text(string='OPINION EMISSION')
notes = fields.Text(string='Additional Notes')


defaults={
    'opinion_emission': lambda self : self.get_opinion(self),
    'notes': lambda self : self.get_notes(self),

}
def  save_it(self, cr, uid,ids , context=None):
    # context = dict(self._context or  {} )
    if context is None: context = {}

    active_id  = context.get('active_id',False)
    print  'active_id' , active_id
    if  active_id :
        # op = self.env['opinion'].browse(active_id)
        info =  self.browse(cr,uid,ids)
        self.pool.get('opinion').write(cr,uid,context['active_id'],{'opinion_emission': info[0].opinion_emission,'notes': info[0].notes})
    return {
        'type': 'ir.actions.act_window_close',
     }


#functions that get the info stored in db
@api.one
def get_opinion(self):
    ids=self._ids
    cr = self._cr
    uid = self._uid
    context = self._context
    if context is None: context = {}
    active_id  = context.get('active_id',False)
    print  'active_id' , active_id
    if  active_id :

        return self.env['opinion'].browse(cr, uid, context['active_id'], context).opinion_emission


@api.one
def get_notes(self,records=None):
    ids=self._ids
    cr = self._cr
    uid = self._uid
    context = self._context
    if context is None: context = {}
    model_name=context.get('active_model')
    print  model_name #gives  NONE  why  ?
    active_id  = context.get('active_id',False)
    print  'active_id' , active_id
    if  active_id :
        print  'output',self.env['opinion'].browse(cr, uid, context['active_id'], context)[0].notes
        return self.env['opinion'].browse(cr, uid, context['active_id'], context)[0].notes

Код просмотра xml:

<openerp>
<data>
     <record id="view_opinion_wizard" model="ir.ui.view">
        <field name="name">opinion_wizard.form</field>
        <field name="model">opinion</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
        <!-- create a normal form view, with the fields you've created on your python file -->
            <form string="OPINION" version="8.0">
                                        <button  icon="gtk-ok" name="get_notes" string='SET VAL' type="object" />

                <group >
                    <separator string="Please insert OPINION" colspan="2"/>
                    <field name="opinion_emission" string="OPINION  EMISSION "/>
                                            <field name="notes" string="NOTES"/>

                    <newline/>
                </group>
                <div style="text-align:right">
                    <button  icon="gtk-cancel" special="cancel" string="Cancel"/>
                                            <button  icon="gtk-ok" name="save_it" string="SAVE  INFO" type="object" />
                                            <button  icon="gtk-ok" name="get_notes" string="GET NOTES" type="object" />

                    <button  icon="gtk-ok" name="get_opinion" string="GET  OPINION" type="object" />

                </div>

           </form>
        </field>
    </record>
    <!-- your action window refers to the view_id you've just created -->
    <record id="action_opinion" model="ir.actions.act_window">
        <field name="name">OPINION</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">opinion</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="view_opinion_wizard"/>
        <field name="target">new</field>
     </record>
            <menuitem  name="OPINION" id="menu_opinion"  action="action_opinion"  parent="timeorder_ratecard_rnd_menu"/>

</data>


person danielmwai    schedule 02.12.2015    source источник


Ответы (1)


Это новый код API, попробуйте этот код:

class opinion(models.TransientModel):
    _name = 'opinion'
    opinion_emission = fields.Text(default=lambda self: self.get_opinion(self), string='OPINION EMISSION')
    notes = fields.Text(default=lambda self: self.get_notes(self), string='Additional Notes')

    @api.multi
    def save_it(self):
        active_id = self.env.context.get('active_id', False)
        print 'active_id', active_id
        if active_id:
            op = self.env['opinion'].browse(active_id)
            op.write({'opinion_emission': self.opinion_emission, 'notes': self.notes})
        return {'type': 'ir.actions.act_window_close', }
    #functions that get the info stored in db

    @api.one
    def get_opinion(self):
        active_id = self.env.context.get('active_id', False)
        print 'active_id', active_id
        if active_id:
            return self.env['opinion'].browse(active_id).opinion_emission

    @api.one
    def get_notes(self, records=None):
        model_name = self.env.context.get('active_model')
        print model_name     # gives  NONE  why  ?
        active_id = self.env.context.get('active_id', False)
        print 'active_id', active_id
        if active_id:
            print 'output', self.env['opinion'].browse(active_id).notes
            return self.env['opinion'].browse(active_id).notes
person Jainik Patel    schedule 03.12.2015