This commit is contained in:
Nabin Hait 2014-03-28 16:57:21 +05:30
parent 81ba0b29da
commit 0d8d30e1cc
39 changed files with 134 additions and 188 deletions

View File

@ -3,12 +3,8 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import flt, fmt_money, cstr, cint
from frappe import msgprint, throw, _
get_value = frappe.db.get_value
from frappe.model.document import Document
class Account(Document):
@ -19,10 +15,7 @@ class Account(Document):
frappe.db.get_value("Company", self.company, "abbr")
def get_address(self):
return {
'address': frappe.db.get_value(self.master_type,
self.master_name, "address")
}
return {'address': frappe.db.get_value(self.master_type, self.master_name, "address")}
def validate(self):
self.validate_master_name()
@ -32,24 +25,19 @@ class Account(Document):
self.validate_mandatory()
self.validate_warehouse_account()
self.validate_frozen_accounts_modifier()
if not self.parent_account:
self.parent_account = ''
def validate_master_name(self):
"""Remind to add master name"""
if self.master_type in ('Customer', 'Supplier') or self.account_type == "Warehouse":
if not self.master_name:
msgprint(_("Please enter Master Name once the account is created."))
elif not frappe.db.exists(self.master_type or self.account_type,
self.master_name):
elif not frappe.db.exists(self.master_type or self.account_type, self.master_name):
throw(_("Invalid Master Name"))
def validate_parent(self):
"""Fetch Parent Details and validation for account not to be created under ledger"""
if self.parent_account:
par = frappe.db.sql("""select name, group_or_ledger, report_type
from tabAccount where name =%s""", self.parent_account, as_dict=1)
par = frappe.db.get_value("Account", self.parent_account,
["name", "group_or_ledger", "report_type"], as_dict=1)
if not par:
throw(_("Parent account does not exists"))
elif par[0]["name"] == self.name:
@ -63,14 +51,13 @@ class Account(Document):
def validate_duplicate_account(self):
if self.get('__islocal') or not self.name:
company_abbr = frappe.db.get_value("Company", self.company, "abbr")
if frappe.db.sql("""select name from tabAccount where name=%s""",
(self.account_name + " - " + company_abbr)):
throw("{name}: {acc_name} {exist}, {rename}".format(**{
"name": _("Account Name"),
"acc_name": self.account_name,
"exist": _("already exists"),
"rename": _("please rename")
}))
if frappe.db.exists("Account", (self.account_name + " - " + company_abbr)):
throw("{name}: {acc_name} {exist}, {rename}".format(**{
"name": _("Account Name"),
"acc_name": self.account_name,
"exist": _("already exists"),
"rename": _("please rename")
}))
def validate_root_details(self):
#does not exists parent

View File

@ -35,12 +35,12 @@ def _make_test_records(verbose):
]
for company, abbr in [["_Test Company", "_TC"], ["_Test Company 1", "_TC1"]]:
test_objects = make_test_objects("Account", [[{
test_objects = make_test_objects("Account", [{
"doctype": "Account",
"account_name": account_name,
"parent_account": parent_account + " - " + abbr,
"company": company,
"group_or_ledger": group_or_ledger
}] for account_name, parent_account, group_or_ledger in accounts])
} for account_name, parent_account, group_or_ledger in accounts])
return test_objects

View File

@ -7,18 +7,16 @@ from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import cint
from frappe.model.document import Document
class AccountsSettings(Document):
def on_update(self):
frappe.db.set_default("auto_accounting_for_stock", self.auto_accounting_for_stock)
if cint(self.auto_accounting_for_stock):
# set default perpetual account in company
for company in frappe.db.sql("select name from tabCompany"):
frappe.bean("Company", company[0]).save()
frappe.get_doc("Company", company[0]).save()
# Create account head for warehouses
warehouse_list = frappe.db.sql("select name, company from tabWarehouse", as_dict=1)

View File

