From 7eba1a35d33b77bf69f6e9102e243cd57509a489 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 2 Oct 2017 15:59:27 +0530 Subject: [PATCH] Controller init args fix (#11015) * Controller init args fix * cleanup useless code --- .../accounts/doctype/journal_entry/journal_entry.py | 4 ++-- .../doctype/purchase_invoice/purchase_invoice.py | 4 ++-- .../accounts/doctype/sales_invoice/sales_invoice.py | 4 ++-- erpnext/accounts/party.py | 6 ++++-- .../buying/doctype/purchase_order/purchase_order.py | 4 ++-- erpnext/controllers/accounts_controller.py | 4 ++-- erpnext/controllers/buying_controller.py | 2 +- erpnext/controllers/selling_controller.py | 3 ++- .../doctype/installation_note/installation_note.py | 4 ++-- erpnext/selling/doctype/quotation/quotation.py | 11 +++-------- erpnext/selling/doctype/sales_order/sales_order.py | 4 ++-- erpnext/setup/doctype/email_digest/email_digest.py | 7 +++---- erpnext/stock/doctype/delivery_note/delivery_note.py | 4 ++-- .../doctype/purchase_receipt/purchase_receipt.py | 4 ++-- erpnext/stock/doctype/serial_no/serial_no.py | 4 ++-- .../stock_reconciliation/stock_reconciliation.py | 4 ++-- 16 files changed, 35 insertions(+), 38 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 375d85d1b72..face5ede256 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -12,8 +12,8 @@ from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amo from erpnext.hr.doctype.employee_loan.employee_loan import update_disbursement_status class JournalEntry(AccountsController): - def __init__(self, arg1, arg2=None): - super(JournalEntry, self).__init__(arg1, arg2) + def __init__(self, *args, **kwargs): + super(JournalEntry, self).__init__(*args, **kwargs) def get_feed(self): return self.voucher_type diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index a46c4b96c33..78c5682ef87 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -22,8 +22,8 @@ form_grid_templates = { } class PurchaseInvoice(BuyingController): - def __init__(self, arg1, arg2=None): - super(PurchaseInvoice, self).__init__(arg1, arg2) + def __init__(self, *args, **kwargs): + super(PurchaseInvoice, self).__init__(*args, **kwargs) self.status_updater = [{ 'source_dt': 'Purchase Invoice Item', 'target_dt': 'Purchase Order Item', diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 7a787c4cba3..6ab614863b8 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -27,8 +27,8 @@ form_grid_templates = { } class SalesInvoice(SellingController): - def __init__(self, arg1, arg2=None): - super(SalesInvoice, self).__init__(arg1, arg2) + def __init__(self, *args, **kwargs): + super(SalesInvoice, self).__init__(*args, **kwargs) self.status_updater = [{ 'source_dt': 'Sales Invoice Item', 'target_field': 'billed_amt', diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 69f40f8b25a..bcec0a29c93 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -68,7 +68,8 @@ def set_address_details(out, party, party_type, doctype=None, company=None): billing_address_field = "customer_address" if party_type == "Lead" \ else party_type.lower() + "_address" out[billing_address_field] = get_default_address(party_type, party.name) - out.update(get_fetch_values(doctype, billing_address_field, out[billing_address_field])) + if doctype: + out.update(get_fetch_values(doctype, billing_address_field, out[billing_address_field])) # address display out.address_display = get_address_display(out[billing_address_field]) @@ -77,7 +78,8 @@ def set_address_details(out, party, party_type, doctype=None, company=None): if party_type in ["Customer", "Lead"]: out.shipping_address_name = get_default_address(party_type, party.name, 'is_shipping_address') out.shipping_address = get_address_display(out["shipping_address_name"]) - out.update(get_fetch_values(doctype, 'shipping_address_name', out.shipping_address_name)) + if doctype: + out.update(get_fetch_values(doctype, 'shipping_address_name', out.shipping_address_name)) if doctype and doctype in ['Delivery Note', 'Sales Invoice']: out.update(get_company_address(company)) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index e2f5a9dca87..36cef4396b9 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -20,8 +20,8 @@ form_grid_templates = { } class PurchaseOrder(BuyingController): - def __init__(self, arg1, arg2=None): - super(PurchaseOrder, self).__init__(arg1, arg2) + def __init__(self, *args, **kwargs): + super(PurchaseOrder, self).__init__(*args, **kwargs) self.status_updater = [{ 'source_dt': 'Purchase Order Item', 'target_dt': 'Material Request Item', diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index a9677b0e8d4..4f49c7747bc 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -15,8 +15,8 @@ from erpnext.exceptions import InvalidCurrency force_item_fields = ("item_group", "barcode", "brand", "stock_uom") class AccountsController(TransactionBase): - def __init__(self, arg1, arg2=None): - super(AccountsController, self).__init__(arg1, arg2) + def __init__(self, *args, **kwargs): + super(AccountsController, self).__init__(*args, **kwargs) @property def company_currency(self): diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 9cc061677e0..1f9051d4333 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -61,7 +61,7 @@ class BuyingController(StockController): # set contact and address details for supplier, if they are not mentioned if getattr(self, "supplier", None): - self.update_if_missing(get_party_details(self.supplier, party_type="Supplier", ignore_permissions=self.flags.ignore_permissions)) + self.update_if_missing(get_party_details(self.supplier, party_type="Supplier", ignore_permissions=self.flags.ignore_permissions, doctype=self.doctype, company=self.company)) self.set_missing_item_details(for_validate) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index d881f18b33b..c1028a598dd 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -49,7 +49,8 @@ class SellingController(StockController): if getattr(self, "customer", None): from erpnext.accounts.party import _get_party_details party_details = _get_party_details(self.customer, - ignore_permissions=self.flags.ignore_permissions) + ignore_permissions=self.flags.ignore_permissions, + doctype=self.doctype, company=self.company) if not self.meta.get_field("sales_team"): party_details.pop("sales_team") diff --git a/erpnext/selling/doctype/installation_note/installation_note.py b/erpnext/selling/doctype/installation_note/installation_note.py index 720247da56b..9f730f4878c 100644 --- a/erpnext/selling/doctype/installation_note/installation_note.py +++ b/erpnext/selling/doctype/installation_note/installation_note.py @@ -12,8 +12,8 @@ from erpnext.stock.utils import get_valid_serial_nos from erpnext.utilities.transaction_base import TransactionBase class InstallationNote(TransactionBase): - def __init__(self, arg1, arg2=None): - super(InstallationNote, self).__init__(arg1, arg2) + def __init__(self, *args, **kwargs): + super(InstallationNote, self).__init__(*args, **kwargs) self.status_updater = [{ 'source_dt': 'Installation Note Item', 'target_dt': 'Delivery Note Item', diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index 1cdd8404288..f0cce5ffb7c 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -32,7 +32,7 @@ class Quotation(SellingController): self.validate_valid_till() if self.items: self.with_items = 1 - + def validate_valid_till(self): if self.valid_till and self.valid_till < self.transaction_date: frappe.throw(_("Valid till date cannot be before transaction date")) @@ -79,15 +79,10 @@ class Quotation(SellingController): else: frappe.throw(_("Cannot set as Lost as Sales Order is made.")) - def check_item_table(self): - if not self.get('items'): - frappe.throw(_("Please enter item details")) - def on_submit(self): - self.check_item_table() - # Check for Approving Authority - frappe.get_doc('Authorization Control').validate_approving_authority(self.doctype, self.company, self.base_grand_total, self) + frappe.get_doc('Authorization Control').validate_approving_authority(self.doctype, + self.company, self.base_grand_total, self) #update enquiry status self.update_opportunity() diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 8720482549d..613b0bb31f5 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -22,8 +22,8 @@ form_grid_templates = { class WarehouseRequired(frappe.ValidationError): pass class SalesOrder(SellingController): - def __init__(self, arg1, arg2=None): - super(SalesOrder, self).__init__(arg1, arg2) + def __init__(self, *args, **kwargs): + super(SalesOrder, self).__init__(*args, **kwargs) def validate(self): super(SalesOrder, self).validate() diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index c85a541d849..8d1fb3d4a63 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -16,14 +16,13 @@ user_specific_content = ["calendar_events", "todo_list"] from frappe.model.document import Document class EmailDigest(Document): - def __init__(self, arg1, arg2=None): - super(EmailDigest, self).__init__(arg1, arg2) + def __init__(self, *args, **kwargs): + super(EmailDigest, self).__init__(*args, **kwargs) self.from_date, self.to_date = self.get_from_to_date() self.set_dates() self._accounts = {} - self.currency = frappe.db.get_value("Company", self.company, - "default_currency") + self.currency = frappe.db.get_value("Company", self.company, "default_currency") def get_users(self): """get list of users""" diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index f5a99afbd21..dd00398695b 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -21,8 +21,8 @@ form_grid_templates = { } class DeliveryNote(SellingController): - def __init__(self, arg1, arg2=None): - super(DeliveryNote, self).__init__(arg1, arg2) + def __init__(self, *args, **kwargs): + super(DeliveryNote, self).__init__(*args, **kwargs) self.status_updater = [{ 'source_dt': 'Delivery Note Item', 'target_dt': 'Sales Order Item', diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 2d089c4419e..e49f9937a56 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -19,8 +19,8 @@ form_grid_templates = { } class PurchaseReceipt(BuyingController): - def __init__(self, arg1, arg2=None): - super(PurchaseReceipt, self).__init__(arg1, arg2) + def __init__(self, *args, **kwargs): + super(PurchaseReceipt, self).__init__(*args, **kwargs) self.status_updater = [{ 'source_dt': 'Purchase Receipt Item', 'target_dt': 'Purchase Order Item', diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py index c39efa06f71..80c93ef434d 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -20,8 +20,8 @@ class SerialNoNotExistsError(ValidationError): pass class SerialNoDuplicateError(ValidationError): pass class SerialNo(StockController): - def __init__(self, arg1, arg2=None): - super(SerialNo, self).__init__(arg1, arg2) + def __init__(self, *args, **kwargs): + super(SerialNo, self).__init__(*args, **kwargs) self.via_stock_ledger = False def validate(self): diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index 360ebca11ea..0f91e43223a 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -14,8 +14,8 @@ class OpeningEntryAccountError(frappe.ValidationError): pass class EmptyStockReconciliationItemsError(frappe.ValidationError): pass class StockReconciliation(StockController): - def __init__(self, arg1, arg2=None): - super(StockReconciliation, self).__init__(arg1, arg2) + def __init__(self, *args, **kwargs): + super(StockReconciliation, self).__init__(*args, **kwargs) self.head_row = ["Item Code", "Warehouse", "Quantity", "Valuation Rate"] def validate(self):