'Links invoice and advance voucher:
1. cancel advance voucher
2. split into multiple rows if partially adjusted, assign against voucher
3. submit advance voucher'

def update_against_document_in_jv(self):

    if (self.doctype == u'Sales    Invoice'):
        party_type = u'Customer'
        party = self.customer
        party_account = self.debit_to
        dr_or_cr = u'credit_in_account_currency'
    else:
        party_type = u'Supplier'
        party = self.supplier
        party_account = self.credit_to
        dr_or_cr = u'debit_in_account_currency'
    lst = []
    for d in self.get(u'advances'):
        if (flt(d.allocated_amount) > 0):
            args = frappe._dict({u'voucher_type': d.reference_type, u'voucher_no': d.reference_name, u'voucher_detail_no': d.reference_row, u'against_voucher_type': self.doctype, u'against_voucher': self.name, u'account': party_account, u'party_type': party_type, u'party': party, u'is_advance': u'Yes', u'dr_or_cr': dr_or_cr, u'unadjusted_amount': flt(d.advance_amount), u'allocated_amount': flt(d.allocated_amount), u'exchange_rate': (self.conversion_rate if (self.party_account_currency != self.company_currency) else 1), u'grand_total': (self.base_grand_total if (self.party_account_currency == self.company_currency) else self.grand_total), u'outstanding_amount': self.outstanding_amount})
            lst.append(args)
    if lst:
        from erpnext.accounts.utils import reconcile_against_document
        reconcile_against_document(lst)
