Fixes for model-cleanup frappe/frappe#478
This commit is contained in:
parent
f7daab7393
commit
13ae548ff6
@ -11,15 +11,15 @@ from erpnext.utilities.doctype.address.address import get_address_display
|
||||
from erpnext.utilities.doctype.contact.contact import get_contact_details
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_party_details(party=None, account=None, party_type="Customer", company=None,
|
||||
def get_party_details(party=None, account=None, party_type="Customer", company=None,
|
||||
posting_date=None, price_list=None, currency=None):
|
||||
|
||||
return _get_party_details(party, account, party_type, company, posting_date, price_list, currency)
|
||||
|
||||
def _get_party_details(party=None, account=None, party_type="Customer", company=None,
|
||||
def _get_party_details(party=None, account=None, party_type="Customer", company=None,
|
||||
posting_date=None, price_list=None, currency=None, ignore_permissions=False):
|
||||
out = frappe._dict(set_account_and_due_date(party, account, party_type, company, posting_date))
|
||||
|
||||
|
||||
party = out[party_type.lower()]
|
||||
|
||||
if not ignore_permissions and not frappe.has_permission(party_type, "read", party):
|
||||
@ -31,38 +31,41 @@ def _get_party_details(party=None, account=None, party_type="Customer", company=
|
||||
set_contact_details(out, party, party_type)
|
||||
set_other_values(out, party, party_type)
|
||||
set_price_list(out, party, party_type, price_list)
|
||||
|
||||
|
||||
if not out.get("currency"):
|
||||
out["currency"] = currency
|
||||
|
||||
|
||||
# sales team
|
||||
if party_type=="Customer":
|
||||
out["sales_team"] = [{
|
||||
"sales_person": d.sales_person,
|
||||
"sales_person": d.sales_person,
|
||||
"sales_designation": d.sales_designation
|
||||
} for d in party.get("sales_team")]
|
||||
|
||||
|
||||
return out
|
||||
|
||||
def set_address_details(out, party, party_type):
|
||||
billing_address_field = "customer_address" if party_type == "Lead" \
|
||||
else party_type.lower() + "_address"
|
||||
out[billing_address_field] = frappe.db.get_value("Address",
|
||||
out[billing_address_field] = frappe.db.get_value("Address",
|
||||
{party_type.lower(): party.name, "is_primary_address":1}, "name")
|
||||
|
||||
|
||||
# address display
|
||||
out.address_display = get_address_display(out[billing_address_field])
|
||||
|
||||
|
||||
# shipping address
|
||||
if party_type in ["Customer", "Lead"]:
|
||||
out.shipping_address_name = frappe.db.get_value("Address",
|
||||
out.shipping_address_name = frappe.db.get_value("Address",
|
||||
{party_type.lower(): party.name, "is_shipping_address":1}, "name")
|
||||
out.shipping_address = get_address_display(out["shipping_address_name"])
|
||||
|
||||
|
||||
def set_contact_details(out, party, party_type):
|
||||
out.contact_person = frappe.db.get_value("Contact",
|
||||
out.contact_person = frappe.db.get_value("Contact",
|
||||
{party_type.lower(): party.name, "is_primary_contact":1}, "name")
|
||||
|
||||
|
||||
if not out.contact_person:
|
||||
return
|
||||
|
||||
out.update(get_contact_details(out.contact_person))
|
||||
|
||||
def set_other_values(out, party, party_type):
|
||||
@ -73,7 +76,7 @@ def set_other_values(out, party, party_type):
|
||||
to_copy = ["supplier_name", "supplier_type"]
|
||||
for f in to_copy:
|
||||
out[f] = party.get(f)
|
||||
|
||||
|
||||
# fields prepended with default in Customer doctype
|
||||
for f in ['currency', 'taxes_and_charges'] \
|
||||
+ (['sales_partner', 'commission_rate'] if party_type=="Customer" else []):
|
||||
@ -81,16 +84,16 @@ def set_other_values(out, party, party_type):
|
||||
out[f] = party.get("default_" + f)
|
||||
|
||||
def set_price_list(out, party, party_type, given_price_list):
|
||||
# price list
|
||||
# price list
|
||||
price_list = get_restrictions().get("Price List")
|
||||
if isinstance(price_list, list):
|
||||
price_list = None
|
||||
|
||||
if not price_list:
|
||||
price_list = party.default_price_list
|
||||
|
||||
|
||||
if not price_list and party_type=="Customer":
|
||||
price_list = frappe.db.get_value("Customer Group",
|
||||
price_list = frappe.db.get_value("Customer Group",
|
||||
party.customer_group, "default_price_list")
|
||||
|
||||
if not price_list:
|
||||
@ -98,9 +101,9 @@ def set_price_list(out, party, party_type, given_price_list):
|
||||
|
||||
if price_list:
|
||||
out.price_list_currency = frappe.db.get_value("Price List", price_list, "currency")
|
||||
|
||||
|
||||
out["selling_price_list" if party.doctype=="Customer" else "buying_price_list"] = price_list
|
||||
|
||||
|
||||
|
||||
def set_account_and_due_date(party, account, party_type, company, posting_date):
|
||||
if not posting_date:
|
||||
@ -108,13 +111,13 @@ def set_account_and_due_date(party, account, party_type, company, posting_date):
|
||||
return {
|
||||
party_type.lower(): party
|
||||
}
|
||||
|
||||
|
||||
if party:
|
||||
account = get_party_account(company, party, party_type)
|
||||
elif account:
|
||||
party = frappe.db.get_value('Account', account, 'master_name')
|
||||
|
||||
account_fieldname = "debit_to" if party_type=="Customer" else "credit_to"
|
||||
account_fieldname = "debit_to" if party_type=="Customer" else "credit_to"
|
||||
|
||||
out = {
|
||||
party_type.lower(): party,
|
||||
@ -133,8 +136,8 @@ def get_party_account(company, party, party_type):
|
||||
|
||||
if not acc_head:
|
||||
create_party_account(party, party_type, company)
|
||||
|
||||
return acc_head
|
||||
|
||||
return acc_head
|
||||
|
||||
def get_due_date(posting_date, party, party_type, account, company):
|
||||
"""Set Due Date = Posting Date + Credit Days"""
|
||||
@ -147,34 +150,34 @@ def get_due_date(posting_date, party, party_type, account, company):
|
||||
credit_days = frappe.db.get_value(party_type, party, "credit_days")
|
||||
if company and not credit_days:
|
||||
credit_days = frappe.db.get_value("Company", company, "credit_days")
|
||||
|
||||
|
||||
due_date = add_days(posting_date, credit_days) if credit_days else posting_date
|
||||
|
||||
return due_date
|
||||
return due_date
|
||||
|
||||
def create_party_account(party, party_type, company):
|
||||
if not company:
|
||||
frappe.throw(_("Company is required"))
|
||||
|
||||
company_details = frappe.db.get_value("Company", company,
|
||||
|
||||
company_details = frappe.db.get_value("Company", company,
|
||||
["abbr", "receivables_group", "payables_group"], as_dict=True)
|
||||
if not frappe.db.exists("Account", (party + " - " + company_details.abbr)):
|
||||
parent_account = company_details.receivables_group \
|
||||
if party_type=="Customer" else company_details.payables_group
|
||||
if not parent_account:
|
||||
frappe.throw(_("Please enter Account Receivable/Payable group in company master"))
|
||||
|
||||
|
||||
# create
|
||||
account = frappe.get_doc({
|
||||
"doctype": "Account",
|
||||
'account_name': party,
|
||||
'parent_account': parent_account,
|
||||
'parent_account': parent_account,
|
||||
'group_or_ledger':'Ledger',
|
||||
'company': company,
|
||||
'master_type': party_type,
|
||||
'company': company,
|
||||
'master_type': party_type,
|
||||
'master_name': party,
|
||||
"freeze_account": "No",
|
||||
"report_type": "Balance Sheet"
|
||||
}).insert(ignore_permissions=True)
|
||||
|
||||
|
||||
frappe.msgprint(_("Account Created") + ": " + account.name)
|
||||
|
@ -1,75 +1,75 @@
|
||||
{
|
||||
"creation": "2013-06-25 11:04:03.000000",
|
||||
"description": "Settings for Buying Module",
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "Other",
|
||||
"creation": "2013-06-25 11:04:03.000000",
|
||||
"description": "Settings for Buying Module",
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "Other",
|
||||
"fields": [
|
||||
{
|
||||
"default": "Supplier Name",
|
||||
"fieldname": "supp_master_name",
|
||||
"fieldtype": "Select",
|
||||
"label": "Supplier Naming By",
|
||||
"options": "Supplier Name\nNaming Series",
|
||||
"default": "Supplier Name",
|
||||
"fieldname": "supp_master_name",
|
||||
"fieldtype": "Select",
|
||||
"label": "Supplier Naming By",
|
||||
"options": "Supplier Name\nNaming Series",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"fieldname": "supplier_type",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Supplier Type",
|
||||
"options": "Supplier Type",
|
||||
"fieldname": "supplier_type",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Supplier Type",
|
||||
"options": "Supplier Type",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"fieldname": "buying_price_list",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Buying Price List",
|
||||
"options": "Price List",
|
||||
"fieldname": "buying_price_list",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Buying Price List",
|
||||
"options": "Price List",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break",
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"fieldname": "maintain_same_rate",
|
||||
"fieldtype": "Check",
|
||||
"label": "Maintain same rate throughout purchase cycle",
|
||||
"fieldname": "maintain_same_rate",
|
||||
"fieldtype": "Check",
|
||||
"label": "Maintain same rate throughout purchase cycle",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"fieldname": "po_required",
|
||||
"fieldtype": "Select",
|
||||
"label": "Purchase Order Required",
|
||||
"options": "No\nYes",
|
||||
"fieldname": "po_required",
|
||||
"fieldtype": "Select",
|
||||
"label": "Purchase Order Required",
|
||||
"options": "No\nYes",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"fieldname": "pr_required",
|
||||
"fieldtype": "Select",
|
||||
"label": "Purchase Receipt Required",
|
||||
"options": "No\nYes",
|
||||
"fieldname": "pr_required",
|
||||
"fieldtype": "Select",
|
||||
"label": "Purchase Receipt Required",
|
||||
"options": "No\nYes",
|
||||
"permlevel": 0
|
||||
}
|
||||
],
|
||||
"icon": "icon-cog",
|
||||
"idx": 1,
|
||||
"issingle": 1,
|
||||
"modified": "2014-02-19 19:02:00.000000",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Buying Settings",
|
||||
"owner": "Administrator",
|
||||
],
|
||||
"icon": "icon-cog",
|
||||
"idx": 1,
|
||||
"issingle": 1,
|
||||
"modified": "2014-02-19 19:02:00.000000",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Buying Settings",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"email": 1,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"role": "System Manager",
|
||||
"create": 1,
|
||||
"email": 1,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"role": "System Manager",
|
||||
"write": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -24,15 +24,15 @@ class Supplier(TransactionBase):
|
||||
self.name = make_autoname(self.naming_series + '.#####')
|
||||
|
||||
def update_address(self):
|
||||
frappe.db.sql("""update `tabAddress` set supplier_name=%s, modified=NOW()
|
||||
frappe.db.sql("""update `tabAddress` set supplier_name=%s, modified=NOW()
|
||||
where supplier=%s""", (self.supplier_name, self.name))
|
||||
|
||||
def update_contact(self):
|
||||
frappe.db.sql("""update `tabContact` set supplier_name=%s, modified=NOW()
|
||||
frappe.db.sql("""update `tabContact` set supplier_name=%s, modified=NOW()
|
||||
where supplier=%s""", (self.supplier_name, self.name))
|
||||
|
||||
def update_credit_days_limit(self):
|
||||
frappe.db.sql("""update tabAccount set credit_days = %s where name = %s""",
|
||||
frappe.db.sql("""update tabAccount set credit_days = %s where name = %s""",
|
||||
(cint(self.credit_days), self.name + " - " + self.get_company_abbr()))
|
||||
|
||||
def on_update(self):
|
||||
@ -47,45 +47,45 @@ class Supplier(TransactionBase):
|
||||
|
||||
# update credit days and limit in account
|
||||
self.update_credit_days_limit()
|
||||
|
||||
|
||||
def get_company_abbr(self):
|
||||
return frappe.db.sql("select abbr from tabCompany where name=%s", self.company)[0][0]
|
||||
|
||||
|
||||
def validate(self):
|
||||
#validation for Naming Series mandatory field...
|
||||
if frappe.defaults.get_global_default('supp_master_name') == 'Naming Series':
|
||||
if not self.naming_series:
|
||||
msgprint("Series is Mandatory.", raise_exception=1)
|
||||
|
||||
|
||||
def get_contacts(self,nm):
|
||||
if nm:
|
||||
contact_details =frappe.db.convert_to_lists(frappe.db.sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = %s", nm))
|
||||
|
||||
|
||||
return contact_details
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def delete_supplier_address(self):
|
||||
for rec in frappe.db.sql("select * from `tabAddress` where supplier=%s", (self.name,), as_dict=1):
|
||||
frappe.db.sql("delete from `tabAddress` where name=%s",(rec['name']))
|
||||
|
||||
|
||||
def delete_supplier_contact(self):
|
||||
for contact in frappe.db.sql_list("""select name from `tabContact`
|
||||
for contact in frappe.db.sql_list("""select name from `tabContact`
|
||||
where supplier=%s""", self.name):
|
||||
frappe.delete_doc("Contact", contact)
|
||||
|
||||
|
||||
def delete_supplier_account(self):
|
||||
"""delete supplier's ledger if exist and check balance before deletion"""
|
||||
acc = frappe.db.sql("select name from `tabAccount` where master_type = 'Supplier' \
|
||||
and master_name = %s and docstatus < 2", self.name)
|
||||
if acc:
|
||||
frappe.delete_doc('Account', acc[0][0])
|
||||
|
||||
|
||||
def on_trash(self):
|
||||
self.delete_supplier_address()
|
||||
self.delete_supplier_contact()
|
||||
self.delete_supplier_account()
|
||||
|
||||
|
||||
def before_rename(self, olddn, newdn, merge=False):
|
||||
from erpnext.accounts.utils import rename_account_for
|
||||
rename_account_for("Supplier", olddn, newdn, merge, self.company)
|
||||
@ -99,7 +99,7 @@ class Supplier(TransactionBase):
|
||||
self.update_supplier_address(newdn, set_field)
|
||||
|
||||
def update_supplier_address(self, newdn, set_field):
|
||||
frappe.db.sql("""update `tabAddress` set address_title=%(newdn)s
|
||||
frappe.db.sql("""update `tabAddress` set address_title=%(newdn)s
|
||||
{set_field} where supplier=%(newdn)s"""\
|
||||
.format(set_field=set_field), ({"newdn": newdn}))
|
||||
|
||||
@ -107,19 +107,19 @@ class Supplier(TransactionBase):
|
||||
def get_dashboard_info(supplier):
|
||||
if not frappe.has_permission("Supplier", "read", supplier):
|
||||
frappe.msgprint("No Permission", raise_exception=True)
|
||||
|
||||
|
||||
out = {}
|
||||
for doctype in ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"]:
|
||||
out[doctype] = frappe.db.get_value(doctype,
|
||||
out[doctype] = frappe.db.get_value(doctype,
|
||||
{"supplier": supplier, "docstatus": ["!=", 2] }, "count(*)")
|
||||
|
||||
billing = frappe.db.sql("""select sum(grand_total), sum(outstanding_amount)
|
||||
from `tabPurchase Invoice`
|
||||
where supplier=%s
|
||||
|
||||
billing = frappe.db.sql("""select sum(grand_total), sum(outstanding_amount)
|
||||
from `tabPurchase Invoice`
|
||||
where supplier=%s
|
||||
and docstatus = 1
|
||||
and fiscal_year = %s""", (supplier, frappe.db.get_default("fiscal_year")))
|
||||
|
||||
|
||||
out["total_billing"] = billing[0][0]
|
||||
out["total_unpaid"] = billing[0][1]
|
||||
|
||||
return out
|
||||
|
||||
return out
|
||||
|
@ -1,90 +1,90 @@
|
||||
{
|
||||
"creation": "2013-06-25 10:25:16.000000",
|
||||
"description": "Settings for Selling Module",
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "Other",
|
||||
"creation": "2013-06-25 10:25:16.000000",
|
||||
"description": "Settings for Selling Module",
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "Other",
|
||||
"fields": [
|
||||
{
|
||||
"default": "Customer Name",
|
||||
"fieldname": "cust_master_name",
|
||||
"fieldtype": "Select",
|
||||
"label": "Customer Naming By",
|
||||
"options": "Customer Name\nNaming Series",
|
||||
"default": "Customer Name",
|
||||
"fieldname": "cust_master_name",
|
||||
"fieldtype": "Select",
|
||||
"label": "Customer Naming By",
|
||||
"options": "Customer Name\nNaming Series",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"description": "<a href=\"#Sales Browser/Customer Group\">Add / Edit</a>",
|
||||
"fieldname": "customer_group",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Customer Group",
|
||||
"options": "Customer Group",
|
||||
"description": "<a href=\"#Sales Browser/Customer Group\">Add / Edit</a>",
|
||||
"fieldname": "customer_group",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Customer Group",
|
||||
"options": "Customer Group",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"description": "<a href=\"#Sales Browser/Territory\">Add / Edit</a>",
|
||||
"fieldname": "territory",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Territory",
|
||||
"options": "Territory",
|
||||
"description": "<a href=\"#Sales Browser/Territory\">Add / Edit</a>",
|
||||
"fieldname": "territory",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Territory",
|
||||
"options": "Territory",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"fieldname": "selling_price_list",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Price List",
|
||||
"options": "Price List",
|
||||
"fieldname": "selling_price_list",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Price List",
|
||||
"options": "Price List",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_5",
|
||||
"fieldtype": "Column Break",
|
||||
"fieldname": "column_break_5",
|
||||
"fieldtype": "Column Break",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"fieldname": "so_required",
|
||||
"fieldtype": "Select",
|
||||
"label": "Sales Order Required",
|
||||
"options": "No\nYes",
|
||||
"fieldname": "so_required",
|
||||
"fieldtype": "Select",
|
||||
"label": "Sales Order Required",
|
||||
"options": "No\nYes",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"fieldname": "dn_required",
|
||||
"fieldtype": "Select",
|
||||
"label": "Delivery Note Required",
|
||||
"options": "No\nYes",
|
||||
"fieldname": "dn_required",
|
||||
"fieldtype": "Select",
|
||||
"label": "Delivery Note Required",
|
||||
"options": "No\nYes",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"fieldname": "maintain_same_sales_rate",
|
||||
"fieldtype": "Check",
|
||||
"label": "Maintain Same Rate Throughout Sales Cycle",
|
||||
"fieldname": "maintain_same_sales_rate",
|
||||
"fieldtype": "Check",
|
||||
"label": "Maintain Same Rate Throughout Sales Cycle",
|
||||
"permlevel": 0
|
||||
},
|
||||
},
|
||||
{
|
||||
"fieldname": "editable_price_list_rate",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow user to edit Price List Rate in transactions",
|
||||
"fieldname": "editable_price_list_rate",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow user to edit Price List Rate in transactions",
|
||||
"permlevel": 0
|
||||
}
|
||||
],
|
||||
"icon": "icon-cog",
|
||||
"idx": 1,
|
||||
"issingle": 1,
|
||||
"modified": "2014-02-19 18:35:36.000000",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Selling",
|
||||
"name": "Selling Settings",
|
||||
"owner": "Administrator",
|
||||
],
|
||||
"icon": "icon-cog",
|
||||
"idx": 1,
|
||||
"issingle": 1,
|
||||
"modified": "2014-02-19 18:35:36.000000",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Selling",
|
||||
"name": "Selling Settings",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"email": 1,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"role": "System Manager",
|
||||
"create": 1,
|
||||
"email": 1,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"role": "System Manager",
|
||||
"write": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ def after_install():
|
||||
def import_country_and_currency():
|
||||
from frappe.country_info import get_all
|
||||
data = get_all()
|
||||
|
||||
|
||||
for name in data:
|
||||
country = frappe._dict(data[name])
|
||||
if not frappe.db.exists("Country", name):
|
||||
@ -31,7 +31,7 @@ def import_country_and_currency():
|
||||
"date_format": country.date_format or "dd-mm-yyyy",
|
||||
"time_zones": "\n".join(country.timezones or [])
|
||||
}).insert()
|
||||
|
||||
|
||||
if country.currency and not frappe.db.exists("Currency", country.currency):
|
||||
frappe.get_doc({
|
||||
"doctype": "Currency",
|
||||
@ -44,6 +44,9 @@ def import_country_and_currency():
|
||||
|
||||
def import_defaults():
|
||||
records = [
|
||||
# role
|
||||
{'doctype': "Role", "role_name": "Analytics"},
|
||||
|
||||
# item group
|
||||
{'doctype': 'Item Group', 'item_group_name': 'All Item Groups', 'is_group': 'Yes', 'parent_item_group': ''},
|
||||
{'doctype': 'Item Group', 'item_group_name': 'Products', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
|
||||
@ -51,40 +54,40 @@ def import_defaults():
|
||||
{'doctype': 'Item Group', 'item_group_name': 'Services', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
|
||||
{'doctype': 'Item Group', 'item_group_name': 'Sub Assemblies', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
|
||||
{'doctype': 'Item Group', 'item_group_name': 'Consumable', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
|
||||
|
||||
|
||||
# deduction type
|
||||
{'doctype': 'Deduction Type', 'name': 'Income Tax', 'description': 'Income Tax', 'deduction_name': 'Income Tax'},
|
||||
{'doctype': 'Deduction Type', 'name': 'Professional Tax', 'description': 'Professional Tax', 'deduction_name': 'Professional Tax'},
|
||||
{'doctype': 'Deduction Type', 'name': 'Provident Fund', 'description': 'Provident fund', 'deduction_name': 'Provident Fund'},
|
||||
|
||||
|
||||
# earning type
|
||||
{'doctype': 'Earning Type', 'name': 'Basic', 'description': 'Basic', 'earning_name': 'Basic', 'taxable': 'Yes'},
|
||||
{'doctype': 'Earning Type', 'name': 'House Rent Allowance', 'description': 'House Rent Allowance', 'earning_name': 'House Rent Allowance', 'taxable': 'No'},
|
||||
|
||||
|
||||
# expense claim type
|
||||
{'doctype': 'Expense Claim Type', 'name': 'Calls', 'expense_type': 'Calls'},
|
||||
{'doctype': 'Expense Claim Type', 'name': 'Food', 'expense_type': 'Food'},
|
||||
{'doctype': 'Expense Claim Type', 'name': 'Medical', 'expense_type': 'Medical'},
|
||||
{'doctype': 'Expense Claim Type', 'name': 'Others', 'expense_type': 'Others'},
|
||||
{'doctype': 'Expense Claim Type', 'name': 'Travel', 'expense_type': 'Travel'},
|
||||
|
||||
|
||||
# leave type
|
||||
{'doctype': 'Leave Type', 'leave_type_name': 'Casual Leave', 'name': 'Casual Leave', 'is_encash': 1, 'is_carry_forward': 1, 'max_days_allowed': '3', },
|
||||
{'doctype': 'Leave Type', 'leave_type_name': 'Compensatory Off', 'name': 'Compensatory Off', 'is_encash': 0, 'is_carry_forward': 0, },
|
||||
{'doctype': 'Leave Type', 'leave_type_name': 'Sick Leave', 'name': 'Sick Leave', 'is_encash': 0, 'is_carry_forward': 0, },
|
||||
{'doctype': 'Leave Type', 'leave_type_name': 'Privilege Leave', 'name': 'Privilege Leave', 'is_encash': 0, 'is_carry_forward': 0, },
|
||||
{'doctype': 'Leave Type', 'leave_type_name': 'Leave Without Pay', 'name': 'Leave Without Pay', 'is_encash': 0, 'is_carry_forward': 0, 'is_lwp':1},
|
||||
|
||||
|
||||
# territory
|
||||
{'doctype': 'Territory', 'territory_name': 'All Territories', 'is_group': 'Yes', 'name': 'All Territories', 'parent_territory': ''},
|
||||
|
||||
|
||||
# customer group
|
||||
{'doctype': 'Customer Group', 'customer_group_name': 'All Customer Groups', 'is_group': 'Yes', 'name': 'All Customer Groups', 'parent_customer_group': ''},
|
||||
{'doctype': 'Customer Group', 'customer_group_name': 'Individual', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
|
||||
{'doctype': 'Customer Group', 'customer_group_name': 'Commercial', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
|
||||
{'doctype': 'Customer Group', 'customer_group_name': 'Non Profit', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
|
||||
{'doctype': 'Customer Group', 'customer_group_name': 'Government', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
|
||||
|
||||
|
||||
# supplier type
|
||||
{'doctype': 'Supplier Type', 'supplier_type': 'Services'},
|
||||
{'doctype': 'Supplier Type', 'supplier_type': 'Local'},
|
||||
@ -93,33 +96,33 @@ def import_defaults():
|
||||
{'doctype': 'Supplier Type', 'supplier_type': 'Hardware'},
|
||||
{'doctype': 'Supplier Type', 'supplier_type': 'Pharmaceutical'},
|
||||
{'doctype': 'Supplier Type', 'supplier_type': 'Distributor'},
|
||||
|
||||
|
||||
# Sales Person
|
||||
{'doctype': 'Sales Person', 'sales_person_name': 'Sales Team', 'is_group': "Yes", "parent_sales_person": ""},
|
||||
|
||||
|
||||
# UOM
|
||||
{'uom_name': 'Unit', 'doctype': 'UOM', 'name': 'Unit', "must_be_whole_number": 1},
|
||||
{'uom_name': 'Box', 'doctype': 'UOM', 'name': 'Box', "must_be_whole_number": 1},
|
||||
{'uom_name': 'Kg', 'doctype': 'UOM', 'name': 'Kg'},
|
||||
{'uom_name': 'Nos', 'doctype': 'UOM', 'name': 'Nos', "must_be_whole_number": 1},
|
||||
{'uom_name': 'Pair', 'doctype': 'UOM', 'name': 'Pair', "must_be_whole_number": 1},
|
||||
{'uom_name': 'Set', 'doctype': 'UOM', 'name': 'Set', "must_be_whole_number": 1},
|
||||
{'uom_name': 'Unit', 'doctype': 'UOM', 'name': 'Unit', "must_be_whole_number": 1},
|
||||
{'uom_name': 'Box', 'doctype': 'UOM', 'name': 'Box', "must_be_whole_number": 1},
|
||||
{'uom_name': 'Kg', 'doctype': 'UOM', 'name': 'Kg'},
|
||||
{'uom_name': 'Nos', 'doctype': 'UOM', 'name': 'Nos', "must_be_whole_number": 1},
|
||||
{'uom_name': 'Pair', 'doctype': 'UOM', 'name': 'Pair', "must_be_whole_number": 1},
|
||||
{'uom_name': 'Set', 'doctype': 'UOM', 'name': 'Set', "must_be_whole_number": 1},
|
||||
{'uom_name': 'Hour', 'doctype': 'UOM', 'name': 'Hour'},
|
||||
{'uom_name': 'Minute', 'doctype': 'UOM', 'name': 'Minute'},
|
||||
{'uom_name': 'Minute', 'doctype': 'UOM', 'name': 'Minute'},
|
||||
|
||||
]
|
||||
|
||||
|
||||
from frappe.modules import scrub
|
||||
for r in records:
|
||||
doc = frappe.get_doc(r)
|
||||
|
||||
|
||||
# ignore mandatory for root
|
||||
parent_link_field = ("parent_" + scrub(doc.doctype))
|
||||
if doc.meta.get_field(parent_link_field) and not doc.get(parent_link_field):
|
||||
doc.ignore_mandatory = True
|
||||
|
||||
|
||||
doc.insert()
|
||||
|
||||
|
||||
def feature_setup():
|
||||
"""save global defaults and features setup"""
|
||||
doc = frappe.get_doc("Features Setup", "Features Setup")
|
||||
|
@ -80,7 +80,6 @@ def create_fiscal_year_and_company(args):
|
||||
'year_end_date': args.get('fy_end_date'),
|
||||
}).insert()
|
||||
|
||||
print args
|
||||
# Company
|
||||
frappe.get_doc({
|
||||
"doctype":"Company",
|
||||
@ -97,16 +96,16 @@ def create_fiscal_year_and_company(args):
|
||||
def create_price_lists(args):
|
||||
for pl_type in ["Selling", "Buying"]:
|
||||
frappe.get_doc({
|
||||
"doctype": "Price List",
|
||||
"price_list_name": "Standard " + pl_type,
|
||||
"enabled": 1,
|
||||
"buying": 1 if pl_type == "Buying" else 0,
|
||||
"selling": 1 if pl_type == "Selling" else 0,
|
||||
"currency": args["currency"],
|
||||
"valid_for_territories": {
|
||||
"territory": "All Territories"
|
||||
}
|
||||
}).insert()
|
||||
"doctype": "Price List",
|
||||
"price_list_name": "Standard " + pl_type,
|
||||
"enabled": 1,
|
||||
"buying": 1 if pl_type == "Buying" else 0,
|
||||
"selling": 1 if pl_type == "Selling" else 0,
|
||||
"currency": args["currency"],
|
||||
"valid_for_territories": [{
|
||||
"territory": "All Territories"
|
||||
}]
|
||||
}).insert()
|
||||
|
||||
def set_defaults(args):
|
||||
# enable default currency
|
||||
|
@ -12,8 +12,11 @@ class PriceList(DocListController):
|
||||
def validate(self):
|
||||
if not cint(self.buying) and not cint(self.selling):
|
||||
throw(_("Price List must be applicable for Buying or Selling"))
|
||||
|
||||
if not self.get("valid_for_territories"):
|
||||
|
||||
try:
|
||||
# at least one territory
|
||||
self.validate_table_has_rows("valid_for_territories")
|
||||
except frappe.EmptyTableError:
|
||||
# if no territory, set default territory
|
||||
if frappe.defaults.get_user_default("territory"):
|
||||
self.append("valid_for_territories", {
|
||||
@ -21,8 +24,7 @@ class PriceList(DocListController):
|
||||
"territory": frappe.defaults.get_user_default("territory")
|
||||
})
|
||||
else:
|
||||
# at least one territory
|
||||
self.validate_table_has_rows("valid_for_territories")
|
||||
raise
|
||||
|
||||
def on_update(self):
|
||||
self.set_default_if_missing()
|
||||
@ -38,8 +40,8 @@ class PriceList(DocListController):
|
||||
frappe.set_value("Buying Settings", "Buying Settings", "buying_price_list", self.name)
|
||||
|
||||
def update_item_price(self):
|
||||
frappe.db.sql("""update `tabItem Price` set currency=%s,
|
||||
buying=%s, selling=%s, modified=NOW() where price_list=%s""",
|
||||
frappe.db.sql("""update `tabItem Price` set currency=%s,
|
||||
buying=%s, selling=%s, modified=NOW() where price_list=%s""",
|
||||
(self.currency, cint(self.buying), cint(self.selling), self.name))
|
||||
|
||||
def on_trash(self):
|
||||
@ -50,6 +52,6 @@ class PriceList(DocListController):
|
||||
if self.name == b.get(price_list_fieldname):
|
||||
b.set(price_list_fieldname, None)
|
||||
b.save()
|
||||
|
||||
|
||||
for module in ["Selling", "Buying"]:
|
||||
_update_default_price_list(module)
|
||||
_update_default_price_list(module)
|
||||
|
Loading…
x
Reference in New Issue
Block a user