commit
5536923101
@ -98,7 +98,7 @@ class GrossProfitGenerator(object):
|
||||
|
||||
row.base_amount = flt(row.base_net_amount)
|
||||
|
||||
sales_boms = self.sales_boms.get(row.parenttype, {}).get(row.name, frappe._dict())
|
||||
sales_boms = self.sales_boms.get(row.parenttype, {}).get(row.parent, frappe._dict())
|
||||
|
||||
# get buying amount
|
||||
if row.item_code in sales_boms:
|
||||
@ -158,7 +158,7 @@ class GrossProfitGenerator(object):
|
||||
|
||||
def get_buying_amount_from_sales_bom(self, row, sales_bom):
|
||||
buying_amount = 0.0
|
||||
for bom_item in sales_bom[row.item_code]:
|
||||
for bom_item in sales_bom:
|
||||
if bom_item.get("parent_detail_docname")==row.item_row:
|
||||
buying_amount += self.get_buying_amount(row, bom_item.item_code)
|
||||
|
||||
@ -174,14 +174,17 @@ class GrossProfitGenerator(object):
|
||||
return flt(row.qty) * item_rate
|
||||
|
||||
else:
|
||||
if row.dn_detail:
|
||||
row.parenttype = "Delivery Note"
|
||||
row.parent = row.delivery_note
|
||||
row.item_row = row.dn_detail
|
||||
if row.update_stock or row.dn_detail:
|
||||
if row.dn_detail:
|
||||
row.parenttype = "Delivery Note"
|
||||
row.parent = row.delivery_note
|
||||
row.item_row = row.dn_detail
|
||||
|
||||
my_sle = self.sle.get((item_code, row.warehouse))
|
||||
for i, sle in enumerate(my_sle):
|
||||
# find the stock valution rate from stock ledger entry
|
||||
print sle.voucher_type, row.parenttype, sle.voucher_no, row.parent, \
|
||||
sle.voucher_detail_no, row.item_row
|
||||
if sle.voucher_type == row.parenttype and row.parent == sle.voucher_no and \
|
||||
sle.voucher_detail_no == row.item_row:
|
||||
previous_stock_value = len(my_sle) > i+1 and \
|
||||
@ -215,7 +218,7 @@ class GrossProfitGenerator(object):
|
||||
if self.filters.to_date:
|
||||
conditions += " and posting_date <= %(to_date)s"
|
||||
|
||||
self.si_list = frappe.db.sql("""select item.parenttype, si.name,
|
||||
self.si_list = frappe.db.sql("""select item.parenttype, item.parent,
|
||||
si.posting_date, si.posting_time, si.project_name, si.update_stock,
|
||||
si.customer, si.customer_group, si.territory,
|
||||
item.item_code, item.item_name, item.description, item.warehouse,
|
||||
|
@ -36,6 +36,15 @@
|
||||
"options": "Supplier",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.send_to=='All Sales Partner Contact'",
|
||||
"fieldname": "sales_partner",
|
||||
"fieldtype": "Link",
|
||||
"label": "Sales Partner",
|
||||
"options": "Sales Partner",
|
||||
"permlevel": 0,
|
||||
"precision": ""
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.send_to=='All Employee (Active)'",
|
||||
"fieldname": "department",
|
||||
@ -108,7 +117,7 @@
|
||||
"idx": 1,
|
||||
"in_create": 0,
|
||||
"issingle": 1,
|
||||
"modified": "2015-02-05 05:11:46.773913",
|
||||
"modified": "2015-05-25 17:46:37.555503",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Selling",
|
||||
"name": "SMS Center",
|
||||
|
@ -34,7 +34,7 @@ def get_columns(filters):
|
||||
|
||||
def get_entries(filters):
|
||||
date_field = filters["doc_type"] == "Sales Order" and "transaction_date" or "posting_date"
|
||||
conditions, items = get_conditions(filters, date_field)
|
||||
conditions, values = get_conditions(filters, date_field)
|
||||
entries = frappe.db.sql("""select dt.name, dt.customer, dt.territory, dt.%s as posting_date,
|
||||
dt_item.item_code, dt_item.qty, dt_item.base_net_amount, st.sales_person,
|
||||
st.allocated_percentage, dt_item.base_net_amount*st.allocated_percentage/100 as contribution_amt
|
||||
@ -42,31 +42,33 @@ def get_entries(filters):
|
||||
where st.parent = dt.name and dt.name = dt_item.parent and st.parenttype = %s
|
||||
and dt.docstatus = 1 %s order by st.sales_person, dt.name desc""" %
|
||||
(date_field, filters["doc_type"], filters["doc_type"], '%s', conditions),
|
||||
tuple([filters["doc_type"]] + items), as_dict=1)
|
||||
tuple([filters["doc_type"]] + values), as_dict=1)
|
||||
|
||||
return entries
|
||||
|
||||
def get_conditions(filters, date_field):
|
||||
conditions = ""
|
||||
if filters.get("company"): conditions += " and dt.company = '%s'" % \
|
||||
filters["company"].replace("'", "\'")
|
||||
if filters.get("customer"): conditions += " and dt.customer = '%s'" % \
|
||||
filters["customer"].replace("'", "\'")
|
||||
if filters.get("territory"): conditions += " and dt.territory = '%s'" % \
|
||||
filters["territory"].replace("'", "\'")
|
||||
|
||||
if filters.get("from_date"): conditions += " and dt.%s >= '%s'" % \
|
||||
(date_field, filters["from_date"])
|
||||
if filters.get("to_date"): conditions += " and dt.%s <= '%s'" % (date_field, filters["to_date"])
|
||||
|
||||
if filters.get("sales_person"): conditions += " and st.sales_person = '%s'" % \
|
||||
filters["sales_person"].replace("'", "\'")
|
||||
conditions = [""]
|
||||
values = []
|
||||
|
||||
for field in ["company", "customer", "territory", "sales_person"]:
|
||||
if filters.get(field):
|
||||
conditions.append("dt.{0}=%s".format(field))
|
||||
values.append(filters[field])
|
||||
|
||||
if filters.get("from_date"):
|
||||
conditions.append("dt.{0}>=%s".format(date_field))
|
||||
values.append(filters["from_date"])
|
||||
|
||||
if filters.get("to_date"):
|
||||
conditions.append("dt.{0}<=%s".format(date_field))
|
||||
values.append(filters["to_date"])
|
||||
|
||||
items = get_items(filters)
|
||||
if items:
|
||||
conditions += " and dt_item.item_code in (%s)" % ', '.join(['%s']*len(items))
|
||||
conditions.append("dt_item.item_code in (%s)" % ', '.join(['%s']*len(items)))
|
||||
values += items
|
||||
|
||||
return conditions, items
|
||||
return " and ".join(conditions), values
|
||||
|
||||
def get_items(filters):
|
||||
if filters.get("item_group"): key = "item_group"
|
||||
|
@ -27,8 +27,12 @@ class Company(Document):
|
||||
return exists
|
||||
|
||||
def validate(self):
|
||||
self.abbr = self.abbr.strip()
|
||||
if self.get('__islocal') and len(self.abbr) > 5:
|
||||
frappe.throw(_("Abbreviation cannot have more than 5 characters"))
|
||||
|
||||
if not self.abbr.strip():
|
||||
frappe.throw(_("Abbr can not be blank or space"))
|
||||
|
||||
self.previous_default_currency = frappe.db.get_value("Company", self.name, "default_currency")
|
||||
if self.default_currency and self.previous_default_currency and \
|
||||
@ -174,6 +178,10 @@ class Company(Document):
|
||||
"""
|
||||
Trash accounts and cost centers for this company if no gl entry exists
|
||||
"""
|
||||
accounts = frappe.db.sql_list("select name from tabAccount where company=%s", self.name)
|
||||
cost_centers = frappe.db.sql_list("select name from `tabCost Center` where company=%s", self.name)
|
||||
warehouses = frappe.db.sql_list("select name from tabWarehouse where company=%s", self.name)
|
||||
|
||||
rec = frappe.db.sql("SELECT name from `tabGL Entry` where company = %s", self.name)
|
||||
if not rec:
|
||||
# delete Account
|
||||
@ -192,23 +200,43 @@ class Company(Document):
|
||||
frappe.db.sql("""delete from `tabWarehouse` where company=%s""", self.name)
|
||||
|
||||
frappe.defaults.clear_default("company", value=self.name)
|
||||
|
||||
# clear default accounts, warehouses from item
|
||||
for f in ["default_warehouse", "website_warehouse"]:
|
||||
frappe.db.sql("""update tabItem set %s=NULL where %s in (%s)"""
|
||||
% (f, f, ', '.join(['%s']*len(warehouses))), tuple(warehouses))
|
||||
|
||||
frappe.db.sql("""delete from `tabItem Reorder` where warehouse in (%s)"""
|
||||
% ', '.join(['%s']*len(warehouses)), tuple(warehouses))
|
||||
|
||||
for f in ["income_account", "expense_account"]:
|
||||
frappe.db.sql("""update tabItem set %s=NULL where %s in (%s)"""
|
||||
% (f, f, ', '.join(['%s']*len(accounts))), tuple(accounts))
|
||||
|
||||
for f in ["selling_cost_center", "buying_cost_center"]:
|
||||
frappe.db.sql("""update tabItem set %s=NULL where %s in (%s)"""
|
||||
% (f, f, ', '.join(['%s']*len(cost_centers))), tuple(cost_centers))
|
||||
|
||||
# reset default company
|
||||
frappe.db.sql("""update `tabSingles` set value=""
|
||||
where doctype='Global Defaults' and field='default_company'
|
||||
and value=%s""", self.name)
|
||||
|
||||
@frappe.whitelist()
|
||||
def replace_abbr(company, old, new):
|
||||
new = new.strip()
|
||||
if not new:
|
||||
frappe.throw(_("Abbr can not be blank or space"))
|
||||
|
||||
frappe.only_for("System Manager")
|
||||
|
||||
frappe.db.set_value("Company", company, "abbr", new)
|
||||
|
||||
def _rename_record(dt):
|
||||
for d in frappe.db.sql("select name from `tab%s` where company=%s" % (dt, '%s'), company):
|
||||
parts = d[0].split(" - ")
|
||||
if parts[-1].lower() == old.lower():
|
||||
name_without_abbr = " - ".join(parts[:-1])
|
||||
frappe.rename_doc(dt, d[0], name_without_abbr + " - " + new)
|
||||
parts = d[0].rsplit(" - ", 1)
|
||||
if len(parts) == 1 or parts[1].lower() == old.lower():
|
||||
frappe.rename_doc(dt, d[0], parts[0] + " - " + new)
|
||||
|
||||
for dt in ["Account", "Cost Center", "Warehouse"]:
|
||||
_rename_record(dt)
|
||||
|
@ -29,5 +29,7 @@ class SalesPerson(NestedSet):
|
||||
return frappe.db.get_value("User", user, "email") or user
|
||||
|
||||
def validate_employee_id(self):
|
||||
if frappe.db.exists({"doctype": "Sales Person","employee": self.employee}):
|
||||
frappe.throw("Another sales person with the same employee id exists.", frappe.DuplicateEntryError)
|
||||
sales_person = frappe.db.get_value("Sales Person", {"employee": self.employee})
|
||||
|
||||
if sales_person and sales_person != self.name:
|
||||
frappe.throw(_("Another Sales Person {0} exists with the same Employee id").format(sales_person))
|
||||
|
@ -110,7 +110,8 @@ class DeliveryNote(SellingController):
|
||||
def validate_with_previous_doc(self):
|
||||
items = self.get("items")
|
||||
|
||||
for fn in (("Sales Order", "against_sales_order"), ("Sales Invoice", "against_sales_invoice")):
|
||||
for fn in (("Sales Order", "against_sales_order", "so_detail"),
|
||||
("Sales Invoice", "against_sales_invoice", "si_detail")):
|
||||
if filter(None, [getattr(d, fn[1], None) for d in items]):
|
||||
super(DeliveryNote, self).validate_with_previous_doc({
|
||||
fn[0]: {
|
||||
@ -123,7 +124,7 @@ class DeliveryNote(SellingController):
|
||||
if cint(frappe.defaults.get_global_default('maintain_same_sales_rate')):
|
||||
super(DeliveryNote, self).validate_with_previous_doc({
|
||||
fn[0] + " Item": {
|
||||
"ref_dn_field": "so_detail",
|
||||
"ref_dn_field": fn[2],
|
||||
"compare_fields": [["rate", "="]],
|
||||
"is_child_table": True
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user