コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
3047 ビュー

As i am new to the odoo i need some help. i want to sent my created invoice to the coustomer email using external api. here is my code how i am creating the invoice 

import xmlrpc.client

# Odoo API information
url = ''
db = ''
username = ''
password = ''

# Connect to Odoo API
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})

# Create a connection object
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))

customer_id=10
product_id
=1
# Create an invoice
invoice_data = {
'partner_id': customer_id, # ID of the customer for whom you want to create the invoice
'move_type': 'out_invoice', # Invoice type (out_invoice for customer invoice)
# Add other invoice data like invoice line items, payment terms, etc.
# For example:
'invoice_line_ids': [
(
0, 0, {
'product_id'
: product_id, # ID of the product on the invoice line
'quantity': 2,
'price_unit': 100.0,
})
]
,
}

invoice_id = models.execute_kw(db, uid, password, 'account.move', 'create', [invoice_data])

# Send the invoice by email
models.execute_kw(db, uid, password, 'account.move', 'action_post', [invoice_id])
invoice_sent = models.execute_kw(db, uid, password, 'account.move', 'action_invoice_sent', [invoice_id])

i am using odoo online. kindly help. 

アバター
破棄
最善の回答
import xmlrpc.client

# Odoo API information: edit it to match your config
url = 'http://localhost:8069'
db = 'MY_DB'
username = 'admin'
password = 'admin'

# Connect to Odoo API
# You may support *sending* None values by passing allow_none=True to the ServerProxy
# In order to *receive* None values you would have to modify odoo core (not recommended)
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})

# Create a connection object
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))

# Create and post an invoice
invoice_data = {
'partner_id': 10,
'move_type': 'out_invoice',
'invoice_line_ids': [
(0, 0, {
'product_id': 1,
'quantity': 2,
'price_unit': 100.0,
})
],
}
invoice_id_1 = models.execute_kw(db, uid, password, 'account.move', 'create', [invoice_data])
invoice_id_2 = models.execute_kw(db, uid, password, 'account.move', 'create', [invoice_data])
invoice_ids = [invoice_id_1, invoice_id_2]
models.execute_kw(db, uid, password, 'account.move', 'action_post', [invoice_ids])

# Prepare values to create send & print wizard
action_vals = models.execute_kw(db, uid, password, 'account.move', 'action_send_and_print', [invoice_ids])

# arguments
# 1) the ORM create() method needs arguments to complete, since that method starts with
# if not vals_list:
# return self.browse()
# 2) the is_print arg avoids the local printing and downloading of the PDF
# this is simply because account.invoice.send's _print_document() method returns a dict
# containing a None value, which is not supported in xmlrpc unless allow_none is enabled
# 3) the composition_mode is necessary to send multiple e-mails at once
wizard_args = [{'is_print': False, 'composition_mode': 'mass_mail'}]

# keyword arguments: the context contains some necessary values such as active_ids
wizard_kwargs = {'context': action_vals.get('context')}

# Create the wizard
wizard_id = models.execute_kw(db, uid, password, 'account.invoice.send', 'create', wizard_args, wizard_kwargs)

# Use the wizard to send the e-mails
# we provide the context once more as send_and_print_action also relies on it for active_ids
wizard_close = models.execute_kw(db, uid, password, 'account.invoice.send', 'send_and_print_action', [wizard_id], wizard_kwargs)

アバター
破棄
関連投稿 返信 ビュー 活動
1
12月 22
2118
3
3月 24
4024
1
1月 23
1856
3
1月 23
6378
1
6月 22
3137