Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
4 Ответы
7386 Представления

hello i want to create report which will give in a table infomation of the record selected via tre view

so i have done my model and know when i want to call my function get_all_records  there are errors like 'self has not attribute context' or 'not attribute env' how to do please??

import time from openerp import api, fields, models

from datetime import datetime, timedelta, date

from openerp.osv import osv, orm from openerp import tools

from openerp.report import report_sxw

class example_report_parser(report_sxw.rml_parse):
    _name = 'report.reportbesoin.report_besoin_report_view'
    def __init__(self, cr, uid, name, context):
        super(example_report_parser, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
                                 
                                 'test_me':self.test_me,
                                 'get_all_records':self._get_all_records,
                               
                                 })

    def test_me(self):
        return "ABC"
       
    @api.model
    def _get_all_records(self):

       recsss = self.env['hr.job'].search(self.cr,self.uid, [('id','in',self.ids)])
        resss = self.env['hr.job'].browse(self.cr, self.uid, recsss)
        return resss


class report_test1_parser(models.AbstractModel):
    _name = 'report.reportbesoin.report_besoin_report_view'
    _inherit = 'report.abstract_report'
    _template ='reportbesoin.report_besoin_report_view'
    _wrapped_report_class = example_report_parser

Аватар
Отменить
Лучший ответ

avasen,

Use self.pool.get instead of self.env

Thank You

Аватар
Отменить
Лучший ответ

Hello,

try below code,

active_ids =  self._context.get('active_ids',False)

maybe it will help you.

Thanks

Аватар
Отменить
Автор Лучший ответ

hello ,thanks for your answer but when i do that i have just the last record so instead i have done


def _get_all_records(self):
       
        active_ids =  self.context.get('active_ids',False)
        recsss = self.pool.get('hr.job').search(self.cr,self.uid, [('id','in',active_ids)], context=self._context)
        resss = self.pool.get('hr.job').browse(self.cr, self.uid, recsss)
        return resss


but they say that my module has not attribute context

can you help please

Аватар
Отменить
Лучший ответ

Hai Brami,

  @api.model
    def _get_all_records(self):

       recsss = self.pool.get('hr.job').search(self.cr,self.uid, [('id','in',self.ids)])
        resss = self.pool.get('hr.job').browse(self.cr, self.uid, recsss)
        return resss

In this report parser you just use the pool.get method, then its work fine, 

Аватар
Отменить
Related Posts Ответы Просмотры Активность
0
мая 21
4
1
нояб. 20
4209
0
мар. 15
3564
1
дек. 24
3527
0
нояб. 24
1460