Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
4495 Представления

Hello ,

I need to be able to open an invoice from JAVA using the XMLRPC library. From what I have investigated I believe that the method is called ACTION_INVOICE_OPEN and in Python it receives at least the self object as a parameter.


It should be noted that the invoice is currently in a draft state.

I found functions to call functions using the library but I think I am parameterizing something wrong.


if someone can help me please, thank you in advance

Аватар
Отменить
Лучший ответ

Some people find it easier to understand the API calls by turning on logging so they can see, in real-time, what Odoo is doing as it creates and processes different kinds of documents.

https://www.odoo.com/documentation/13.0/reference/cmdline.html#logging


All I have is a script written in Python for version 12.0, we made major changes to the Accounting framework and account.invoice and account.invoice.line no longer exist.  You should be able to adapt this to work with account.move and account.move.line instead:


Switch the calls based on the examples at

import xmlrpclib
import csv
import requests
import base64
from dateutil.parser import parse
from time import gmtime, strftime


username = ''
pwd = ''
dbname = ''

sock_common = xmlrpclib.ServerProxy ('http://server:8069/xmlrpc/common', allow_none=True)

uid = sock_common.login(dbname, username, pwd)

sock = xmlrpclib.ServerProxy('http://server:8069/xmlrpc/2/object', allow_none=True)


reader = csv.reader(open('/opt/imports/vendor_bills.csv','rb'))

count = 0
for row in reader:
if count == 0:
count+=1
continue
count += 1

invoice_id = False
invoice_exist = False
partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'search', [('ref', '=', row[0]),('company_id', '=', 1)])
partner_id = partner_id[0]

if float(row[7]) > 0:
invoice_type = 'in_invoice'
price_unit = row[7]
else:
invoice_type = 'in_refund'
price_unit = -float(row[7])

currency = sock.execute(dbname, uid, pwd, 'res.currency', 'search', [('name', '=', 'USD')])
journal = sock.execute(dbname, uid, pwd, 'account.journal', 'search', [('name', '=', 'Vendor Bills'),('company_id', '=', 1)])
invoice_vals = {
'move_name': row[2],
'name': row[2],
'type': invoice_type,
'company_id': 1,
'date_invoice': parse(row[3]).strftime("%Y-%m-%d"),
'date_due': parse(row[5]).strftime("%Y-%m-%d"),
'partner_id': partner_id,
'currency_id': currency and currency[0],
'journal_id': journal and journal[0] or False,
'x_migrated':True,
'origin': 'Imported AP',
'user_id': False,
}

invoice_id = sock.execute(dbname, uid,pwd, 'account.invoice','create',invoice_vals)
account_id = sock.execute(dbname, uid, pwd, 'account.account', 'search', [('name', '=', 'Open AP'),('company_id', '=', 1)])
invoice_line_vals = {
'quantity': 1,
'price_unit': price_unit,
'account_id': account_id and account_id[0],
'company_id':1,
'name': 'Open AP',
'invoice_id': invoice_id,
'partner_id': partner_id,
}
sock.execute(dbname, uid,pwd, 'account.invoice.line','create',invoice_line_vals)
sock.execute_kw(dbname, uid, pwd, 'account.invoice', 'action_invoice_open', [invoice_id])


Аватар
Отменить
Автор Лучший ответ

I know that the action_invoice_open function is executed intermittently and the self is passed to the function, but I don't know how to do that using the XMLRPC library, any example works, apart from the LOG I have everything activated as the link you shared tells me

Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
нояб. 18
3933
0
янв. 22
3088
3
февр. 20
16007
3
дек. 19
4427
1
дек. 19
4193