@ -3,20 +3,25 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, flt, getdate, now, nowdate
from frappe import msgprint
from frappe.utils import cstr, flt, getdate, nowdate
from frappe import msgprint, _
from frappe.model.document import Document
class BankReconciliation(Document):
def get_details(self):
if not (self.bank_account and self.from_date and self.to_date):
msgprint("Bank Account, From Date and To Date are Mandatory")
return
dl = frappe.db.sql("select t1.name, t1.cheque_no, t1.cheque_date, t2.debit, t2.credit, t1.posting_date, t2.against_account from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t2.parent = t1.name and t2.account = %s and (clearance_date is null or clearance_date = '0000-00-00' or clearance_date = '') and t1.posting_date >= %s and t1.posting_date <= %s and t1.docstatus=1", (self.bank_account, self.from_date, self.to_date))
dl = frappe.db.sql("""select t1.name, t1.cheque_no, t1.cheque_date, t2.debit,
t2.credit, t1.posting_date, t2.against_account
from
`tabJournal Voucher` t1, `tabJournal Voucher Detail` t2
where
t2.parent = t1.name and t2.account = %s
and (clearance_date is null or clearance_date = '0000-00-00' or clearance_date = '')
and t1.posting_date >= %s and t1.posting_date <= %s and t1.docstatus=1""",
(self.bank_account, self.from_date, self.to_date))
self.set('entries', [])
self.total_amount = 0.0
@ -37,15 +42,14 @@ class BankReconciliation(Document):
for d in self.get('entries'):
if d.clearance_date:
if d.cheque_date and getdate(d.clearance_date) < getdate(d.cheque_date):
msgprint("Clearance Date can not be before Cheque Date (Row #%s)" %
d.idx, raise_exception=1)
frappe.throw("Clearance Date can not be before Cheque Date (Row #%s)" % d.idx)
frappe.db.sql("""update `tabJournal Voucher`
set clearance_date = %s, modified = %s where name=%s""",
(d.clearance_date, nowdate(), d.voucher_id))
frappe.db.set_value("Journal Voucher", d.voucher_id, "clearance_date", d.clearance_date)
frappe.db.sql("""update `tabJournal Voucher` set clearance_date = %s, modified = %s
where name=%s""", (d.clearance_date, nowdate(), d.voucher_id))
vouchers.append(d.voucher_id)
if vouchers:
msgprint("Clearance Date updated in %s" % ", ".join(vouchers))
else:
msgprint("Clearance Date not mentioned")
msgprint(_("Clearance Date not mentioned"))

View File

@ -3,7 +3,6 @@
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class BankReconciliationDetail(Document):

View File

@ -3,7 +3,6 @@
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class BudgetDetail(Document):

View File

@ -3,11 +3,8 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import flt
from frappe.model.bean import getlist
from frappe import msgprint, _
from frappe import _
from frappe.model.document import Document
class BudgetDistribution(Document):
@ -17,13 +14,12 @@ class BudgetDistribution(Document):
idx =1
for m in month_list:
mnth = self.append('budget_distribution_details')
mnth.month = m or ''
mnth.month = m
mnth.idx = idx
idx += 1
def validate(self):
total = sum([flt(d.percentage_allocation, 2) for d in self.doclist.get(
{"parentfield": "budget_distribution_details"})])
total = sum([flt(d.percentage_allocation) for d in self.get("budget_distribution_details")])
if total != 100.0:
msgprint(_("Percentage Allocation should be equal to ") + "100%", raise_exception=1)
frappe.throw(_("Percentage Allocation should be equal to ") + "100%")

View File

