Fixes in Taxes, Quotation and Address Territory

This commit is contained in:
Anand Doshi
2014-04-18 01:30:14 +05:30
parent 33e1db8c40
commit ac32bad25a
11 changed files with 338 additions and 272 deletions

View File

@@ -27,6 +27,7 @@ class AccountsController(TransactionBase):
self.set(fieldname, today()) self.set(fieldname, today())
if not self.fiscal_year: if not self.fiscal_year:
self.fiscal_year = get_fiscal_year(self.get(fieldname))[0] self.fiscal_year = get_fiscal_year(self.get(fieldname))[0]
break
def validate_date_with_fiscal_year(self): def validate_date_with_fiscal_year(self):
if self.meta.get_field("fiscal_year") : if self.meta.get_field("fiscal_year") :
@@ -125,12 +126,15 @@ class AccountsController(TransactionBase):
tax_master = frappe.get_doc(tax_master_doctype, self.get(tax_master_field)) tax_master = frappe.get_doc(tax_master_doctype, self.get(tax_master_field))
for i, tax in enumerate(tax_master.get(tax_parentfield)): for i, tax in enumerate(tax_master.get(tax_parentfield)):
tax = tax.as_dict()
for fieldname in default_fields: for fieldname in default_fields:
tax.set(fieldname, None) if fieldname in tax:
del tax[fieldname]
self.append(tax_parentfield, tax) self.append(tax_parentfield, tax)
def get_other_charges(self): def set_other_charges(self):
self.set("other_charges", []) self.set("other_charges", [])
self.set_taxes("other_charges", "taxes_and_charges") self.set_taxes("other_charges", "taxes_and_charges")

View File

@@ -62,14 +62,36 @@ class SellingController(StockController):
shipping_amount = condition.shipping_amount shipping_amount = condition.shipping_amount
break break
self.append("other_charges", { shipping_charge = {
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"charge_type": "Actual", "charge_type": "Actual",
"account_head": shipping_rule.account, "account_head": shipping_rule.account,
"cost_center": shipping_rule.cost_center, "cost_center": shipping_rule.cost_center
"description": shipping_rule.label, }
"rate": shipping_amount
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): def set_total_in_words(self):
from frappe.utils import money_in_words from frappe.utils import money_in_words
@@ -242,6 +264,9 @@ class SellingController(StockController):
self.precision("total_commission")) self.precision("total_commission"))
def calculate_contribution(self): def calculate_contribution(self):
if not self.meta.get_field("sales_team"):
return
total = 0.0 total = 0.0
sales_team = self.get("sales_team") sales_team = self.get("sales_team")
for sales_person in sales_team: for sales_person in sales_team:

View File

