Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
13193 Widoki

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
lip 25
760
0
cze 20
61
1
maj 24
2785
1
lis 22
3233
3
cze 22
6496