@ -2,69 +2,48 @@
# License: GNU General Public License v3. See license.txt
test_records = [
[{
{
"doctype": "Budget Distribution",
"distribution_id": "_Test Distribution",
"fiscal_year": "_Test Fiscal Year 2013",
}, {
"doctype": "Budget Distribution Detail",
"parentfield": "budget_distribution_details",
"month": "January",
"percentage_allocation": "8"
}, {
"doctype": "Budget Distribution Detail",
"parentfield": "budget_distribution_details",
"month": "February",
"percentage_allocation": "8"
}, {
"doctype": "Budget Distribution Detail",
"parentfield": "budget_distribution_details",
"month": "March",
"percentage_allocation": "8"
}, {
"doctype": "Budget Distribution Detail",
"parentfield": "budget_distribution_details",
"month": "April",
"percentage_allocation": "8"
}, {
"doctype": "Budget Distribution Detail",
"parentfield": "budget_distribution_details",
"month": "May",
"percentage_allocation": "8"
}, {
"doctype": "Budget Distribution Detail",
"parentfield": "budget_distribution_details",
"month": "June",
"percentage_allocation": "8"
}, {
"doctype": "Budget Distribution Detail",
"parentfield": "budget_distribution_details",
"month": "July",
"percentage_allocation": "8"
}, {
"doctype": "Budget Distribution Detail",
"parentfield": "budget_distribution_details",
"month": "August",
"percentage_allocation": "8"
}, {
"doctype": "Budget Distribution Detail",
"parentfield": "budget_distribution_details",
"month": "September",
"percentage_allocation": "8"
}, {
"doctype": "Budget Distribution Detail",
"parentfield": "budget_distribution_details",
"month": "October",
"percentage_allocation": "8"
}, {
"doctype": "Budget Distribution Detail",
"parentfield": "budget_distribution_details",
"month": "November",
"percentage_allocation": "10"
}, {
"doctype": "Budget Distribution Detail",
"parentfield": "budget_distribution_details",
"month": "December",
"percentage_allocation": "10"
}]
"budget_distribution_details": [
{
"month": "January",
"percentage_allocation": "8"
}, {
"month": "February",
"percentage_allocation": "8"
}, {
"month": "March",
"percentage_allocation": "8"
}, {
"month": "April",
"percentage_allocation": "8"
}, {
"month": "May",
"percentage_allocation": "8"
}, {
"month": "June",
"percentage_allocation": "8"
}, {
"month": "July",
"percentage_allocation": "8"
}, {
"month": "August",
"percentage_allocation": "8"
}, {
"month": "September",
"percentage_allocation": "8"
}, {
"month": "October",
"percentage_allocation": "8"
}, {
"month": "November",
"percentage_allocation": "10"
}, {
"month": "December",
"percentage_allocation": "10"
}
]
}
]

View File

@ -3,7 +3,6 @@
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class BudgetDistributionDetail(Document):

View File

@ -3,14 +3,11 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import flt, getdate
from frappe.model.bean import getlist
from frappe.utils import flt
from frappe import _
from frappe.model.document import Document
class CForm(Document):
def validate(self):
"""Validate invoice that c-form is applicable
and no other c-form is received for that"""
@ -21,18 +18,17 @@ class CForm(Document):
`tabSales Invoice` where name = %s and docstatus = 1""", d.invoice_no)
if not inv:
frappe.msgprint("""Invoice: %s is not exists in the system or
is not submitted, please check.""" % d.invoice_no, raise_exception=1)
frappe.throw("""Invoice: %s is not exists in the system or
is not submitted, please check.""" % d.invoice_no)
elif inv[0][0] != 'Yes':
frappe.msgprint("C-form is not applicable for Invoice: %s" %
d.invoice_no, raise_exception=1)
frappe.throw("C-form is not applicable for Invoice: %s" % d.invoice_no)
elif inv[0][1] and inv[0][1] != self.name:
frappe.msgprint("""Invoice %s is tagged in another C-form: %s.
frappe.throw("""Invoice %s is tagged in another C-form: %s.
If you want to change C-form no for this invoice,
please remove invoice no from the previous c-form and then try again""" %
(d.invoice_no, inv[0][1]), raise_exception=1)
(d.invoice_no, inv[0][1]))
def on_update(self):
""" Update C-Form No on invoices"""
@ -43,22 +39,19 @@ class CForm(Document):
def before_cancel(self):
# remove cform reference
frappe.db.sql("""update `tabSales Invoice` set c_form_no=null
where c_form_no=%s""", self.name)
frappe.db.sql("""update `tabSales Invoice` set c_form_no=null where c_form_no=%s""", self.name)
def set_cform_in_sales_invoices(self):
inv = [d.invoice_no for d in self.get('invoice_details')]
if inv:
frappe.db.sql("""update `tabSales Invoice` set c_form_no=%s, modified=%s
where name in (%s)""" % ('%s', '%s', ', '.join(['%s'] * len(inv))),
tuple([self.name, self.modified] + inv))
frappe.db.sql("""update `tabSales Invoice` set c_form_no=%s, modified=%s where name in (%s)""" %
('%s', '%s', ', '.join(['%s'] * len(inv))), tuple([self.name, self.modified] + inv))
frappe.db.sql("""update `tabSales Invoice` set c_form_no = null, modified = %s
where name not in (%s) and ifnull(c_form_no, '') = %s""" %
('%s', ', '.join(['%s']*len(inv)), '%s'),
tuple([self.modified] + inv + [self.name]))
('%s', ', '.join(['%s']*len(inv)), '%s'), tuple([self.modified] + inv + [self.name]))
else:
frappe.msgprint("Please enter atleast 1 invoice in the table", raise_exception=1)
frappe.throw(_("Please enter atleast 1 invoice in the table"))
def set_total_invoiced_amount(self):
total = sum([flt(d.grand_total) for d in self.get('invoice_details')])
@ -67,13 +60,13 @@ class CForm(Document):
def get_invoice_details(self, invoice_no):
""" Pull details from invoices for referrence """
inv = frappe.db.sql("""select posting_date, territory, net_total, grand_total
from `tabSales Invoice` where name = %s""", invoice_no)
inv = frappe.db.get_value("Sales Invoice", invoice_no,
["posting_date", "territory", "net_total", "grand_total"], as_dict=True)
return {
'invoice_date' : inv and getdate(inv[0][0]).strftime('%Y-%m-%d') or '',
'territory' : inv and inv[0][1] or '',
'net_total' : inv and flt(inv[0][2]) or '',
'grand_total' : inv and flt(inv[0][3]) or ''
'invoice_date' : inv.posting_date,
'territory' : inv.territory,
'net_total' : inv.net_total,
'grand_total' : inv.grand_total
}
def get_invoice_nos(doctype, txt, searchfield, start, page_len, filters):

