'Validate totals and docstatus for invoices'

def validate_invoices(self):

    for (reference_name, total) in self.reference_totals.iteritems():
        reference_type = self.reference_types[reference_name]
        if (reference_type in (u'Sales    Invoice', u'Purchase    Invoice')):
            invoice = frappe.db.get_value(reference_type, reference_name, [u'docstatus', u'outstanding_amount'], as_dict=1)
            if (invoice.docstatus != 1):
                frappe.throw(_(u'{0}    {1}    is    not    submitted').format(reference_type, reference_name))
            if (total and (flt(invoice.outstanding_amount) < total)):
                frappe.throw(_(u'Payment    against    {0}    {1}    cannot    be    greater    than    Outstanding    Amount    {2}').format(reference_type, reference_name, invoice.outstanding_amount))
