콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
18 답글
19899 화면

When I run this query on Postgresql :

SELECT code, total FROM hr_payslip_line WHERE slip_id=1

I get :

____________________________
|  code    |    total      |
__________________________
|  BASE    |    57000.00   |
____________________________

And when I run this code :

    sql = '''
        SELECT code, total FROM hr_payslip_line WHERE slip_id=%s
    ''' % (slip.id)
    cr.execute(sql)
    for code, total in cr.fetchall() :                
        raise osv.except_osv(_('Info'),_('code : %s\nTotal :  %s\nSlip ID : %s\nSQL : %s ' % (code, total,slip.id,sql)))

I've used the raise to catch the error I get this dialog :

    Info

code : BASE
Total : None
Slip ID : 1
SQL : SELECT code, total FROM hr_payslip_line WHERE slip_id=1

The problem is that the total return None and not 57000.00 More informations : 1. I've one slip 2. I've one line 3. the field total is a stored function

아바타
취소

Can you add slip.id to your debug message and post the result?

작성자

The debug is updated, I have used also res = cr.fetchall() and setting res[0] get 'BASE' and res[1] get False

베스트 답변

that's because your code is wrong :-) you should have used

for row in cr.fetchall() :                
        raise osv.except_osv(_('Info'),_('code : %s\nTotal :  %s ' % (row[0], row[1])))

you can also use

    for row in cr.dictfetchall() :                
            raise osv.except_osv(_('Info'),_('code : %s\nTotal :  %s ' % (row['code'], row['total'])))

or you can (could?) also use the browse record instead of using an SQL query that ignore the orm (and the access rights checking for example): try with the following:

for line in slip.line_ids:
    raise osv.except_osv(_('Info'),_('code : %s\nTotal :  %s ' % (line.code, line.total)))

if, even with that you cannot get a value for line.total, it means that the total line is not yet computed. To force the computation, just manually call _calculate_total().

아바타
취소
작성자

I replaced the code by the last one I get the same thing code='BASE' and Total=None,

na... you should have done something wrong. Print the row before the raise please

작성자

for row in cr.fetchall() : raise osv.except_osv(_('Info'),_('Row : %s' % (row,))) I get : Info

Row : (u'BASE', None) I guess that the problem is the type of total in the orm because it's a field calcultaed but it's stored !!

i don't get the reason, this kind of code is widely used in OpenERP and without any problem... but you can still use the browse record to access the total -_- I updated my answer with a code avoiding the SQL query...

작성자

It's my first thing that I have done, using browse get the same thing, when i print line.total I get None so I switch to SQL as solution but not work, it's a very complicate case, but if i find the problem I will publish it, I'm already advanced In OpenObject, and it's first time that I face som

작성자

calling the function _calculate_total() has resolved the problem.

베스트 답변

Your code is correct, there are two possibilities:

  • You changed the value of total before or after the code you shown. As you used raise, the transactions are rollbacked and, when you perform your manual query in SQL, you do not see the changed value. Do a cr.commit() just before raise, you may get NULL in your manual SQL query after calling the python code.
  • Both tests are not on the same database.
아바타
취소
작성자

Of course the moment when the query is executed the value of total is False, there is an interference, but how can I get the same thing as the sql request, I use just one database, and I puted cr.commit() before the sql execution, and always same thing, I can share with you all the file

베스트 답변

For me works this way:

  1. sql = "..."

  2. result = self.env.cr.execute(sql)

  3. value = ''

  4. for res in self.env.cr.dictfetchall():

  5.        if (value != ''):

  6.             value += ','

  7.         value += res['number']


  8. record.invoices = value

Hope it helps

아바타
취소
베스트 답변

cr.execute('''SELECT code, total FROM hr_payslip_line WHERE slip_id=%s''' % (slip.id)) x = cr.fetchone() #Only if it returns one (1) row

raise osv.except_osv('Info', 'code : %s\nTotal : %s' % (x[0], x[1]))

#or to return just one row SELECT code, SUM(total) FROM hr_payslip_line WHERE slip_id=1 GROUP BY code

아바타
취소
작성자 베스트 답변

I guess that the problem is an interference between the function compute_sheet in the hr_payroll module and my function

I have a stored fucntion field that get total from what shown above, but I put store=False it works well, for me it's not logic and I declared this as a bug,

There is somthing that not good in this module, as a advanced developper I get always values of stored function in the database using SQL and anawhere, this time it's different for me, If I Try to use cr.commit(), there isn't any changes, if I use cr.rollback() I get an other message that say that a field quantity from the object hr_payslip_line doesn't exist, for my module there is not any treatement of field quantity

So if you have a logic to resolve this problem, I'm gratfull for you

To recap : I want to compute a stored function field, I execute the code above and it don't work

아바타
취소

just manually call _calculate_total()

작성자

Ohh Quentin you're found a path , Thank you now I see 57000.00, I have to set this resolved

ok let me add this in my answer, then you can check my answer as correct ^^

관련 게시물 답글 화면 활동
4
11월 16
2932
1
3월 15
3517
2
3월 15
5268
3
5월 21
7171
0
3월 15
3147