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

Hi,

We are considering using Odoo for reporting purposes, and I'm doing some proof of concept tests right now. Basically, we need to create some journal entries by using the external API and Python. The ultimate goal is to integrate this with our Python based application. I'm using Odoo v11.

I've figured out how to create the journal entry and also journal items - however as soon as I enter a credit or debit balance when creating the item I receive the following error:-

Fault: <Fault 2: 'Cannot create unbalanced journal entry.'>

My very basic code is below. If I run this as-is, it creates the journal entry. However, as soon as I uncomment the credit or debit balances, I receive the error above.

I guess I need a way to create the three lines simultaneously, or alternatively temporarily disable the control preventing the unbalanced entry. (The journal entry will balance after the final entry)

# Create journal entry

je_id = models.execute_kw(db, uid, password, 'account.move', 'create',

[{'name': "Python Journal Entry 2", 'date' : '06-Mar-2018', 'journal_id': '3'}])

# Create three lines - debit AR, Credit sales & tax

l1 = models.execute_kw(db, uid, password, 'account.move.line', 'create',

[{

'move_id': je_id,

'account_id': 7, #Receivables

# 'debit' : 120.00

}])

l2 = models.execute_kw(db, uid, password, 'account.move.line', 'create',

[{'move_id': je_id,

'account_id': 17, #Revenue

# 'credit' : 100.00

}])

l3 = models.execute_kw(db, uid, password, 'account.move.line', 'create',

[{'move_id': je_id,

'account_id': 14, #Tax

# 'credit' : 20.00

}])


Appreciate any advice that can be given.

George

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

I figured it out!

I need to use {'context' :{'check_move_validity': False}} to allow a journal entry to be temporarily unbalanced. I use 'True' for the final entry to ensure it does eventually balance.

Here's the working code.


# Create journal entry

je_id = models.execute_kw(db, uid, password, 'account.move', 'create',

[{'name': "Python Journal Entry 4", 'date' : '06-Mar-2018', 'journal_id': '3'}])

# Create three lines - debit AR, Credit sales & tax. Credits & debits must total zero.

l1 = models.execute_kw(db, uid, password, 'account.move.line', 'create',

[{

'move_id': je_id,

'account_id': 7, #Receivables

'debit' : 120.00

}],{'context' :{'check_move_validity': False}})

l2 = models.execute_kw(db, uid, password, 'account.move.line', 'create',

[{'move_id': je_id,

'account_id': 17, #Revenue

'credit' : 100.00

}],{'context' :{'check_move_validity': False}})

l3 = models.execute_kw(db, uid, password, 'account.move.line', 'create',

[{'move_id': je_id,

'account_id': 14, #Tax

'credit' : 20.00

}],{'context' :{'check_move_validity': True}})

아바타
취소
관련 게시물 답글 화면 활동
3
7월 25
746
0
6월 20
61
1
5월 24
2783
1
11월 22
3225
3
6월 22
6488