From 5b552b51f1359002b498a69747acbc434a248ccf Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 2 Apr 2014 15:03:35 +0530 Subject: [PATCH] frappe/frappe#478 --- .../journal_voucher/journal_voucher.py | 3 +- .../period_closing_voucher.py | 4 +-- .../purchase_common/purchase_common.py | 7 ++--- .../doctype/purchase_order/purchase_order.py | 26 ++++++++-------- erpnext/controllers/accounts_controller.py | 12 ++------ erpnext/controllers/buying_controller.py | 12 -------- .../production_planning_tool.py | 2 ++ .../installation_note/installation_note.py | 30 +++++++++---------- erpnext/selling/doctype/lead/lead.py | 15 +++++----- .../authorization_control.py | 4 +-- .../setup/doctype/item_group/item_group.py | 2 +- .../material_request/material_request.py | 1 - .../stock/doctype/packed_item/packed_item.py | 2 +- .../doctype/sms_control/sms_control.py | 2 +- erpnext/utilities/transaction_base.py | 4 +-- 15 files changed, 53 insertions(+), 73 deletions(-) diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.py b/erpnext/accounts/doctype/journal_voucher/journal_voucher.py index a2fbec1da8..02bca17732 100644 --- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.py +++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.py @@ -11,7 +11,8 @@ from erpnext.setup.utils import get_company_currency from erpnext.controllers.accounts_controller import AccountsController class JournalVoucher(AccountsController): - + def __init__(self, arg1, arg2=None): + super(JournalVoucher, self).__init__(arg1, arg2) self.master_type = {} self.credit_days_for = {} self.credit_days_global = -1 diff --git a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py index a07ed2f3a5..d8661e19d8 100644 --- a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py +++ b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py @@ -8,8 +8,6 @@ from frappe import _ from erpnext.controllers.accounts_controller import AccountsController class PeriodClosingVoucher(AccountsController): - self.year_start_date = '' - def validate(self): self.validate_account_head() self.validate_posting_date() @@ -47,7 +45,7 @@ class PeriodClosingVoucher(AccountsController): and t2.docstatus < 2 and t2.company = %s and t1.posting_date between %s and %s group by t1.account - """, (self.company, self.year_start_date, self.posting_date), as_dict=1) + """, (self.company, self.get("year_start_date"), self.posting_date), as_dict=1) def make_gl_entries(self): gl_entries = [] diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.py b/erpnext/buying/doctype/purchase_common/purchase_common.py index a57114446c..80af450654 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.py +++ b/erpnext/buying/doctype/purchase_common/purchase_common.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals import frappe from frappe.utils import cstr, flt -from frappe.model.utils import getlist from frappe import msgprint, _ from erpnext.stock.doctype.item.item import get_last_purchase_details @@ -19,7 +18,7 @@ class PurchaseCommon(BuyingController): import frappe.utils this_purchase_date = frappe.utils.getdate(obj.get('posting_date') or obj.get('transaction_date')) - for d in getlist(obj.doclist,obj.fname): + for d in obj.get(obj.fname): # get last purchase details last_purchase_details = get_last_purchase_details(d.item_code, obj.name) @@ -47,7 +46,7 @@ class PurchaseCommon(BuyingController): doc_name = obj.name conversion_rate = flt(obj.get('conversion_rate')) or 1.0 - for d in getlist(obj.doclist, obj.fname): + for d in obj.get(obj.fname): if d.item_code: last_purchase_details = get_last_purchase_details(d.item_code, doc_name) @@ -69,7 +68,7 @@ class PurchaseCommon(BuyingController): def validate_for_items(self, obj): check_list, chk_dupl_itm=[],[] - for d in getlist( obj.doclist, obj.fname): + for d in obj.get(obj.fname): # validation for valid qty if flt(d.qty) < 0 or (d.parenttype != 'Purchase Receipt' and not flt(d.qty)): frappe.throw("Please enter valid qty for item %s" % cstr(d.item_code)) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index ca68e2b515..81c7dfb9d0 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -11,19 +11,19 @@ from frappe import msgprint from erpnext.controllers.buying_controller import BuyingController class PurchaseOrder(BuyingController): - self.tname = 'Purchase Order Item' - self.fname = 'po_details' - self.status_updater = [{ - 'source_dt': 'Purchase Order Item', - 'target_dt': 'Material Request Item', - 'join_field': 'prevdoc_detail_docname', - 'target_field': 'ordered_qty', - 'target_parent_dt': 'Material Request', - 'target_parent_field': 'per_ordered', - 'target_ref_field': 'qty', - 'source_field': 'qty', - 'percent_join_field': 'prevdoc_docname', - }] + tname = 'Purchase Order Item' + fname = 'po_details' + status_updater = [{ + 'source_dt': 'Purchase Order Item', + 'target_dt': 'Material Request Item', + 'join_field': 'prevdoc_detail_docname', + 'target_field': 'ordered_qty', + 'target_parent_dt': 'Material Request', + 'target_parent_field': 'per_ordered', + 'target_ref_field': 'qty', + 'source_field': 'qty', + 'percent_join_field': 'prevdoc_docname', + }] def validate(self): super(DocType, self).validate() diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 777150e7b3..b3155fd79f 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -342,20 +342,14 @@ class AccountsController(TransactionBase): def _cleanup(self): for tax in self.tax_doclist: - for fieldname in ("grand_total_for_current_item", - "tax_amount_for_current_item", - "tax_fraction_for_current_item", - "grand_total_fraction_for_current_item"): - if fieldname in tax.fields: - del tax.get(fieldname) - tax.item_wise_tax_detail = json.dumps(tax.item_wise_tax_detail) def _set_in_company_currency(self, item, print_field, base_field): """set values in base currency""" - item.set(base_field, flt((flt(item.get(print_field),) - self.precision(print_field, item)) * self.conversion_rate), + value_in_company_currency = flt(self.conversion_rate * + flt(item.get(print_field), self.precision(print_field, item)), self.precision(base_field, item)) + item.set(base_field, value_in_company_currency) def calculate_total_advance(self, parenttype, advance_parentfield): if self.doctype == parenttype and self.docstatus < 2: diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index b186e5c665..b37213c0e8 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -147,18 +147,6 @@ class BuyingController(StockController): self.outstanding_amount = flt(self.total_amount_to_pay - self.total_advance, self.precision("outstanding_amount")) - def _cleanup(self): - super(BuyingController, self)._cleanup() - - if not self.meta.get_field("item_tax_amount", parentfield=self.fname): - for item in self.item_doclist: - del item.get("item_tax_amount") - - if not self.meta.get_field("tax_amount_after_discount_amount", - parentfield=self.other_fname): - for tax in self.tax_doclist: - del tax.get("tax_amount_after_discount_amount") - # update valuation rate def update_valuation_rate(self, parentfield): """ diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py index 8c9c3cdb9f..cec6471bb2 100644 --- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py +++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py @@ -10,6 +10,8 @@ from frappe import msgprint, _ from frappe.model.document import Document class ProductionPlanningTool(Document): + def __init__(self, arg1, arg2=None): + super(ProductionPlanningTool, self).__init__(arg1, arg2) self.item_dict = {} def get_so_details(self, so): diff --git a/erpnext/selling/doctype/installation_note/installation_note.py b/erpnext/selling/doctype/installation_note/installation_note.py index 91f1a07e93..b69e319001 100644 --- a/erpnext/selling/doctype/installation_note/installation_note.py +++ b/erpnext/selling/doctype/installation_note/installation_note.py @@ -12,21 +12,21 @@ from erpnext.stock.utils import get_valid_serial_nos from erpnext.utilities.transaction_base import TransactionBase class InstallationNote(TransactionBase): - self.tname = 'Installation Note Item' - self.fname = 'installed_item_details' - self.status_updater = [{ - 'source_dt': 'Installation Note Item', - 'target_dt': 'Delivery Note Item', - 'target_field': 'installed_qty', - 'target_ref_field': 'qty', - 'join_field': 'prevdoc_detail_docname', - 'target_parent_dt': 'Delivery Note', - 'target_parent_field': 'per_installed', - 'source_field': 'qty', - 'percent_join_field': 'prevdoc_docname', - 'status_field': 'installation_status', - 'keyword': 'Installed' - }] + tname = 'Installation Note Item' + fname = 'installed_item_details' + status_updater = [{ + 'source_dt': 'Installation Note Item', + 'target_dt': 'Delivery Note Item', + 'target_field': 'installed_qty', + 'target_ref_field': 'qty', + 'join_field': 'prevdoc_detail_docname', + 'target_parent_dt': 'Delivery Note', + 'target_parent_field': 'per_installed', + 'source_field': 'qty', + 'percent_join_field': 'prevdoc_docname', + 'status_field': 'installation_status', + 'keyword': 'Installed' + }] def validate(self): self.validate_fiscal_year() diff --git a/erpnext/selling/doctype/lead/lead.py b/erpnext/selling/doctype/lead/lead.py index 4fdb8c0bd5..743dc04c6f 100644 --- a/erpnext/selling/doctype/lead/lead.py +++ b/erpnext/selling/doctype/lead/lead.py @@ -11,20 +11,19 @@ from frappe import session from erpnext.controllers.selling_controller import SellingController class Lead(SellingController): - - self._prev = frappe._dict({ - "contact_date": frappe.db.get_value("Lead", self.name, "contact_date") if \ - (not cint(self.get("__islocal"))) else None, - "contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if \ - (not cint(self.get("__islocal"))) else None, - }) - def onload(self): customer = frappe.db.get_value("Customer", {"lead_name": self.name}) if customer: self.set("__is_customer", customer) def validate(self): + self._prev = frappe._dict({ + "contact_date": frappe.db.get_value("Lead", self.name, "contact_date") if \ + (not cint(self.get("__islocal"))) else None, + "contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if \ + (not cint(self.get("__islocal"))) else None, + }) + self.set_status() if self.source == 'Campaign' and not self.campaign_name and session['user'] != 'Guest': diff --git a/erpnext/setup/doctype/authorization_control/authorization_control.py b/erpnext/setup/doctype/authorization_control/authorization_control.py index a50eb2f8c6..8a401f07be 100644 --- a/erpnext/setup/doctype/authorization_control/authorization_control.py +++ b/erpnext/setup/doctype/authorization_control/authorization_control.py @@ -86,7 +86,7 @@ class AuthorizationControl(TransactionBase): add_cond = " and master_name = '"+make_esc("'")(cstr(customer))+"'" if based_on == 'Itemwise Discount': if doc_obj: - for t in getlist(doc_obj.doclist, doc_obj.fname): + for t in doc_obj.get(doc_obj.fname): self.validate_auth_rule(doctype_name, t.discount_percentage, based_on, add_cond, company,t.item_code ) else: self.validate_auth_rule(doctype_name, auth_value, based_on, add_cond, company) @@ -98,7 +98,7 @@ class AuthorizationControl(TransactionBase): av_dis = 0 if doc_obj: price_list_rate, base_rate = 0, 0 - for d in getlist(doc_obj.doclist, doc_obj.fname): + for d in doc_obj.get(doc_obj.fname): if d.base_price_list_rate and d.base_rate: price_list_rate += flt(d.base_price_list_rate) base_rate += flt(d.base_rate) diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py index 52880fc8d5..e1f79a570b 100644 --- a/erpnext/setup/doctype/item_group/item_group.py +++ b/erpnext/setup/doctype/item_group/item_group.py @@ -7,7 +7,7 @@ import frappe from frappe.utils.nestedset import DocTypeNestedSet class ItemGroup(DocTypeNestedSet): - self.nsm_parent_field = 'parent_item_group' + nsm_parent_field = 'parent_item_group' def validate(self): if not self.parent_website_route: diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py index fc7f64eb6f..f9ba9b527f 100644 --- a/erpnext/stock/doctype/material_request/material_request.py +++ b/erpnext/stock/doctype/material_request/material_request.py @@ -8,7 +8,6 @@ from __future__ import unicode_literals import frappe from frappe.utils import cstr, flt -from frappe.model.utils import getlist from frappe import msgprint, _ from erpnext.controllers.buying_controller import BuyingController diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py index 232e60149d..755c110875 100644 --- a/erpnext/stock/doctype/packed_item/packed_item.py +++ b/erpnext/stock/doctype/packed_item/packed_item.py @@ -32,7 +32,7 @@ def update_packing_list_item(obj, packing_item_code, qty, warehouse, line, packi # check if exists exists = 0 - for d in getlist(obj.doclist, 'packing_details'): + for d in obj.get("packing_details"): if d.parent_item == line.item_code and d.item_code == packing_item_code and d.parent_detail_docname == line.name: pi, exists = d, 1 break diff --git a/erpnext/utilities/doctype/sms_control/sms_control.py b/erpnext/utilities/doctype/sms_control/sms_control.py index c0a46471fc..6b8c684ec6 100644 --- a/erpnext/utilities/doctype/sms_control/sms_control.py +++ b/erpnext/utilities/doctype/sms_control/sms_control.py @@ -70,7 +70,7 @@ class SmsControl(Document): def send_via_gateway(self, arg): ss = frappe.get_doc('SMS Settings', 'SMS Settings') args = {ss.message_parameter : arg.get('message')} - for d in getlist(ss.doclist, 'static_parameter_details'): + for d in ss.get("static_parameter_details"): args[d.parameter] = d.value resp = [] diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py index 66a1a0320f..4be3d6fb24 100644 --- a/erpnext/utilities/transaction_base.py +++ b/erpnext/utilities/transaction_base.py @@ -13,8 +13,8 @@ class TransactionBase(StatusUpdater): def load_notification_message(self): dt = self.doctype.lower().replace(" ", "_") if int(frappe.db.get_value("Notification Control", None, dt) or 0): - self.set("__notification_message", \) - frappe.db.get_value("Notification Control", None, dt + "_message") + self.set("__notification_message", + frappe.db.get_value("Notification Control", None, dt + "_message")) def validate_posting_time(self): if not self.posting_time: