I'm getting record does not exist or has been deleted.\n(record: account.move.line(5398,), user: 7) error while updating data to odoo. Following is my code can anyone help to solve this problem.
import xmlrpc.client
endpoint_url = "/api/account.move/"
obj = get_object_or_404(OrderItem, order__id=order_id)
invoice_date = obj.order.created_on
name = obj.product.varient_name
price = obj.total
quantity = obj.quantity
payment_source = obj.order.payment_method
payment_reference = obj.order.order_number
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
ids = models.execute_kw(db, uid, password, 'account.move', 'search_read', [[['source_document', '=', payment_reference]]], {'fields': ['partner_id', 'id']})
invoice_id = ids[0]['id']
partner_id_ = ids[0]['partner_id'][0]
headers = {
"access-token":tokens,
"Content-type":"application/jsonp",
"Cookie":session_id
}
api_invoice_line_id = [(1, invoice_id,{'name':name, 'price_unit':price, 'quantity':quantity})]
data = {
"partner_id":partner_id_,
"invoice_date":str(invoice_date),
"move_type":"out_invoice",
"__api__invoice_line_ids":str(api_invoice_line_id),
"payment_source":payment_source,
"source_document": payment_reference,
"rider":rider_name,
"ref":""
}
datas_ = json.dumps(data, indent=4)
req = requests.put(url+endpoint_url+str(invoice_id), headers=headers, data=datas_)
if req.status_code == 200:
status = "Update Successful"
else:
status = str(req.text)
return status
It looks like your code is failing because of the tuple you give to insert/update data in __api__invoice_line_ids
.
I suppose it's some account.move.line
Many2many or One2many field.
I see you are using the command 1 with invoice_id
(an account.move
id) and some data in a dict.
The problem here is that you are then trying to add that in the field pointing to account.move.line
. So your ID 5398 is the account.move
id, not an account.move.line
id.
Not sure what your goal is to achieve here. If it's to push/update some account.move records with new data, change your __api__invoice_line_ids
to point to account.move.
If your goal is to push/update some account.move.line
records, then you better loop on the line_ids
of your invoice_id
:)
If I wasn't clear on something or you have any other question don't hesitate asking !