Skip to Content
Menu
This question has been flagged
1 Reply
11972 Views

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

Avatar
Discard
Author Best Answer

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}})

Avatar
Discard
Related Posts Replies Views Activity
0
Jun 20
61
1
May 24
2033
1
Nov 22
2508
3
Jun 22
5650
1
May 22
2617