Error in Opening Invoice creation Tool (#11938) (#11941)

* add qty field

* cast qty to float

* PEP8 compliance
This commit is contained in:
tundebabzy 2017-12-12 09:49:07 +01:00 committed by Nabin Hait
parent ff1b875661
commit f628184c68
2 changed files with 79 additions and 13 deletions

View File

@ -8,6 +8,7 @@ from frappe import _
from frappe.utils import flt
from frappe.model.document import Document
class OpeningInvoiceCreationTool(Document):
def onload(self):
"""Load the Opening Invoice summary"""
@ -70,7 +71,7 @@ class OpeningInvoiceCreationTool(Document):
if not row.party:
frappe.throw(mandatory_error_msg.format(
idx=row.idx,
field= _("Party"),
field=_("Party"),
invoice_type=self.invoice_type
))
# set party type if not available
@ -80,14 +81,14 @@ class OpeningInvoiceCreationTool(Document):
if not row.posting_date:
frappe.throw(mandatory_error_msg.format(
idx=row.idx,
field= _("Party"),
field=_("Party"),
invoice_type=self.invoice_type
))
if not row.outstanding_amount:
frappe.throw(mandatory_error_msg.format(
idx=row.idx,
field= _("Outstanding Amount"),
field=_("Outstanding Amount"),
invoice_type=self.invoice_type
))
@ -99,10 +100,14 @@ class OpeningInvoiceCreationTool(Document):
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)
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
@ -111,8 +116,10 @@ class OpeningInvoiceCreationTool(Document):
default_uom = frappe.db.get_single_value("Stock Settings", "stock_uom") or _("Nos")
cost_center = frappe.db.get_value("Company", self.company, "cost_center")
if not cost_center:
frappe.throw(_("Please set the Default Cost Center in {0} company").format(frappe.bold(self.company)))
rate = flt(row.outstanding_amount) / row.qty
frappe.throw(
_("Please set the Default Cost Center in {0} company").format(frappe.bold(self.company))
)
rate = flt(row.outstanding_amount) / flt(row.qty)
return frappe._dict({
"uom": default_uom,
@ -143,8 +150,7 @@ class OpeningInvoiceCreationTool(Document):
"due_date": row.due_date,
"posting_date": row.posting_date,
frappe.scrub(party_type): row.party,
"doctype": "Sales Invoice" if self.invoice_type == "Sales" \
else "Purchase Invoice",
"doctype": "Sales Invoice" if self.invoice_type == "Sales" else "Purchase Invoice",
"currency": frappe.db.get_value("Company", self.company, "default_currency")
})
@ -160,4 +166,4 @@ def get_temporary_opening_account(company=None):
if not accounts:
frappe.throw(_("Please add a Temporary Opening account in Chart of Accounts"))
return accounts[0].name
return accounts[0].name

View File

@ -288,6 +288,66 @@
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "column_break_4",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "1",
"fieldname": "qty",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Quantity",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}
],
"has_web_view": 0,
@ -300,7 +360,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-11-15 14:19:00.433148",
"modified": "2017-12-11 17:49:14.541176",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Opening Invoice Creation Tool Item",