View File

@ -3,7 +3,6 @@
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class CFormInvoiceDetail(Document):

View File

@ -5,25 +5,21 @@ from __future__ import unicode_literals
import frappe, os, json
from frappe.utils import cstr
from unidecode import unidecode
from frappe.model.document import Document
class ChartOfAccounts(Document):
self.no_report_type = False
no_report_type = False
def create_accounts(self, company):
chart = {}
with open(os.path.join(os.path.dirname(__file__), "charts",
self.source_file), "r") as f:
with open(os.path.join(os.path.dirname(__file__), "charts", self.source_file), "r") as f:
chart = json.loads(f.read())
from erpnext.accounts.doctype.chart_of_accounts.charts.account_properties \
import account_properties
from erpnext.accounts.doctype.chart_of_accounts.charts.account_properties import account_properties
if chart:
accounts = []
def _import_accounts(children, parent):
for child in children:
account_name = child.get("name")
@ -33,10 +29,9 @@ class ChartOfAccounts(Document):
count = accounts.count(account_name_in_db)
account_name = account_name + " " + cstr(count)
child.update(account_properties.get(chart.get("name"), {})\
.get(account_name, {}))
child.update(account_properties.get(chart.get("name"), {}).get(account_name, {}))
account = frappe.bean({
account = frappe.new_doc({
"doctype": "Account",
"account_name": account_name,
"company": company,
@ -63,5 +58,5 @@ class ChartOfAccounts(Document):
@frappe.whitelist()
def get_charts_for_country(country):
return frappe.db.sql_list("select chart_name from `tabChart of Accounts` where country=%s",
country)
return frappe.db.sql_list("""select chart_name from `tabChart of Accounts`
where country=%s""", country)

View File

@ -13,7 +13,7 @@ def import_charts():
chart = json.loads(f.read())
country = frappe.db.get_value("Country", {"code": fname.split("_", 1)[0]})
if country:
bean = frappe.bean({
bean = frappe.new_doc({
"doctype":"Chart of Accounts",
"chart_name": chart.get("name"),
"source_file": fname,

View File

@ -3,19 +3,17 @@
from __future__ import unicode_literals
import frappe
from frappe.model.bean import getlist
from frappe import msgprint, _
from frappe.utils.nestedset import DocTypeNestedSet
class CostCenter(DocTypeNestedSet):
self.nsm_parent_field = 'parent_cost_center'
nsm_parent_field = 'parent_cost_center'
def autoname(self):
company_abbr = frappe.db.sql("select abbr from tabCompany where name=%s",
self.company)[0][0]
self.name = self.cost_center_name.strip() + ' - ' + company_abbr
self.name = self.cost_center_name.strip() + ' - ' + \
frappe.get_value("Company", self.company, "abbr")
def validate_mandatory(self):
if not self.group_or_ledger:
@ -78,7 +76,7 @@ class CostCenter(DocTypeNestedSet):
new_cost_center = get_name_with_abbr(newdn, self.company)
# Validate properties before merging
super(DocType, self).before_rename(olddn, new_cost_center, merge, "group_or_ledger")
super(CostCenter, self).before_rename(olddn, new_cost_center, merge, "group_or_ledger")
return new_cost_center
@ -87,5 +85,5 @@ class CostCenter(DocTypeNestedSet):
frappe.db.set_value("Cost Center", newdn, "cost_center_name",
" - ".join(newdn.split(" - ")[:-1]))
else:
super(DocType, self).after_rename(olddn, newdn, merge)
super(CostCenter, self).after_rename(olddn, newdn, merge)

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import flt
from frappe.model.bean import getlist
from frappe import msgprint, _
from frappe.model.document import Document

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cint, cstr, flt, formatdate
from frappe.model.bean import getlist
from frappe.model.code import get_obj
from frappe import msgprint, _
from erpnext.setup.utils import get_company_currency

View File

@ -10,7 +10,7 @@ from frappe.utils import add_days, cint, cstr, date_diff, flt, getdate, nowdate,
from frappe.utils import comma_and
from frappe.model.naming import make_autoname
from frappe.model.bean import getlist
from frappe.model.code import get_obj
from frappe import _, msgprint

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, flt
from frappe.model.bean import getlist
from frappe.model.code import get_obj
from frappe import msgprint

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, flt, getdate
from frappe.model.bean import getlist
from frappe import msgprint, _
from frappe.model.mapper import get_mapped_doc
from frappe.model.document import Document

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe.model.bean import getlist
from frappe import msgprint
from frappe.model.document import Document

View File

@ -6,7 +6,7 @@ import frappe
from frappe.utils import add_days, cint, cstr, flt, getdate, nowdate, _round
from frappe.model.naming import make_autoname
from frappe.model.bean import getlist
from frappe.model.code import get_obj
from frappe import msgprint, _
from erpnext.setup.utils import get_company_currency

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cint, cstr, flt, now, nowdate
from frappe.model.bean import getlist
from frappe.model.code import get_obj
from frappe import msgprint, _

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, flt, cint, nowdate, add_days
from frappe.model.bean import getlist
from frappe.model.code import get_obj
from frappe import msgprint, _

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, getdate
from frappe.model.bean import getlist
from frappe import msgprint
from erpnext.stock.utils import get_valid_serial_nos

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint
from frappe.model.bean import getlist
from frappe import msgprint, _

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr
from frappe.model.bean import getlist
from frappe.model.code import get_obj
from frappe import _, msgprint

View File

@ -6,7 +6,7 @@ import frappe
import frappe.utils
from frappe.utils import cstr, flt, getdate
from frappe.model.bean import getlist
from frappe.model.code import get_obj
from frappe import msgprint
from frappe.model.mapper import get_mapped_doc

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, flt, has_common, make_esc
from frappe.model.bean import getlist
from frappe import session, msgprint
from erpnext.setup.utils import get_company_currency

View File

@ -3,7 +3,7 @@
from __future__ import unicode_literals
import frappe
from frappe.model.bean import getlist
from frappe.utils import flt
from frappe.utils.nestedset import DocTypeNestedSet

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe.model.bean import getlist
from frappe.utils import flt
from frappe.utils.nestedset import DocTypeNestedSet

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, flt, cint
from frappe.model.bean import getlist
from frappe.model.code import get_obj
from frappe import msgprint, _
import frappe.defaults

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, flt, getdate, now_datetime, formatdate
from frappe.model.bean import getlist
from frappe import msgprint, _
from frappe.model.controller import DocListController

View File

@ -6,7 +6,7 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, flt
from frappe.model.bean import getlist
from frappe.model.document import Document

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, flt, cint
from frappe.model.bean import getlist
from frappe.model.code import get_obj
from frappe import msgprint, _
import frappe.defaults

View File

@ -6,7 +6,7 @@ import frappe
import frappe.defaults
from frappe.utils import cstr, cint, flt, comma_or, nowdate
from frappe.model.bean import getlist
from frappe.model.code import get_obj
from frappe import msgprint, _
from erpnext.stock.utils import get_incoming_rate

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import add_days, cstr, flt, nowdate, cint, now
from frappe.model.bean import getlist
from frappe.model.code import get_obj
from frappe import session, msgprint
from erpnext.stock.utils import get_valid_serial_nos

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import add_days, cstr, getdate, cint
from frappe.model.bean import getlist
from frappe import throw, _
from erpnext.utilities.transaction_base import TransactionBase, delete_events
from erpnext.stock.utils import get_valid_serial_nos

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cstr
from frappe.model.bean import getlist
from frappe import msgprint

View File

@ -7,7 +7,7 @@ import frappe, json
from frappe.utils import nowdate, cstr
from frappe.model.code import get_obj
from frappe import msgprint, throw, _
from frappe.model.bean import getlist
from frappe.model.document import Document