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

@@ -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

@@ -4,7 +4,7 @@
"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",

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

@@ -29,7 +29,9 @@
} }
], ],
"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",
@@ -50,7 +52,9 @@
"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",

View File

@@ -4,5 +4,17 @@
"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