'create entry'

def create_payment_entry(self, submit=True):

    frappe.flags.ignore_account_permission = True
    ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
    if (self.reference_doctype == u'Sales    Invoice'):
        party_account = ref_doc.debit_to
    elif (self.reference_doctype == u'Purchase    Invoice'):
        party_account = ref_doc.credit_to
    else:
        party_account = get_party_account(u'Customer', ref_doc.get(u'customer'), ref_doc.company)
    party_account_currency = (ref_doc.get(u'party_account_currency') or get_account_currency(party_account))
    bank_amount = self.grand_total
    if ((party_account_currency == ref_doc.company_currency) and (party_account_currency != self.currency)):
        party_amount = ref_doc.base_grand_total
    else:
        party_amount = self.grand_total
    payment_entry = get_payment_entry(self.reference_doctype, self.reference_name, party_amount=party_amount, bank_account=self.payment_account, bank_amount=bank_amount)
    payment_entry.update({u'reference_no': self.name, u'reference_date': nowdate(), u'remarks': u'Payment    Entry    against    {0}    {1}    via    Payment    Request    {2}'.format(self.reference_doctype, self.reference_name, self.name)})
    if payment_entry.difference_amount:
        company_details = get_company_defaults(ref_doc.company)
        payment_entry.append(u'deductions', {u'account': company_details.exchange_gain_loss_account, u'cost_center': company_details.cost_center, u'amount': payment_entry.difference_amount})
    if submit:
        payment_entry.insert(ignore_permissions=True)
        payment_entry.submit()
    return payment_entry
