validation change

This commit is contained in:
hello@openetech.com 2019-11-23 06:50:51 +05:30 committed by Rohit Waghchaure
parent e9377e2513
commit 39b54cb889

View File

@ -19,6 +19,9 @@ import dateutil
from frappe.utils.file_manager import save_file from frappe.utils.file_manager import save_file
class ImportSupplierInvoice(Document): class ImportSupplierInvoice(Document):
def validate(self):
if not frappe.db.get_value("Stock Settings", fieldname="stock_uom"):
frappe.throw(_("Please set default UOM in Stock Settings"))
def autoname(self): def autoname(self):
if not self.name: if not self.name:
@ -35,9 +38,6 @@ class ImportSupplierInvoice(Document):
default_uom = frappe.db.get_value("Stock Settings", fieldname="stock_uom") default_uom = frappe.db.get_value("Stock Settings", fieldname="stock_uom")
if not default_uom:
frappe.throw(_("Please set default UOM in Stock Settings"))
with zipfile.ZipFile(get_full_path(self.zip_file)) as zf: with zipfile.ZipFile(get_full_path(self.zip_file)) as zf:
file_count = 0 file_count = 0
for file_name in zf.namelist(): for file_name in zf.namelist():
@ -158,7 +158,6 @@ class ImportSupplierInvoice(Document):
#read payment data from file #read payment data from file
for line in file_content.find_all("DettaglioPagamento"): for line in file_content.find_all("DettaglioPagamento"):
mop_code = line.ModalitaPagamento.text + '-' + mop_dict.get(line.ModalitaPagamento.text) mop_code = line.ModalitaPagamento.text + '-' + mop_dict.get(line.ModalitaPagamento.text)
if line.find("DataScadenzaPagamento"): if line.find("DataScadenzaPagamento"):
due_date = dateutil.parser.parse(line.DataScadenzaPagamento.text).strftime("%Y-%m-%d") due_date = dateutil.parser.parse(line.DataScadenzaPagamento.text).strftime("%Y-%m-%d")
else: else:
@ -208,7 +207,6 @@ class ImportSupplierInvoice(Document):
frappe.publish_realtime("import_invoice_update", {"title": title, "message": message, "count": count, "total": total}) frappe.publish_realtime("import_invoice_update", {"title": title, "message": message, "count": count, "total": total})
def create_supplier(**args): def create_supplier(**args):
args = frappe._dict(args) args = frappe._dict(args)
existing_supplier_name = frappe.db.get_value("Supplier", existing_supplier_name = frappe.db.get_value("Supplier",
filters={"tax_id": args.tax_id}, fieldname="name") filters={"tax_id": args.tax_id}, fieldname="name")
@ -261,7 +259,6 @@ def create_supplier(**args):
return new_supplier.name return new_supplier.name
def create_address(**args): def create_address(**args):
args = frappe._dict(args) args = frappe._dict(args)
filters = [ filters = [
["Dynamic Link", "link_doctype", "=", "Supplier"], ["Dynamic Link", "link_doctype", "=", "Supplier"],
@ -301,7 +298,6 @@ def create_address(**args):
return None return None
def create_purchase_invoice(**args): def create_purchase_invoice(**args):
args = frappe._dict(args) args = frappe._dict(args)
pi = frappe.get_doc({ pi = frappe.get_doc({
"doctype": "Purchase Invoice", "doctype": "Purchase Invoice",
@ -321,13 +317,11 @@ def create_purchase_invoice(**args):
try: try:
pi.set_missing_values() pi.set_missing_values()
pi.insert(ignore_permissions=True) pi.insert(ignore_permissions=True)
#if discount exists in file, apply any discount on grand total #if discount exists in file, apply any discount on grand total
if args.total_discount > 0: if args.total_discount > 0:
pi.apply_discount_on = "Grand Total" pi.apply_discount_on = "Grand Total"
pi.discount_amount = args.total_discount pi.discount_amount = args.total_discount
pi.save() pi.save()
#adjust payment amount to match with grand total calculated #adjust payment amount to match with grand total calculated
calc_total = 0 calc_total = 0
adj = 0 adj = 0
@ -344,14 +338,12 @@ def create_purchase_invoice(**args):
adj = 0 adj = 0
pi.imported_grand_total = calc_total pi.imported_grand_total = calc_total
pi.save() pi.save()
return pi.name return pi.name
except Exception as e: except Exception as e:
frappe.log_error(message=e, title="Create Purchase Invoice: " + args.bill_no + "File Name: " + args.file_name) frappe.log_error(message=e, title="Create Purchase Invoice: " + args.bill_no + "File Name: " + args.file_name)
return None return None
def get_country(code): def get_country(code):
existing_country_name = frappe.db.get_value("Country", existing_country_name = frappe.db.get_value("Country",
filters={"code": code}, fieldname="name") filters={"code": code}, fieldname="name")
if existing_country_name: if existing_country_name:
@ -360,7 +352,6 @@ def get_country(code):
frappe.throw(_("Country Code in File does not match with country code set up in the system")) frappe.throw(_("Country Code in File does not match with country code set up in the system"))
def create_uom(uom): def create_uom(uom):
existing_uom = frappe.db.get_value("UOM", existing_uom = frappe.db.get_value("UOM",
filters={"uom_name": uom}, fieldname="uom_name") filters={"uom_name": uom}, fieldname="uom_name")
if existing_uom: if existing_uom: