Trying to set the mode of payment in Sales invoice

I am trying to create a paid invoice when a sales order is submitted. I have been able to do so but since i am using an is pos I am required to include a mode of payment. I have tried various ways but getting an error. See sample code and assist

target.status=‘Paid’
target.docstatus = 1
target.is_pos = 1
x=frappe.get_doc(“Mode of Payment”,“Cash”)
target.payments = x
target.save()
This gives me an error ModeOfPayment is not not iterable. Where am I going wrong? Please assist

If target.payments is link field to Mode of Payment

Try
target.payments = x.name

When I have tried
target.status=‘Paid’
target.docstatus = 1
target.is_pos = 1
x=frappe.get_doc(“Mode of Payment”,“Cash”)
target.payments = x.name
target.save()

Getting the error: AttributeError: ‘unicode’ object has no attribute ‘amount’

Hi I have sorted this the answer is - since payment is a list
x=frappe.get_doc(“Mode of Payment”,“Cash”)
target.payments.append(x)

1 Like