Fixes in Taxes, Quotation and Address Territory
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index dbcccc7..bbc6e53 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -27,6 +27,7 @@
self.set(fieldname, today())
if not self.fiscal_year:
self.fiscal_year = get_fiscal_year(self.get(fieldname))[0]
+ break
def validate_date_with_fiscal_year(self):
if self.meta.get_field("fiscal_year") :
@@ -125,12 +126,15 @@
tax_master = frappe.get_doc(tax_master_doctype, self.get(tax_master_field))
for i, tax in enumerate(tax_master.get(tax_parentfield)):
+ tax = tax.as_dict()
+
for fieldname in default_fields:
- tax.set(fieldname, None)
+ if fieldname in tax:
+ del tax[fieldname]
self.append(tax_parentfield, tax)
- def get_other_charges(self):
+ def set_other_charges(self):
self.set("other_charges", [])
self.set_taxes("other_charges", "taxes_and_charges")
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index 0a0b4f0..c3fbd6b 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -62,14 +62,36 @@
shipping_amount = condition.shipping_amount
break
- self.append("other_charges", {
+ shipping_charge = {
"doctype": "Sales Taxes and Charges",
"charge_type": "Actual",
"account_head": shipping_rule.account,
- "cost_center": shipping_rule.cost_center,
- "description": shipping_rule.label,
- "rate": shipping_amount
+ "cost_center": shipping_rule.cost_center
+ }
+
+ existing_shipping_charge = self.get("other_charges", filters=shipping_charge)
+ if existing_shipping_charge:
+ # take the last record found
+ existing_shipping_charge[-1].rate = shipping_amount
+ else:
+ shipping_charge["rate"] = shipping_amount
+ shipping_charge["description"] = shipping_rule.label
+ self.append("other_charges", shipping_charge)
+
+ self.calculate_taxes_and_totals()
+
+ def remove_shipping_charge(self):
+ if self.shipping_rule:
+ shipping_rule = frappe.get_doc("Shipping Rule", self.shipping_rule)
+ existing_shipping_charge = self.get("other_charges", {
+ "doctype": "Sales Taxes and Charges",
+ "charge_type": "Actual",
+ "account_head": shipping_rule.account,
+ "cost_center": shipping_rule.cost_center
})
+ if existing_shipping_charge:
+ self.get("other_charges").remove(existing_shipping_charge[-1])
+ self.calculate_taxes_and_totals()
def set_total_in_words(self):
from frappe.utils import money_in_words
@@ -242,6 +264,9 @@
self.precision("total_commission"))
def calculate_contribution(self):
+ if not self.meta.get_field("sales_team"):
+ return
+
total = 0.0
sales_team = self.get("sales_team")
for sales_person in sales_team:
diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js
index 4aaa138..067302e 100644
--- a/erpnext/public/js/transaction.js
+++ b/erpnext/public/js/transaction.js
@@ -716,7 +716,7 @@
if(this.frm.doc.taxes_and_charges) {
return this.frm.call({
doc: this.frm.doc,
- method: "get_other_charges",
+ method: "set_other_charges",
callback: function(r) {
if(!r.exc) {
me.calculate_taxes_and_totals();
diff --git a/erpnext/selling/doctype/customer/test_records.json b/erpnext/selling/doctype/customer/test_records.json
index b4fb6e5..6bac543 100644
--- a/erpnext/selling/doctype/customer/test_records.json
+++ b/erpnext/selling/doctype/customer/test_records.json
@@ -1,26 +1,26 @@
[
{
- "company": "_Test Company",
- "customer_group": "_Test Customer Group",
- "customer_name": "_Test Customer",
- "customer_type": "Individual",
- "doctype": "Customer",
+ "company": "_Test Company",
+ "customer_group": "_Test Customer Group",
+ "customer_name": "_Test Customer",
+ "customer_type": "Individual",
+ "doctype": "Customer",
"territory": "_Test Territory"
- },
+ },
{
- "company": "_Test Company",
- "customer_group": "_Test Customer Group",
- "customer_name": "_Test Customer 1",
- "customer_type": "Individual",
- "doctype": "Customer",
+ "company": "_Test Company",
+ "customer_group": "_Test Customer Group",
+ "customer_name": "_Test Customer 1",
+ "customer_type": "Individual",
+ "doctype": "Customer",
"territory": "_Test Territory"
- },
+ },
{
- "company": "_Test Company",
- "customer_group": "_Test Customer Group",
- "customer_name": "_Test Customer 2",
- "customer_type": "Individual",
- "doctype": "Customer",
+ "company": "_Test Company",
+ "customer_group": "_Test Customer Group",
+ "customer_name": "_Test Customer 2",
+ "customer_type": "Individual",
+ "doctype": "Customer",
"territory": "_Test Territory"
}
-]
\ No newline at end of file
+]
diff --git a/erpnext/selling/doctype/lead/lead.py b/erpnext/selling/doctype/lead/lead.py
index 5689d6d..525e451 100644
--- a/erpnext/selling/doctype/lead/lead.py
+++ b/erpnext/selling/doctype/lead/lead.py
@@ -33,6 +33,10 @@
if not validate_email_add(self.email_id):
frappe.throw(_('{0} is not a valid email id').format(self.email_id))
+ if self.email_id == self.lead_owner:
+ # Lead Owner cannot be same as the Lead
+ self.lead_owner = None
+
def on_update(self):
self.check_email_id_is_unique()
self.add_calendar_event()
diff --git a/erpnext/selling/doctype/lead/test_records.json b/erpnext/selling/doctype/lead/test_records.json
index 89eeab7..c286a12 100644
--- a/erpnext/selling/doctype/lead/test_records.json
+++ b/erpnext/selling/doctype/lead/test_records.json
@@ -1,27 +1,27 @@
[
{
- "doctype": "Lead",
- "email_id": "test_lead@example.com",
- "lead_name": "_Test Lead",
- "status": "Open",
- "territory": "_Test Territory"
- },
+ "doctype": "Lead",
+ "email_id": "test_lead@example.com",
+ "lead_name": "_Test Lead",
+ "status": "Open",
+ "territory": "_Test Territory Rest Of The World"
+ },
{
- "doctype": "Lead",
- "email_id": "test_lead1@example.com",
- "lead_name": "_Test Lead 1",
+ "doctype": "Lead",
+ "email_id": "test_lead1@example.com",
+ "lead_name": "_Test Lead 1",
"status": "Open"
- },
+ },
{
- "doctype": "Lead",
- "email_id": "test_lead2@example.com",
- "lead_name": "_Test Lead 2",
+ "doctype": "Lead",
+ "email_id": "test_lead2@example.com",
+ "lead_name": "_Test Lead 2",
"status": "Contacted"
- },
+ },
{
- "doctype": "Lead",
- "email_id": "test_lead3@example.com",
- "lead_name": "_Test Lead 3",
+ "doctype": "Lead",
+ "email_id": "test_lead3@example.com",
+ "lead_name": "_Test Lead 3",
"status": "Converted"
}
-]
\ No newline at end of file
+]
diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py
index f06a7dd..652a934 100644
--- a/erpnext/selling/doctype/quotation/quotation.py
+++ b/erpnext/selling/doctype/quotation/quotation.py
@@ -13,6 +13,14 @@
tname = 'Quotation Item'
fname = 'quotation_details'
+ def validate(self):
+ super(Quotation, self).validate()
+ self.set_status()
+ self.validate_order_type()
+ self.validate_for_items()
+ self.validate_uom_is_integer("stock_uom", "qty")
+ self.quotation_to = "Customer" if self.customer else "Lead"
+
def has_sales_order(self):
return frappe.db.get_value("Sales Order Item", {"prevdoc_docname": self.name, "docstatus": 1})
@@ -42,13 +50,6 @@
if is_sales_item == 'No':
frappe.throw(_("Item {0} must be Sales Item").format(d.item_code))
- def validate(self):
- super(Quotation, self).validate()
- self.set_status()
- self.validate_order_type()
- self.validate_for_items()
- self.validate_uom_is_integer("stock_uom", "qty")
-
def update_opportunity(self):
for opportunity in list(set([d.prevdoc_docname for d in self.get("quotation_details")])):
if opportunity:
diff --git a/erpnext/setup/doctype/territory/territory.py b/erpnext/setup/doctype/territory/territory.py
index 890e778..d1b8dda 100644
--- a/erpnext/setup/doctype/territory/territory.py
+++ b/erpnext/setup/doctype/territory/territory.py
@@ -21,3 +21,4 @@
def on_update(self):
super(Territory, self).on_update()
self.validate_one_root()
+
diff --git a/erpnext/stock/doctype/item/test_records.json b/erpnext/stock/doctype/item/test_records.json
index bc407e0..761d4f2 100644
--- a/erpnext/stock/doctype/item/test_records.json
+++ b/erpnext/stock/doctype/item/test_records.json
@@ -1,248 +1,252 @@
[
{
- "default_warehouse": "_Test Warehouse - _TC",
- "description": "_Test Item",
- "doctype": "Item",
- "expense_account": "_Test Account Cost for Goods Sold - _TC",
- "has_batch_no": "No",
- "has_serial_no": "No",
- "income_account": "Sales - _TC",
- "inspection_required": "No",
- "is_asset_item": "No",
- "is_pro_applicable": "Yes",
- "is_purchase_item": "Yes",
- "is_sales_item": "Yes",
- "is_service_item": "No",
- "is_stock_item": "Yes",
- "is_sub_contracted_item": "No",
- "item_code": "_Test Item",
- "item_group": "_Test Item Group",
- "item_name": "_Test Item",
+ "default_warehouse": "_Test Warehouse - _TC",
+ "description": "_Test Item",
+ "doctype": "Item",
+ "expense_account": "_Test Account Cost for Goods Sold - _TC",
+ "has_batch_no": "No",
+ "has_serial_no": "No",
+ "income_account": "Sales - _TC",
+ "inspection_required": "No",
+ "is_asset_item": "No",
+ "is_pro_applicable": "Yes",
+ "is_purchase_item": "Yes",
+ "is_sales_item": "Yes",
+ "is_service_item": "No",
+ "is_stock_item": "Yes",
+ "is_sub_contracted_item": "No",
+ "item_code": "_Test Item",
+ "item_group": "_Test Item Group",
+ "item_name": "_Test Item",
"item_reorder": [
{
- "doctype": "Item Reorder",
- "material_request_type": "Purchase",
- "parentfield": "item_reorder",
- "warehouse": "_Test Warehouse - _TC",
- "warehouse_reorder_level": 20,
+ "doctype": "Item Reorder",
+ "material_request_type": "Purchase",
+ "parentfield": "item_reorder",
+ "warehouse": "_Test Warehouse - _TC",
+ "warehouse_reorder_level": 20,
"warehouse_reorder_qty": 20
}
- ],
- "selling_cost_center": "_Test Cost Center - _TC",
- "stock_uom": "_Test UOM"
- },
+ ],
+ "selling_cost_center": "_Test Cost Center - _TC",
+ "stock_uom": "_Test UOM",
+ "show_in_website": 1,
+ "website_warehouse": "_Test Warehouse - _TC"
+ },
{
- "default_warehouse": "_Test Warehouse - _TC",
- "description": "_Test Item 2",
- "doctype": "Item",
- "expense_account": "_Test Account Cost for Goods Sold - _TC",
- "has_batch_no": "No",
- "has_serial_no": "No",
- "income_account": "Sales - _TC",
- "inspection_required": "No",
- "is_asset_item": "No",
- "is_pro_applicable": "Yes",
- "is_purchase_item": "Yes",
- "is_sales_item": "Yes",
- "is_service_item": "No",
- "is_stock_item": "Yes",
- "is_sub_contracted_item": "No",
- "item_code": "_Test Item 2",
- "item_group": "_Test Item Group",
- "item_name": "_Test Item 2",
- "stock_uom": "_Test UOM"
- },
+ "default_warehouse": "_Test Warehouse - _TC",
+ "description": "_Test Item 2",
+ "doctype": "Item",
+ "expense_account": "_Test Account Cost for Goods Sold - _TC",
+ "has_batch_no": "No",
+ "has_serial_no": "No",
+ "income_account": "Sales - _TC",
+ "inspection_required": "No",
+ "is_asset_item": "No",
+ "is_pro_applicable": "Yes",
+ "is_purchase_item": "Yes",
+ "is_sales_item": "Yes",
+ "is_service_item": "No",
+ "is_stock_item": "Yes",
+ "is_sub_contracted_item": "No",
+ "item_code": "_Test Item 2",
+ "item_group": "_Test Item Group",
+ "item_name": "_Test Item 2",
+ "stock_uom": "_Test UOM",
+ "show_in_website": 1,
+ "website_warehouse": "_Test Warehouse - _TC"
+ },
{
- "default_warehouse": "_Test Warehouse - _TC",
- "description": "_Test Item Home Desktop 100",
- "doctype": "Item",
- "expense_account": "_Test Account Cost for Goods Sold - _TC",
- "has_batch_no": "No",
- "has_serial_no": "No",
- "income_account": "Sales - _TC",
- "inspection_required": "No",
- "is_asset_item": "No",
- "is_manufactured_item": "No",
- "is_pro_applicable": "No",
- "is_purchase_item": "Yes",
- "is_sales_item": "Yes",
- "is_service_item": "No",
- "is_stock_item": "Yes",
- "is_sub_contracted_item": "No",
- "item_code": "_Test Item Home Desktop 100",
- "item_group": "_Test Item Group Desktops",
- "item_name": "_Test Item Home Desktop 100",
+ "default_warehouse": "_Test Warehouse - _TC",
+ "description": "_Test Item Home Desktop 100",
+ "doctype": "Item",
+ "expense_account": "_Test Account Cost for Goods Sold - _TC",
+ "has_batch_no": "No",
+ "has_serial_no": "No",
+ "income_account": "Sales - _TC",
+ "inspection_required": "No",
+ "is_asset_item": "No",
+ "is_manufactured_item": "No",
+ "is_pro_applicable": "No",
+ "is_purchase_item": "Yes",
+ "is_sales_item": "Yes",
+ "is_service_item": "No",
+ "is_stock_item": "Yes",
+ "is_sub_contracted_item": "No",
+ "item_code": "_Test Item Home Desktop 100",
+ "item_group": "_Test Item Group Desktops",
+ "item_name": "_Test Item Home Desktop 100",
"item_tax": [
{
- "doctype": "Item Tax",
- "parentfield": "item_tax",
- "tax_rate": 10,
+ "doctype": "Item Tax",
+ "parentfield": "item_tax",
+ "tax_rate": 10,
"tax_type": "_Test Account Excise Duty - _TC"
}
- ],
+ ],
"stock_uom": "_Test UOM"
- },
+ },
{
- "default_warehouse": "_Test Warehouse - _TC",
- "description": "_Test Item Home Desktop 200",
- "doctype": "Item",
- "expense_account": "_Test Account Cost for Goods Sold - _TC",
- "has_batch_no": "No",
- "has_serial_no": "No",
- "income_account": "Sales - _TC",
- "inspection_required": "No",
- "is_asset_item": "No",
- "is_manufactured_item": "No",
- "is_pro_applicable": "No",
- "is_purchase_item": "Yes",
- "is_sales_item": "Yes",
- "is_service_item": "No",
- "is_stock_item": "Yes",
- "is_sub_contracted_item": "No",
- "item_code": "_Test Item Home Desktop 200",
- "item_group": "_Test Item Group Desktops",
- "item_name": "_Test Item Home Desktop 200",
+ "default_warehouse": "_Test Warehouse - _TC",
+ "description": "_Test Item Home Desktop 200",
+ "doctype": "Item",
+ "expense_account": "_Test Account Cost for Goods Sold - _TC",
+ "has_batch_no": "No",
+ "has_serial_no": "No",
+ "income_account": "Sales - _TC",
+ "inspection_required": "No",
+ "is_asset_item": "No",
+ "is_manufactured_item": "No",
+ "is_pro_applicable": "No",
+ "is_purchase_item": "Yes",
+ "is_sales_item": "Yes",
+ "is_service_item": "No",
+ "is_stock_item": "Yes",
+ "is_sub_contracted_item": "No",
+ "item_code": "_Test Item Home Desktop 200",
+ "item_group": "_Test Item Group Desktops",
+ "item_name": "_Test Item Home Desktop 200",
"stock_uom": "_Test UOM"
- },
+ },
{
- "description": "_Test Sales BOM Item",
- "doctype": "Item",
- "expense_account": "_Test Account Cost for Goods Sold - _TC",
- "has_batch_no": "No",
- "has_serial_no": "No",
- "income_account": "Sales - _TC",
- "inspection_required": "No",
- "is_asset_item": "No",
- "is_pro_applicable": "No",
- "is_purchase_item": "Yes",
- "is_sales_item": "Yes",
- "is_service_item": "No",
- "is_stock_item": "No",
- "is_sub_contracted_item": "No",
- "item_code": "_Test Sales BOM Item",
- "item_group": "_Test Item Group Desktops",
- "item_name": "_Test Sales BOM Item",
+ "description": "_Test Sales BOM Item",
+ "doctype": "Item",
+ "expense_account": "_Test Account Cost for Goods Sold - _TC",
+ "has_batch_no": "No",
+ "has_serial_no": "No",
+ "income_account": "Sales - _TC",
+ "inspection_required": "No",
+ "is_asset_item": "No",
+ "is_pro_applicable": "No",
+ "is_purchase_item": "Yes",
+ "is_sales_item": "Yes",
+ "is_service_item": "No",
+ "is_stock_item": "No",
+ "is_sub_contracted_item": "No",
+ "item_code": "_Test Sales BOM Item",
+ "item_group": "_Test Item Group Desktops",
+ "item_name": "_Test Sales BOM Item",
"stock_uom": "_Test UOM"
- },
+ },
{
- "default_warehouse": "_Test Warehouse - _TC",
- "description": "_Test FG Item",
- "doctype": "Item",
- "expense_account": "_Test Account Cost for Goods Sold - _TC",
- "has_batch_no": "No",
- "has_serial_no": "No",
- "income_account": "Sales - _TC",
- "inspection_required": "No",
- "is_asset_item": "No",
- "is_pro_applicable": "Yes",
- "is_purchase_item": "Yes",
- "is_sales_item": "Yes",
- "is_service_item": "No",
- "is_stock_item": "Yes",
- "is_sub_contracted_item": "Yes",
- "item_code": "_Test FG Item",
- "item_group": "_Test Item Group Desktops",
- "item_name": "_Test FG Item",
+ "default_warehouse": "_Test Warehouse - _TC",
+ "description": "_Test FG Item",
+ "doctype": "Item",
+ "expense_account": "_Test Account Cost for Goods Sold - _TC",
+ "has_batch_no": "No",
+ "has_serial_no": "No",
+ "income_account": "Sales - _TC",
+ "inspection_required": "No",
+ "is_asset_item": "No",
+ "is_pro_applicable": "Yes",
+ "is_purchase_item": "Yes",
+ "is_sales_item": "Yes",
+ "is_service_item": "No",
+ "is_stock_item": "Yes",
+ "is_sub_contracted_item": "Yes",
+ "item_code": "_Test FG Item",
+ "item_group": "_Test Item Group Desktops",
+ "item_name": "_Test FG Item",
"stock_uom": "_Test UOM"
- },
+ },
{
- "description": "_Test Non Stock Item",
- "doctype": "Item",
- "has_batch_no": "No",
- "has_serial_no": "No",
- "inspection_required": "No",
- "is_asset_item": "No",
- "is_pro_applicable": "No",
- "is_purchase_item": "Yes",
- "is_sales_item": "Yes",
- "is_service_item": "No",
- "is_stock_item": "No",
- "is_sub_contracted_item": "No",
- "item_code": "_Test Non Stock Item",
- "item_group": "_Test Item Group Desktops",
- "item_name": "_Test Non Stock Item",
+ "description": "_Test Non Stock Item",
+ "doctype": "Item",
+ "has_batch_no": "No",
+ "has_serial_no": "No",
+ "inspection_required": "No",
+ "is_asset_item": "No",
+ "is_pro_applicable": "No",
+ "is_purchase_item": "Yes",
+ "is_sales_item": "Yes",
+ "is_service_item": "No",
+ "is_stock_item": "No",
+ "is_sub_contracted_item": "No",
+ "item_code": "_Test Non Stock Item",
+ "item_group": "_Test Item Group Desktops",
+ "item_name": "_Test Non Stock Item",
"stock_uom": "_Test UOM"
- },
+ },
{
- "default_warehouse": "_Test Warehouse - _TC",
- "description": "_Test Serialized Item",
- "doctype": "Item",
- "has_batch_no": "No",
- "has_serial_no": "Yes",
- "inspection_required": "No",
- "is_asset_item": "No",
- "is_pro_applicable": "No",
- "is_purchase_item": "Yes",
- "is_sales_item": "Yes",
- "is_service_item": "No",
- "is_stock_item": "Yes",
- "is_sub_contracted_item": "No",
- "item_code": "_Test Serialized Item",
- "item_group": "_Test Item Group Desktops",
- "item_name": "_Test Serialized Item",
+ "default_warehouse": "_Test Warehouse - _TC",
+ "description": "_Test Serialized Item",
+ "doctype": "Item",
+ "has_batch_no": "No",
+ "has_serial_no": "Yes",
+ "inspection_required": "No",
+ "is_asset_item": "No",
+ "is_pro_applicable": "No",
+ "is_purchase_item": "Yes",
+ "is_sales_item": "Yes",
+ "is_service_item": "No",
+ "is_stock_item": "Yes",
+ "is_sub_contracted_item": "No",
+ "item_code": "_Test Serialized Item",
+ "item_group": "_Test Item Group Desktops",
+ "item_name": "_Test Serialized Item",
"stock_uom": "_Test UOM"
- },
+ },
{
- "default_warehouse": "_Test Warehouse - _TC",
- "description": "_Test Serialized Item",
- "doctype": "Item",
- "has_batch_no": "No",
- "has_serial_no": "Yes",
- "inspection_required": "No",
- "is_asset_item": "No",
- "is_pro_applicable": "Yes",
- "is_purchase_item": "Yes",
- "is_sales_item": "Yes",
- "is_service_item": "No",
- "is_stock_item": "Yes",
- "is_sub_contracted_item": "No",
- "item_code": "_Test Serialized Item With Series",
- "item_group": "_Test Item Group Desktops",
- "item_name": "_Test Serialized Item With Series",
- "serial_no_series": "ABCD.#####",
+ "default_warehouse": "_Test Warehouse - _TC",
+ "description": "_Test Serialized Item",
+ "doctype": "Item",
+ "has_batch_no": "No",
+ "has_serial_no": "Yes",
+ "inspection_required": "No",
+ "is_asset_item": "No",
+ "is_pro_applicable": "Yes",
+ "is_purchase_item": "Yes",
+ "is_sales_item": "Yes",
+ "is_service_item": "No",
+ "is_stock_item": "Yes",
+ "is_sub_contracted_item": "No",
+ "item_code": "_Test Serialized Item With Series",
+ "item_group": "_Test Item Group Desktops",
+ "item_name": "_Test Serialized Item With Series",
+ "serial_no_series": "ABCD.#####",
"stock_uom": "_Test UOM"
- },
+ },
{
- "default_warehouse": "_Test Warehouse - _TC",
- "description": "_Test Item Home Desktop Manufactured",
- "doctype": "Item",
- "expense_account": "_Test Account Cost for Goods Sold - _TC",
- "has_batch_no": "No",
- "has_serial_no": "No",
- "income_account": "Sales - _TC",
- "inspection_required": "No",
- "is_asset_item": "No",
- "is_manufactured_item": "Yes",
- "is_pro_applicable": "Yes",
- "is_purchase_item": "Yes",
- "is_sales_item": "Yes",
- "is_service_item": "No",
- "is_stock_item": "Yes",
- "is_sub_contracted_item": "No",
- "item_code": "_Test Item Home Desktop Manufactured",
- "item_group": "_Test Item Group Desktops",
- "item_name": "_Test Item Home Desktop Manufactured",
+ "default_warehouse": "_Test Warehouse - _TC",
+ "description": "_Test Item Home Desktop Manufactured",
+ "doctype": "Item",
+ "expense_account": "_Test Account Cost for Goods Sold - _TC",
+ "has_batch_no": "No",
+ "has_serial_no": "No",
+ "income_account": "Sales - _TC",
+ "inspection_required": "No",
+ "is_asset_item": "No",
+ "is_manufactured_item": "Yes",
+ "is_pro_applicable": "Yes",
+ "is_purchase_item": "Yes",
+ "is_sales_item": "Yes",
+ "is_service_item": "No",
+ "is_stock_item": "Yes",
+ "is_sub_contracted_item": "No",
+ "item_code": "_Test Item Home Desktop Manufactured",
+ "item_group": "_Test Item Group Desktops",
+ "item_name": "_Test Item Home Desktop Manufactured",
"stock_uom": "_Test UOM"
- },
+ },
{
- "default_warehouse": "_Test Warehouse - _TC",
- "description": "_Test FG Item 2",
- "doctype": "Item",
- "expense_account": "_Test Account Cost for Goods Sold - _TC",
- "has_batch_no": "No",
- "has_serial_no": "No",
- "income_account": "Sales - _TC",
- "inspection_required": "No",
- "is_asset_item": "No",
- "is_pro_applicable": "Yes",
- "is_purchase_item": "Yes",
- "is_sales_item": "Yes",
- "is_service_item": "No",
- "is_stock_item": "Yes",
- "is_sub_contracted_item": "Yes",
- "item_code": "_Test FG Item 2",
- "item_group": "_Test Item Group Desktops",
- "item_name": "_Test FG Item 2",
+ "default_warehouse": "_Test Warehouse - _TC",
+ "description": "_Test FG Item 2",
+ "doctype": "Item",
+ "expense_account": "_Test Account Cost for Goods Sold - _TC",
+ "has_batch_no": "No",
+ "has_serial_no": "No",
+ "income_account": "Sales - _TC",
+ "inspection_required": "No",
+ "is_asset_item": "No",
+ "is_pro_applicable": "Yes",
+ "is_purchase_item": "Yes",
+ "is_sales_item": "Yes",
+ "is_service_item": "No",
+ "is_stock_item": "Yes",
+ "is_sub_contracted_item": "Yes",
+ "item_code": "_Test FG Item 2",
+ "item_group": "_Test Item Group Desktops",
+ "item_name": "_Test FG Item 2",
"stock_uom": "_Test UOM"
}
-]
\ No newline at end of file
+]
diff --git a/erpnext/stock/doctype/item_price/test_records.json b/erpnext/stock/doctype/item_price/test_records.json
index 72d5582..b4ceb92 100644
--- a/erpnext/stock/doctype/item_price/test_records.json
+++ b/erpnext/stock/doctype/item_price/test_records.json
@@ -1,8 +1,20 @@
[
{
- "doctype": "Item Price",
- "item_code": "_Test Item",
- "price_list": "_Test Price List",
+ "doctype": "Item Price",
+ "item_code": "_Test Item",
+ "price_list": "_Test Price List",
"price_list_rate": 100
+ },
+ {
+ "doctype": "Item Price",
+ "item_code": "_Test Item",
+ "price_list": "_Test Price List Rest of the World",
+ "price_list_rate": 10
+ },
+ {
+ "doctype": "Item Price",
+ "item_code": "_Test Item 2",
+ "price_list": "_Test Price List Rest of the World",
+ "price_list_rate": 20
}
-]
\ No newline at end of file
+]
diff --git a/erpnext/utilities/doctype/address/address.py b/erpnext/utilities/doctype/address/address.py
index 0558574..b00b40d 100644
--- a/erpnext/utilities/doctype/address/address.py
+++ b/erpnext/utilities/doctype/address/address.py
@@ -73,3 +73,18 @@
return display.strip()
+def get_territory_from_address(address):
+ """Tries to match city, state and country of address to existing territory"""
+ if not address:
+ return
+
+ if isinstance(address, basestring):
+ address = frappe.get_doc("Address", address)
+
+ territory = None
+ for fieldname in ("city", "state", "country"):
+ territory = frappe.db.get_value("Territory", address.get(fieldname))
+ if territory:
+ break
+
+ return territory