aii fixes

This commit is contained in:
Nabin Hait
2013-03-29 16:42:33 +05:30
parent acecb94a0f
commit 787c02ee42
27 changed files with 294 additions and 150 deletions

View File

@@ -53,4 +53,15 @@ cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn)
return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50';
}
cur_frm.fields_dict["expense_account"].get_query = function(doc) {
return {
"query": "accounts.utils.get_account_list",
"filters": {
"is_pl_account": "Yes",
"debit_or_credit": "Debit",
"company": doc.company
}
}
}
cur_frm.fields_dict.user.get_query = erpnext.utils.profile_query;

View File

@@ -76,7 +76,11 @@ class DocType(BuyingController):
self.update_valuation_rate("entries")
def get_credit_to(self):
acc_head = sql("select name, credit_days from `tabAccount` where (name = %s or (master_name = %s and master_type = 'supplier')) and docstatus != 2", (cstr(self.doc.supplier) + " - " + self.company_abbr,self.doc.supplier))
acc_head = sql("""select name, credit_days from `tabAccount`
where (name = %s or (master_name = %s and master_type = 'supplier'))
and docstatus != 2 and company = %s""",
(cstr(self.doc.supplier) + " - " + self.company_abbr,
self.doc.supplier, self.doc.company))
ret = {}
if acc_head and acc_head[0][0]:
@@ -217,7 +221,8 @@ class DocType(BuyingController):
# 3. Is not a PL Account
# ----------------------------
def validate_credit_acc(self):
acc = sql("select debit_or_credit, is_pl_account from tabAccount where name = '%s'" % self.doc.credit_to)
acc = sql("select debit_or_credit, is_pl_account from tabAccount where name = %s",
self.doc.credit_to)
if not acc:
msgprint("Account: "+ self.doc.credit_to + "does not exist")
raise Exception
@@ -409,7 +414,7 @@ class DocType(BuyingController):
purchase_controller.update_prevdoc_detail(self, is_submit = 1)
def make_gl_entries(self, is_cancel = 0):
def make_gl_entries(self):
from accounts.general_ledger import make_gl_entries
auto_inventory_accounting = \
cint(webnotes.defaults.get_global_default("auto_inventory_accounting"))
@@ -426,7 +431,7 @@ class DocType(BuyingController):
"remarks": self.doc.remarks,
"against_voucher": self.doc.name,
"against_voucher_type": self.doc.doctype,
}, is_cancel)
})
)
# tax table gl entries
@@ -441,7 +446,7 @@ class DocType(BuyingController):
"credit": tax.add_deduct_tax == "Deduct" and tax.tax_amount or 0,
"remarks": self.doc.remarks,
"cost_center": tax.cost_center
}, is_cancel)
})
)
# accumulate valuation tax
@@ -469,7 +474,7 @@ class DocType(BuyingController):
"debit": flt(item.valuation_rate) * flt(item.conversion_factor) \
* flt(item.qty),
"remarks": self.doc.remarks or "Accounting Entry for Stock"
}, is_cancel)
})
)
elif flt(item.amount):
@@ -481,7 +486,7 @@ class DocType(BuyingController):
"debit": item.amount,
"remarks": self.doc.remarks,
"cost_center": item.cost_center
}, is_cancel)
})
)
if stock_item_and_auto_inventory_accounting and valuation_tax:
@@ -494,7 +499,7 @@ class DocType(BuyingController):
"against": self.doc.credit_to,
"credit": valuation_tax,
"remarks": self.doc.remarks or "Accounting Entry for Stock"
}, is_cancel)
})
)
# writeoff account includes petty difference in the invoice amount
@@ -507,19 +512,19 @@ class DocType(BuyingController):
"credit": flt(self.doc.write_off_amount),
"remarks": self.doc.remarks,
"cost_center": self.doc.write_off_cost_center
}, is_cancel)
})
)
if gl_entries:
make_gl_entries(gl_entries, cancel=is_cancel)
make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))
def on_cancel(self):
from accounts.utils import remove_against_link_from_jv
remove_against_link_from_jv(self.doc.doctype, self.doc.name, "against_voucher")
self.make_gl_entries(is_cancel=1)
get_obj(dt = 'Purchase Common').update_prevdoc_detail(self, is_submit = 0)
self.make_cancel_gl_entries()
def on_update(self):
pass

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-02-27 13:45:00",
"creation": "2013-03-07 11:42:55",
"docstatus": 0,
"modified": "2013-03-07 07:03:26",
"modified": "2013-03-29 13:44:37",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -35,6 +35,7 @@
"oldfieldtype": "Link",
"options": "Item",
"print_hide": 1,
"read_only": 0,
"reqd": 0,
"search_index": 1
},
@@ -46,6 +47,7 @@
"label": "Item Name",
"oldfieldname": "item_name",
"oldfieldtype": "Data",
"read_only": 0,
"reqd": 1,
"search_index": 0
},
@@ -57,6 +59,7 @@
"oldfieldname": "description",
"oldfieldtype": "Text",
"print_width": "300px",
"read_only": 0,
"width": "300px"
},
{
@@ -67,6 +70,7 @@
"oldfieldname": "qty",
"oldfieldtype": "Currency",
"print_hide": 0,
"read_only": 0,
"reqd": 1
},
{
@@ -75,7 +79,8 @@
"fieldtype": "Link",
"label": "UOM",
"options": "UOM",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -83,14 +88,16 @@
"fieldtype": "Currency",
"label": "Ref Rate ",
"options": "currency",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "discount_rate",
"fieldtype": "Float",
"label": "Discount %",
"print_hide": 0
"print_hide": 0,
"read_only": 0
},
{
"doctype": "DocField",
@@ -101,6 +108,7 @@
"oldfieldtype": "Currency",
"options": "currency",
"print_hide": 0,
"read_only": 0,
"reqd": 1
},
{
@@ -120,7 +128,8 @@
"fieldtype": "Currency",
"label": "Ref Rate*",
"options": "Company:company:default_currency",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -131,6 +140,7 @@
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 0,
"reqd": 1
},
{
@@ -155,7 +165,8 @@
"options": "Account",
"print_hide": 1,
"print_width": "120px",
"reqd": 1,
"read_only": 0,
"reqd": 0,
"width": "120px"
},
{
@@ -168,6 +179,7 @@
"options": "Cost Center",
"print_hide": 1,
"print_width": "120px",
"read_only": 0,
"width": "120px"
},
{
@@ -177,7 +189,8 @@
"in_filter": 1,
"label": "Project Name",
"options": "Project",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -187,7 +200,8 @@
"label": "Brand",
"oldfieldname": "brand",
"oldfieldtype": "Data",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -298,7 +312,8 @@
"fieldname": "conversion_factor",
"fieldtype": "Float",
"label": "Conversion Factor",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -319,6 +334,7 @@
"label": "Page Break",
"no_copy": 1,
"print_hide": 1,
"read_only": 0,
"report_hide": 1
}
]