@@ -716,7 +716,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
if(this.frm.doc.taxes_and_charges) { if(this.frm.doc.taxes_and_charges) {
return this.frm.call({ return this.frm.call({
doc: this.frm.doc, doc: this.frm.doc,
method: "get_other_charges", method: "set_other_charges",
callback: function(r) { callback: function(r) {
if(!r.exc) { if(!r.exc) {
me.calculate_taxes_and_totals(); me.calculate_taxes_and_totals();

View File

@@ -1,26 +1,26 @@
[ [
{ {
"company": "_Test Company", "company": "_Test Company",
"customer_group": "_Test Customer Group", "customer_group": "_Test Customer Group",
"customer_name": "_Test Customer", "customer_name": "_Test Customer",
"customer_type": "Individual", "customer_type": "Individual",
"doctype": "Customer", "doctype": "Customer",
"territory": "_Test Territory" "territory": "_Test Territory"
}, },
{ {
"company": "_Test Company", "company": "_Test Company",
"customer_group": "_Test Customer Group", "customer_group": "_Test Customer Group",
"customer_name": "_Test Customer 1", "customer_name": "_Test Customer 1",
"customer_type": "Individual", "customer_type": "Individual",
"doctype": "Customer", "doctype": "Customer",
"territory": "_Test Territory" "territory": "_Test Territory"
}, },
{ {
"company": "_Test Company", "company": "_Test Company",
"customer_group": "_Test Customer Group", "customer_group": "_Test Customer Group",
"customer_name": "_Test Customer 2", "customer_name": "_Test Customer 2",
"customer_type": "Individual", "customer_type": "Individual",
"doctype": "Customer", "doctype": "Customer",
"territory": "_Test Territory" "territory": "_Test Territory"
} }
] ]

View File

@@ -33,6 +33,10 @@ class Lead(SellingController):
if not validate_email_add(self.email_id): if not validate_email_add(self.email_id):
frappe.throw(_('{0} is not a valid email id').format(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): def on_update(self):
self.check_email_id_is_unique() self.check_email_id_is_unique()
self.add_calendar_event() self.add_calendar_event()

View File

@@ -1,27 +1,27 @@
[ [
{ {
"doctype": "Lead", "doctype": "Lead",
"email_id": "test_lead@example.com", "email_id": "test_lead@example.com",
"lead_name": "_Test Lead", "lead_name": "_Test Lead",
"status": "Open", "status": "Open",
"territory": "_Test Territory" "territory": "_Test Territory Rest Of The World"
}, },
{ {
"doctype": "Lead", "doctype": "Lead",
"email_id": "test_lead1@example.com", "email_id": "test_lead1@example.com",
"lead_name": "_Test Lead 1", "lead_name": "_Test Lead 1",
"status": "Open" "status": "Open"
}, },
{ {
"doctype": "Lead", "doctype": "Lead",
"email_id": "test_lead2@example.com", "email_id": "test_lead2@example.com",
"lead_name": "_Test Lead 2", "lead_name": "_Test Lead 2",
"status": "Contacted" "status": "Contacted"
}, },
{ {
"doctype": "Lead", "doctype": "Lead",
"email_id": "test_lead3@example.com", "email_id": "test_lead3@example.com",
"lead_name": "_Test Lead 3", "lead_name": "_Test Lead 3",
"status": "Converted" "status": "Converted"
} }
] ]

View File

@@ -13,6 +13,14 @@ class Quotation(SellingController):
tname = 'Quotation Item' tname = 'Quotation Item'
fname = 'quotation_details' 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): def has_sales_order(self):
return frappe.db.get_value("Sales Order Item", {"prevdoc_docname": self.name, "docstatus": 1}) return frappe.db.get_value("Sales Order Item", {"prevdoc_docname": self.name, "docstatus": 1})
@@ -42,13 +50,6 @@ class Quotation(SellingController):
if is_sales_item == 'No': if is_sales_item == 'No':
frappe.throw(_("Item {0} must be Sales Item").format(d.item_code)) 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): def update_opportunity(self):
for opportunity in list(set([d.prevdoc_docname for d in self.get("quotation_details")])): for opportunity in list(set([d.prevdoc_docname for d in self.get("quotation_details")])):
if opportunity: if opportunity:

View File

@@ -21,3 +21,4 @@ class Territory(NestedSet):
def on_update(self): def on_update(self):
super(Territory, self).on_update() super(Territory, self).on_update()
self.validate_one_root() self.validate_one_root()

View File

@@ -1,248 +1,252 @@
[ [
{ {
"default_warehouse": "_Test Warehouse - _TC", "default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Item", "description": "_Test Item",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC", "expense_account": "_Test Account Cost for Goods Sold - _TC",
"has_batch_no": "No", "has_batch_no": "No",
"has_serial_no": "No", "has_serial_no": "No",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"inspection_required": "No", "inspection_required": "No",
"is_asset_item": "No", "is_asset_item": "No",
"is_pro_applicable": "Yes", "is_pro_applicable": "Yes",
"is_purchase_item": "Yes", "is_purchase_item": "Yes",
"is_sales_item": "Yes", "is_sales_item": "Yes",
"is_service_item": "No", "is_service_item": "No",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"is_sub_contracted_item": "No", "is_sub_contracted_item": "No",
"item_code": "_Test Item", "item_code": "_Test Item",
"item_group": "_Test Item Group", "item_group": "_Test Item Group",
"item_name": "_Test Item", "item_name": "_Test Item",
"item_reorder": [ "item_reorder": [
{ {
"doctype": "Item Reorder", "doctype": "Item Reorder",
"material_request_type": "Purchase", "material_request_type": "Purchase",
"parentfield": "item_reorder", "parentfield": "item_reorder",
"warehouse": "_Test Warehouse - _TC", "warehouse": "_Test Warehouse - _TC",
"warehouse_reorder_level": 20, "warehouse_reorder_level": 20,
"warehouse_reorder_qty": 20 "warehouse_reorder_qty": 20
} }
], ],
"selling_cost_center": "_Test Cost Center - _TC", "selling_cost_center": "_Test Cost Center - _TC",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM",
}, "show_in_website": 1,
"website_warehouse": "_Test Warehouse - _TC"
},
{ {
"default_warehouse": "_Test Warehouse - _TC", "default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Item 2", "description": "_Test Item 2",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC", "expense_account": "_Test Account Cost for Goods Sold - _TC",
"has_batch_no": "No", "has_batch_no": "No",
"has_serial_no": "No", "has_serial_no": "No",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"inspection_required": "No", "inspection_required": "No",
"is_asset_item": "No", "is_asset_item": "No",
"is_pro_applicable": "Yes", "is_pro_applicable": "Yes",
"is_purchase_item": "Yes", "is_purchase_item": "Yes",
"is_sales_item": "Yes", "is_sales_item": "Yes",
"is_service_item": "No", "is_service_item": "No",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"is_sub_contracted_item": "No", "is_sub_contracted_item": "No",
"item_code": "_Test Item 2", "item_code": "_Test Item 2",
"item_group": "_Test Item Group", "item_group": "_Test Item Group",
"item_name": "_Test Item 2", "item_name": "_Test Item 2",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM",
}, "show_in_website": 1,
"website_warehouse": "_Test Warehouse - _TC"
},
{ {
"default_warehouse": "_Test Warehouse - _TC", "default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Item Home Desktop 100", "description": "_Test Item Home Desktop 100",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC", "expense_account": "_Test Account Cost for Goods Sold - _TC",
"has_batch_no": "No", "has_batch_no": "No",
"has_serial_no": "No", "has_serial_no": "No",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"inspection_required": "No", "inspection_required": "No",
"is_asset_item": "No", "is_asset_item": "No",
"is_manufactured_item": "No", "is_manufactured_item": "No",
"is_pro_applicable": "No", "is_pro_applicable": "No",
"is_purchase_item": "Yes", "is_purchase_item": "Yes",
"is_sales_item": "Yes", "is_sales_item": "Yes",
"is_service_item": "No", "is_service_item": "No",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"is_sub_contracted_item": "No", "is_sub_contracted_item": "No",
"item_code": "_Test Item Home Desktop 100", "item_code": "_Test Item Home Desktop 100",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Item Home Desktop 100", "item_name": "_Test Item Home Desktop 100",
"item_tax": [ "item_tax": [
{ {
"doctype": "Item Tax", "doctype": "Item Tax",
"parentfield": "item_tax", "parentfield": "item_tax",
"tax_rate": 10, "tax_rate": 10,
"tax_type": "_Test Account Excise Duty - _TC" "tax_type": "_Test Account Excise Duty - _TC"
} }
], ],
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC", "default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Item Home Desktop 200", "description": "_Test Item Home Desktop 200",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC", "expense_account": "_Test Account Cost for Goods Sold - _TC",
"has_batch_no": "No", "has_batch_no": "No",
"has_serial_no": "No", "has_serial_no": "No",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"inspection_required": "No", "inspection_required": "No",
"is_asset_item": "No", "is_asset_item": "No",
"is_manufactured_item": "No", "is_manufactured_item": "No",
"is_pro_applicable": "No", "is_pro_applicable": "No",
"is_purchase_item": "Yes", "is_purchase_item": "Yes",
"is_sales_item": "Yes", "is_sales_item": "Yes",
"is_service_item": "No", "is_service_item": "No",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"is_sub_contracted_item": "No", "is_sub_contracted_item": "No",
"item_code": "_Test Item Home Desktop 200", "item_code": "_Test Item Home Desktop 200",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Item Home Desktop 200", "item_name": "_Test Item Home Desktop 200",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
}, },
{ {
"description": "_Test Sales BOM Item", "description": "_Test Sales BOM Item",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC", "expense_account": "_Test Account Cost for Goods Sold - _TC",
"has_batch_no": "No", "has_batch_no": "No",
"has_serial_no": "No", "has_serial_no": "No",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"inspection_required": "No", "inspection_required": "No",
"is_asset_item": "No", "is_asset_item": "No",
"is_pro_applicable": "No", "is_pro_applicable": "No",
"is_purchase_item": "Yes", "is_purchase_item": "Yes",
"is_sales_item": "Yes", "is_sales_item": "Yes",
"is_service_item": "No", "is_service_item": "No",
"is_stock_item": "No", "is_stock_item": "No",
"is_sub_contracted_item": "No", "is_sub_contracted_item": "No",
"item_code": "_Test Sales BOM Item", "item_code": "_Test Sales BOM Item",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Sales BOM Item", "item_name": "_Test Sales BOM Item",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC", "default_warehouse": "_Test Warehouse - _TC",
"description": "_Test FG Item", "description": "_Test FG Item",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC", "expense_account": "_Test Account Cost for Goods Sold - _TC",
"has_batch_no": "No", "has_batch_no": "No",
"has_serial_no": "No", "has_serial_no": "No",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"inspection_required": "No", "inspection_required": "No",
"is_asset_item": "No", "is_asset_item": "No",
"is_pro_applicable": "Yes", "is_pro_applicable": "Yes",
"is_purchase_item": "Yes", "is_purchase_item": "Yes",
"is_sales_item": "Yes", "is_sales_item": "Yes",
"is_service_item": "No", "is_service_item": "No",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"is_sub_contracted_item": "Yes", "is_sub_contracted_item": "Yes",
"item_code": "_Test FG Item", "item_code": "_Test FG Item",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test FG Item", "item_name": "_Test FG Item",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
}, },
{ {
"description": "_Test Non Stock Item", "description": "_Test Non Stock Item",
"doctype": "Item", "doctype": "Item",
"has_batch_no": "No", "has_batch_no": "No",
"has_serial_no": "No", "has_serial_no": "No",
"inspection_required": "No", "inspection_required": "No",
"is_asset_item": "No", "is_asset_item": "No",
"is_pro_applicable": "No", "is_pro_applicable": "No",
"is_purchase_item": "Yes", "is_purchase_item": "Yes",
"is_sales_item": "Yes", "is_sales_item": "Yes",
"is_service_item": "No", "is_service_item": "No",
"is_stock_item": "No", "is_stock_item": "No",
"is_sub_contracted_item": "No", "is_sub_contracted_item": "No",
"item_code": "_Test Non Stock Item", "item_code": "_Test Non Stock Item",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Non Stock Item", "item_name": "_Test Non Stock Item",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC", "default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Serialized Item", "description": "_Test Serialized Item",
"doctype": "Item", "doctype": "Item",
"has_batch_no": "No", "has_batch_no": "No",
"has_serial_no": "Yes", "has_serial_no": "Yes",
"inspection_required": "No", "inspection_required": "No",
"is_asset_item": "No", "is_asset_item": "No",
"is_pro_applicable": "No", "is_pro_applicable": "No",
"is_purchase_item": "Yes", "is_purchase_item": "Yes",
"is_sales_item": "Yes", "is_sales_item": "Yes",
"is_service_item": "No", "is_service_item": "No",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"is_sub_contracted_item": "No", "is_sub_contracted_item": "No",
"item_code": "_Test Serialized Item", "item_code": "_Test Serialized Item",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Serialized Item", "item_name": "_Test Serialized Item",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC", "default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Serialized Item", "description": "_Test Serialized Item",
"doctype": "Item", "doctype": "Item",
"has_batch_no": "No", "has_batch_no": "No",
"has_serial_no": "Yes", "has_serial_no": "Yes",
"inspection_required": "No", "inspection_required": "No",
"is_asset_item": "No", "is_asset_item": "No",
"is_pro_applicable": "Yes", "is_pro_applicable": "Yes",
"is_purchase_item": "Yes", "is_purchase_item": "Yes",
"is_sales_item": "Yes", "is_sales_item": "Yes",
"is_service_item": "No", "is_service_item": "No",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"is_sub_contracted_item": "No", "is_sub_contracted_item": "No",
"item_code": "_Test Serialized Item With Series", "item_code": "_Test Serialized Item With Series",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Serialized Item With Series", "item_name": "_Test Serialized Item With Series",
"serial_no_series": "ABCD.#####", "serial_no_series": "ABCD.#####",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC", "default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Item Home Desktop Manufactured", "description": "_Test Item Home Desktop Manufactured",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC", "expense_account": "_Test Account Cost for Goods Sold - _TC",
"has_batch_no": "No", "has_batch_no": "No",
"has_serial_no": "No", "has_serial_no": "No",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"inspection_required": "No", "inspection_required": "No",
"is_asset_item": "No", "is_asset_item": "No",
"is_manufactured_item": "Yes", "is_manufactured_item": "Yes",
"is_pro_applicable": "Yes", "is_pro_applicable": "Yes",
"is_purchase_item": "Yes", "is_purchase_item": "Yes",
"is_sales_item": "Yes", "is_sales_item": "Yes",
"is_service_item": "No", "is_service_item": "No",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"is_sub_contracted_item": "No", "is_sub_contracted_item": "No",
"item_code": "_Test Item Home Desktop Manufactured", "item_code": "_Test Item Home Desktop Manufactured",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Item Home Desktop Manufactured", "item_name": "_Test Item Home Desktop Manufactured",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC", "default_warehouse": "_Test Warehouse - _TC",
"description": "_Test FG Item 2", "description": "_Test FG Item 2",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC", "expense_account": "_Test Account Cost for Goods Sold - _TC",
"has_batch_no": "No", "has_batch_no": "No",
"has_serial_no": "No", "has_serial_no": "No",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"inspection_required": "No", "inspection_required": "No",
"is_asset_item": "No", "is_asset_item": "No",
"is_pro_applicable": "Yes", "is_pro_applicable": "Yes",
"is_purchase_item": "Yes", "is_purchase_item": "Yes",
"is_sales_item": "Yes", "is_sales_item": "Yes",
"is_service_item": "No", "is_service_item": "No",
"is_stock_item": "Yes", "is_stock_item": "Yes",
"is_sub_contracted_item": "Yes", "is_sub_contracted_item": "Yes",
"item_code": "_Test FG Item 2", "item_code": "_Test FG Item 2",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test FG Item 2", "item_name": "_Test FG Item 2",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
} }
] ]

View File

@@ -1,8 +1,20 @@
[ [
{ {
"doctype": "Item Price", "doctype": "Item Price",
"item_code": "_Test Item", "item_code": "_Test Item",
"price_list": "_Test Price List", "price_list": "_Test Price List",
"price_list_rate": 100 "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
} }
] ]

View File

@@ -73,3 +73,18 @@ def get_address_display(address_dict):
return display.strip() 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