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