View File

@@ -80,7 +80,8 @@ cur_frm.cscript.hide_fields = function(doc, cdt, cdn) {
'total_commission', 'advances'];
item_flds_normal = ['sales_order', 'delivery_note']
item_flds_pos = ['warehouse', 'serial_no', 'batch_no', 'actual_qty', 'delivered_qty']
item_flds_pos = ['warehouse', 'serial_no', 'batch_no', 'actual_qty',
'delivered_qty', 'expense_account']
if(cint(doc.is_pos) == 1) {
hide_field(par_flds);

View File

@@ -16,6 +16,7 @@
from __future__ import unicode_literals
import webnotes
import webnotes.defaults
from webnotes.utils import add_days, cint, cstr, date_diff, flt, getdate, nowdate, \
get_first_day, get_last_day
@@ -131,7 +132,7 @@ class DocType(SellingController):
sales_com_obj.update_prevdoc_detail(0, self)
self.make_gl_entries()
self.make_cancel_gl_entries()
def on_update_after_submit(self):
self.validate_recurring_invoice()

View File

@@ -264,48 +264,61 @@ def create_stock_in_hand_jv(reverse=False):
from webnotes.utils import nowdate
today = nowdate()
fiscal_year = get_fiscal_year(today)[0]
jv_list = []
for company in webnotes.conn.sql_list("select name from `tabCompany`"):
stock_rbnb_value = get_stock_rbnb_value(company)
stock_rbnb_value = reverse and -1*stock_rbnb_value or stock_rbnb_value
if stock_rbnb_value:
jv = webnotes.bean([
{
"doctype": "Journal Voucher",
"naming_series": "_PATCH-",
"company": company,
"posting_date": today,
"fiscal_year": fiscal_year,
"voucher_type": "Journal Entry",
"user_remark": "Accounting Entry for Stock: \
Initial booking of stock received but not billed account"
},
{
"doctype": "Journal Voucher Detail",
"parentfield": "entries",
"account": get_company_default(company, "stock_received_but_not_billed"),
(stock_rbnb_value > 0 and "credit" or "debit"): abs(stock_rbnb_value)
},
{
"doctype": "Journal Voucher Detail",
"parentfield": "entries",
"account": get_company_default(company, "stock_adjustment_account"),
(stock_rbnb_value > 0 and "debit" or "credit"): abs(stock_rbnb_value),
"cost_center": get_company_default(company, "stock_adjustment_cost_center")
},
])
jv.insert()
jv.submit()
jv_list.append(jv.doc.name)
if jv_list:
webnotes.msgprint("""Folowing Journal Vouchers has been created automatically:
%s""" % '\n'.join(jv_list))
webnotes.msgprint("""Please refresh the system to get effect of Auto Inventory Accounting""")
jv = webnotes.bean([
{
"doctype": "Journal Voucher",
"naming_series": "_PATCH-",
"company": company,
"posting_date": today,
"fiscal_year": fiscal_year,
"voucher_type": "Journal Entry"
},
{
"doctype": "Journal Voucher Detail",
"parentfield": "entries",
"account": get_company_default(company, "stock_received_but_not_billed"),
(reverse and "debit" or "credit"): stock_rbnb_value
},
{
"doctype": "Journal Voucher Detail",
"parentfield": "entries",
"account": get_company_default(company, "stock_adjustment_account"),
(reverse and "credit" or "debit"): stock_rbnb_value
},
])
jv.insert()
jv.submit()
def get_stock_rbnb_value(company):
total_received_amount = webnotes.conn.sql("""select sum(valuation_rate*qty)
def get_stock_rbnb_value(company):
total_received_amount = webnotes.conn.sql("""select sum(valuation_rate*qty*conversion_factor)
from `tabPurchase Receipt Item` pr_item where docstatus=1
and exists(select name from `tabItem` where name = pr_item.item_code
and is_stock_item='Yes')
and exists(select name from `tabPurchase Receipt`
where name = pr_item.parent and company = %s)""", company)
total_billed_amount = webnotes.conn.sql("""select sum(valuation_rate*qty)
total_billed_amount = webnotes.conn.sql("""select sum(valuation_rate*qty*conversion_factor)
from `tabPurchase Invoice Item` pi_item where docstatus=1
and exists(select name from `tabItem` where name = pi_item.item_code
and is_stock_item='Yes')
and exists(select name from `tabPurchase Invoice`
where name = pi_item.parent and company = %s)""", company)
return flt(total_received_amount[0][0]) - flt(total_billed_amount[0][0])