跳至內容
選單
此問題已被標幟
1 回覆
13201 瀏覽次數

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
768
0
6月 20
61
1
5月 24
2792
1
11月 22
3252
3
6月 22
6507