# Buggy code
def make_invoices(self):
    names = []
    mandatory_error_msg = _(
        "Row {idx}: {field} is required to create the Opening {invoice_type} Invoices"
    )
    if not self.company:
        frappe.throw(_("Please select the Company"))

    for row in self.invoices:
        if not row.qty:
            row.qty = 1.0
        if not row.party:
            frappe.throw(
                mandatory_error_msg.format(
                    idx=row.idx, field=_("Party"), invoice_type=self.invoice_type
                )
            )
        # set party type if not available
        if not row.party_type:
            row.party_type = "Customer" if self.invoice_type == "Sales" else "Supplier"

        if not row.posting_date:
            frappe.throw(
                mandatory_error_msg.format(
                    idx=row.idx, field=_("Party"), invoice_type=self.invoice_type
                )
            )

        if not row.outstanding_amount:
            frappe.throw(
                mandatory_error_msg.format(
                    idx=row.idx,
                    field=_("Outstanding Amount"),
                    invoice_type=self.invoice_type,
                )
            )

        args = self.get_invoice_dict(row=row)
        if not args:
            continue

        doc = frappe.get_doc(args).insert()
        doc.submit()
        names.append(doc.name)

        if len(self.invoices) > 5:
            frappe.publish_realtime(
                "progress",
                dict(
                    progress=[row.idx, len(self.invoices)],
                    title=_("Creating {0}").format(doc.doctype),
                ),
                user=frappe.session.user,
            )

    return names


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/umairsayyed/frappe-bench/apps/frappe/frappe/app.py", line 62, in application
response = frappe.handler.handle()
File "/Users/umairsayyed/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle
data = execute_cmd(cmd)
File "/Users/umairsayyed/frappe-bench/apps/frappe/frappe/handler.py", line 53, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "/Users/umairsayyed/frappe-bench/apps/frappe/frappe/__init__.py", line 939, in call
return fn(*args, **newargs)
File "/Users/umairsayyed/frappe-bench/apps/frappe/frappe/handler.py", line 81, in runserverobj
frappe.desk.form.run_method.runserverobj(method, docs=docs, dt=dt, dn=dn, arg=arg, args=args)
File "/Users/umairsayyed/frappe-bench/apps/frappe/frappe/desk/form/run_method.py", line 36, in runserverobj
r = doc.run_method(method)
File "/Users/umairsayyed/frappe-bench/apps/frappe/frappe/model/document.py", line 755, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File "/Users/umairsayyed/frappe-bench/apps/frappe/frappe/model/document.py", line 1024, in composer
return composed(self, method, *args, **kwargs)
File "/Users/umairsayyed/frappe-bench/apps/frappe/frappe/model/document.py", line 1007, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File "/Users/umairsayyed/frappe-bench/apps/frappe/frappe/model/document.py", line 749, in <lambda>
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File "/Users/umairsayyed/frappe-bench/apps/erpnext/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py", line 68, in make_invoices
if not row.qty:
AttributeError: 'OpeningInvoiceCreationToolItem' object has no attribute 'qty'

# Fixed code
def make_invoices(self):
    names = []
    mandatory_error_msg = _(
        "Row {idx}: {field} is required to create the Opening {invoice_type} Invoices"
    )
    if not self.company:
        frappe.throw(_("Please select the Company"))

    for row in self.invoices:
        if not row.qty:
            row.qty = 1.0
        if not row.party:
            frappe.throw(
                mandatory_error_msg.format(
                    idx=row.idx, field=_("Party"), invoice_type=self.invoice_type
                )
            )
        # set party type if not available
        if not row.party_type:
            row.party_type = "Customer" if self.invoice_type == "Sales" else "Supplier"

        if not row.posting_date:
            frappe.throw(
                mandatory_error_msg.format(
                    idx=row.idx, field=_("Party"), invoice_type=self.invoice_type
                )
            )

        if not row.outstanding_amount:
            frappe.throw(
                mandatory_error_msg.format(
                    idx=row.idx,
                    field=_("Outstanding Amount"),
                    invoice_type=self.invoice_type,
                )
            )

        args = self.get_invoice_dict(row=row)
        if not args:
            continue

        doc = frappe.get_doc(args).insert()
        doc.submit()
        names.append(doc.name)

        if len(self.invoices) > 5:
            frappe.publish_realtime(
                "progress",
                dict(
                    progress=[row.idx, len(self.invoices)],
                    title=_("Creating {0}").format(doc.doctype),
                ),
                user=frappe.session.user,
            )

    return names