mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 00:44:45 +00:00
Merge branch 'master' of https://github.com/webnotes/erpnext
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-02-22 01:27:40",
|
||||
"creation": "2013-03-08 15:36:47",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-03-07 07:03:29",
|
||||
"modified": "2013-03-22 16:45:28",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "wasim@webnotestech.com"
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"autoname": "PVTD.######",
|
||||
@@ -26,6 +26,17 @@
|
||||
"doctype": "DocType",
|
||||
"name": "Purchase Taxes and Charges"
|
||||
},
|
||||
{
|
||||
"default": "Valuation and Total",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "category",
|
||||
"fieldtype": "Select",
|
||||
"label": "Consider Tax or Charge for",
|
||||
"oldfieldname": "category",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "Valuation and Total\nValuation\nTotal",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "charge_type",
|
||||
@@ -105,17 +116,6 @@
|
||||
"oldfieldname": "row_id",
|
||||
"oldfieldtype": "Data"
|
||||
},
|
||||
{
|
||||
"default": "Valuation and Total",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "category",
|
||||
"fieldtype": "Select",
|
||||
"label": "Consider Tax or Charge for",
|
||||
"oldfieldname": "category",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "Valuation and Total\nValuation\nTotal",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"default": "Add",
|
||||
"doctype": "DocField",
|
||||
|
||||
@@ -27,8 +27,6 @@ from webnotes.model.bean import getlist
|
||||
from webnotes.model.code import get_obj
|
||||
from webnotes import _, msgprint
|
||||
|
||||
from stock.utils import get_buying_amount, get_sales_bom
|
||||
|
||||
session = webnotes.session
|
||||
|
||||
month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12}
|
||||
@@ -701,19 +699,9 @@ class DocType(SellingController):
|
||||
})
|
||||
)
|
||||
|
||||
def make_item_gl_entries(self, gl_entries):
|
||||
# item gl entries
|
||||
auto_inventory_accounting = \
|
||||
cint(webnotes.defaults.get_global_default("auto_inventory_accounting"))
|
||||
|
||||
if auto_inventory_accounting:
|
||||
if cint(self.doc.is_pos) and cint(self.doc.update_stock):
|
||||
stock_account = self.get_default_account("stock_in_hand_account")
|
||||
else:
|
||||
stock_account = self.get_default_account("stock_delivered_but_not_billed")
|
||||
|
||||
def make_item_gl_entries(self, gl_entries):
|
||||
# income account gl entries
|
||||
for item in self.doclist.get({"parentfield": "entries"}):
|
||||
# income account gl entries
|
||||
if flt(item.amount):
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
@@ -725,28 +713,16 @@ class DocType(SellingController):
|
||||
})
|
||||
)
|
||||
|
||||
# expense account gl entries
|
||||
if auto_inventory_accounting and flt(item.buying_amount):
|
||||
# expense account gl entries
|
||||
if cint(webnotes.defaults.get_global_default("auto_inventory_accounting")) \
|
||||
and cint(self.doc.is_pos) and cint(self.doc.update_stock):
|
||||
|
||||
for item in self.doclist.get({"parentfield": "entries"}):
|
||||
self.check_expense_account(item)
|
||||
|
||||
gl_entries += self.get_gl_entries_for_stock(item.expense_account,
|
||||
-1*item.buying_amount, cost_center=item.cost_center)
|
||||
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": item.expense_account,
|
||||
"against": stock_account,
|
||||
"debit": item.buying_amount,
|
||||
"remarks": self.doc.remarks or "Accounting Entry for Stock",
|
||||
"cost_center": item.cost_center
|
||||
})
|
||||
)
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": stock_account,
|
||||
"against": item.expense_account,
|
||||
"credit": item.buying_amount,
|
||||
"remarks": self.doc.remarks or "Accounting Entry for Stock"
|
||||
})
|
||||
)
|
||||
|
||||
def make_pos_gl_entries(self, gl_entries):
|
||||
if cint(self.doc.is_pos) and self.doc.cash_bank_account and self.doc.paid_amount:
|
||||
# POS, make payment entries
|
||||
@@ -789,42 +765,6 @@ class DocType(SellingController):
|
||||
"cost_center": self.doc.write_off_cost_center
|
||||
})
|
||||
)
|
||||
|
||||
def set_buying_amount(self):
|
||||
if cint(self.doc.is_pos) and cint(self.doc.update_stock):
|
||||
stock_ledger_entries = self.get_stock_ledger_entries()
|
||||
item_sales_bom = get_sales_bom()
|
||||
else:
|
||||
stock_ledger_entries = item_sales_bom = None
|
||||
|
||||
for item in self.doclist.get({"parentfield": "entries"}):
|
||||
if item.item_code in self.stock_items or \
|
||||
(item_sales_bom and item_sales_bom.get(item.item_code)):
|
||||
item.buying_amount = self.get_item_buying_amount(item, stock_ledger_entries,
|
||||
item_sales_bom)
|
||||
webnotes.conn.set_value("Sales Invoice Item", item.name,
|
||||
"buying_amount", item.buying_amount)
|
||||
|
||||
def get_item_buying_amount(self, item, stock_ledger_entries, item_sales_bom):
|
||||
item_buying_amount = 0
|
||||
if stock_ledger_entries:
|
||||
# is pos and update stock
|
||||
item_buying_amount = get_buying_amount(item.item_code, item.warehouse, -1*item.qty,
|
||||
self.doc.doctype, self.doc.name, item.name, stock_ledger_entries, item_sales_bom)
|
||||
item.buying_amount = item_buying_amount > 0 and item_buying_amount or 0
|
||||
elif item.delivery_note and item.dn_detail:
|
||||
# against delivery note
|
||||
dn_item = webnotes.conn.get_value("Delivery Note Item", item.dn_detail,
|
||||
["buying_amount", "qty"], as_dict=1)
|
||||
item_buying_rate = flt(dn_item.buying_amount) / flt(dn_item.qty)
|
||||
item_buying_amount = item_buying_rate * flt(item.qty)
|
||||
|
||||
return item_buying_amount
|
||||
|
||||
def check_expense_account(self, item):
|
||||
if not item.expense_account:
|
||||
msgprint(_("""Expense account is mandatory for item: """) + item.item_code,
|
||||
raise_exception=1)
|
||||
|
||||
def update_c_form(self):
|
||||
"""Update amended id in C-form"""
|
||||
|
||||
@@ -86,68 +86,6 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
|
||||
self.assertEquals(gle_count[0][0], 8)
|
||||
|
||||
def test_sales_invoice_gl_entry_with_aii_delivery_note(self):
|
||||
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
|
||||
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
|
||||
|
||||
self._insert_purchase_receipt()
|
||||
dn = self._insert_delivery_note()
|
||||
|
||||
si_against_dn = webnotes.copy_doclist(test_records[1])
|
||||
si_against_dn[1]["delivery_note"] = dn.doc.name
|
||||
si_against_dn[1]["dn_detail"] = dn.doclist[1].name
|
||||
si = webnotes.bean(si_against_dn)
|
||||
si.insert()
|
||||
|
||||
si.submit()
|
||||
|
||||
gl_entries = webnotes.conn.sql("""select account, debit, credit
|
||||
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
|
||||
order by account asc""", si.doc.name, as_dict=1)
|
||||
self.assertTrue(gl_entries)
|
||||
|
||||
expected_values = sorted([
|
||||
[si.doc.debit_to, 630.0, 0.0],
|
||||
[test_records[1][1]["income_account"], 0.0, 500.0],
|
||||
[test_records[1][2]["account_head"], 0.0, 80.0],
|
||||
[test_records[1][3]["account_head"], 0.0, 50.0],
|
||||
["Stock Delivered But Not Billed - _TC", 0.0, 375.0],
|
||||
[test_records[1][1]["expense_account"], 375.0, 0.0]
|
||||
])
|
||||
for i, gle in enumerate(gl_entries):
|
||||
self.assertEquals(expected_values[i][0], gle.account)
|
||||
self.assertEquals(expected_values[i][1], gle.debit)
|
||||
self.assertEquals(expected_values[i][2], gle.credit)
|
||||
|
||||
si.cancel()
|
||||
gl_entries = webnotes.conn.sql("""select account, debit, credit
|
||||
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
|
||||
and ifnull(is_cancelled, 'No') = 'No'
|
||||
order by account asc, name asc""", si.doc.name, as_dict=1)
|
||||
|
||||
expected_values = sorted([
|
||||
[si.doc.debit_to, 630.0, 0.0],
|
||||
[si.doc.debit_to, 0.0, 630.0],
|
||||
[test_records[1][1]["income_account"], 0.0, 500.0],
|
||||
[test_records[1][1]["income_account"], 500.0, 0.0],
|
||||
[test_records[1][2]["account_head"], 0.0, 80.0],
|
||||
[test_records[1][2]["account_head"], 80.0, 0.0],
|
||||
[test_records[1][3]["account_head"], 0.0, 50.0],
|
||||
[test_records[1][3]["account_head"], 50.0, 0.0],
|
||||
["Stock Delivered But Not Billed - _TC", 0.0, 375.0],
|
||||
["Stock Delivered But Not Billed - _TC", 375.0, 0.0],
|
||||
[test_records[1][1]["expense_account"], 375.0, 0.0],
|
||||
[test_records[1][1]["expense_account"], 0.0, 375.0]
|
||||
|
||||
])
|
||||
for i, gle in enumerate(gl_entries):
|
||||
self.assertEquals(expected_values[i][0], gle.account)
|
||||
self.assertEquals(expected_values[i][1], gle.debit)
|
||||
self.assertEquals(expected_values[i][2], gle.credit)
|
||||
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
|
||||
|
||||
def test_pos_gl_entry_with_aii(self):
|
||||
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
|
||||
@@ -262,8 +200,6 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
|
||||
|
||||
|
||||
|
||||
def _insert_purchase_receipt(self):
|
||||
from stock.doctype.purchase_receipt.test_purchase_receipt import test_records \
|
||||
as pr_test_records
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-03-07 11:42:55",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-03-18 15:41:19",
|
||||
"modified": "2013-03-21 18:35:47",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -207,11 +207,10 @@
|
||||
"width": "120px"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:sys_defaults.auto_inventory_accounting",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "expense_account",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"hidden": 1,
|
||||
"in_filter": 1,
|
||||
"label": "Expense Account",
|
||||
"options": "Account",
|
||||
|
||||
@@ -6,6 +6,18 @@ wn.query_reports["Gross Profit"] = {
|
||||
"fieldtype": "Link",
|
||||
"options": "Company",
|
||||
"default": wn.defaults.get_user_default("company")
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldname":"from_date",
|
||||
"label": "From Date",
|
||||
"fieldtype": "Date",
|
||||
"default": wn.defaults.get_user_default("year_start_date")
|
||||
},
|
||||
{
|
||||
"fieldname":"to_date",
|
||||
"label": "To Date",
|
||||
"fieldtype": "Date",
|
||||
"default": wn.defaults.get_user_default("year_end_date")
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -1,31 +1,29 @@
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes.utils import flt
|
||||
from stock.utils import get_buying_amount, get_sales_bom
|
||||
from stock.utils import get_buying_amount
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters = {}
|
||||
|
||||
stock_ledger_entries = get_stock_ledger_entries(filters)
|
||||
item_sales_bom = get_sales_bom()
|
||||
|
||||
delivery_note_items = webnotes.conn.sql("""select dn.name, dn.posting_date, dn.posting_time,
|
||||
dn.project_name, item.item_code, item.item_name, item.description, item.warehouse,
|
||||
item.qty, item.basic_rate, item.amount, item.name as "item_row"
|
||||
from `tabDelivery Note` dn, `tabDelivery Note Item` item
|
||||
where item.parent = dn.name and dn.docstatus = 1
|
||||
order by dn.posting_date desc, dn.posting_time desc""", as_dict=1)
|
||||
source = get_source_data(filters)
|
||||
|
||||
columns = ["Delivery Note:Link/Delivery Note", "Posting Date:Date", "Posting Time",
|
||||
item_sales_bom = get_item_sales_bom()
|
||||
|
||||
columns = ["Delivery Note/Sales Invoice::120", "Posting Date:Date", "Posting Time",
|
||||
"Item Code:Link/Item", "Item Name", "Description", "Warehouse:Link/Warehouse",
|
||||
"Qty:Float", "Selling Rate:Currency", "Selling Amount:Currency", "Buying Amount:Currency",
|
||||
"Gross Profit:Currency", "Gross Profit %:Percent", "Project:Link/Project"]
|
||||
|
||||
|
||||
data = []
|
||||
for row in delivery_note_items:
|
||||
for row in source:
|
||||
selling_amount = flt(row.amount)
|
||||
buying_amount = get_buying_amount(row.item_code, row.warehouse, -1*row.qty,
|
||||
"Delivery Note", row.name, row.item_row, stock_ledger_entries, item_sales_bom)
|
||||
row.parenttype, row.name, row.item_row, stock_ledger_entries,
|
||||
item_sales_bom.get(row.parenttype, {}).get(row.name, webnotes._dict()))
|
||||
|
||||
buying_amount = buying_amount > 0 and buying_amount or 0
|
||||
|
||||
if selling_amount:
|
||||
@@ -34,7 +32,8 @@ def execute(filters=None):
|
||||
else:
|
||||
gross_profit = gross_profit_percent = 0.0
|
||||
|
||||
data.append([row.name, row.posting_date, row.posting_time, row.item_code, row.item_name,
|
||||
name = """<a href="%s">%s</a>""" % ("/".join(["#Form", row.parenttype, row.name]), row.name)
|
||||
data.append([name, row.posting_date, row.posting_time, row.item_code, row.item_name,
|
||||
row.description, row.warehouse, row.qty, row.basic_rate, row.amount, buying_amount,
|
||||
gross_profit, gross_profit_percent, row.project])
|
||||
|
||||
@@ -44,7 +43,8 @@ def get_stock_ledger_entries(filters):
|
||||
query = """select item_code, voucher_type, voucher_no,
|
||||
voucher_detail_no, posting_date, posting_time, stock_value,
|
||||
warehouse, actual_qty as qty
|
||||
from `tabStock Ledger Entry` where ifnull(`is_cancelled`, "No") = "No" """
|
||||
from `tabStock Ledger Entry`
|
||||
where ifnull(`is_cancelled`, "No") = "No" """
|
||||
|
||||
if filters.get("company"):
|
||||
query += """ and company=%(company)s"""
|
||||
@@ -52,3 +52,48 @@ def get_stock_ledger_entries(filters):
|
||||
query += " order by item_code desc, warehouse desc, posting_date desc, posting_time desc, name desc"
|
||||
|
||||
return webnotes.conn.sql(query, filters, as_dict=True)
|
||||
|
||||
def get_item_sales_bom():
|
||||
item_sales_bom = {}
|
||||
|
||||
for d in webnotes.conn.sql("""select parenttype, parent, parent_item,
|
||||
item_code, warehouse, -1*qty as total_qty
|
||||
from `tabDelivery Note Packing Item` where docstatus=1""", as_dict=True):
|
||||
item_sales_bom.setdefault(d.parenttype, webnotes._dict()).setdefault(d.parent,
|
||||
webnotes._dict()).setdefault(d.parent_item, []).append(d)
|
||||
|
||||
return item_sales_bom
|
||||
|
||||
def get_source_data(filters):
|
||||
conditions = ""
|
||||
if filters.get("company"):
|
||||
conditions += " and company=%(company)s"
|
||||
if filters.get("from_date"):
|
||||
conditions += " and posting_date>=%(from_date)s"
|
||||
if filters.get("to_date"):
|
||||
conditions += " and posting_date<=%(to_date)s"
|
||||
|
||||
delivery_note_items = webnotes.conn.sql("""select item.parenttype, dn.name,
|
||||
dn.posting_date, dn.posting_time, dn.project_name,
|
||||
item.item_code, item.item_name, item.description, item.warehouse,
|
||||
item.qty, item.basic_rate, item.amount, item.name as "item_row",
|
||||
timestamp(dn.posting_date, dn.posting_time) as posting_datetime
|
||||
from `tabDelivery Note` dn, `tabDelivery Note Item` item
|
||||
where item.parent = dn.name and dn.docstatus = 1 %s
|
||||
order by dn.posting_date desc, dn.posting_time desc""" % (conditions,), filters, as_dict=1)
|
||||
|
||||
sales_invoice_items = webnotes.conn.sql("""select item.parenttype, si.name,
|
||||
si.posting_date, si.posting_time, si.project_name,
|
||||
item.item_code, item.item_name, item.description, item.warehouse,
|
||||
item.qty, item.basic_rate, item.amount, item.name as "item_row",
|
||||
timestamp(si.posting_date, si.posting_time) as posting_datetime
|
||||
from `tabSales Invoice` si, `tabSales Invoice Item` item
|
||||
where item.parent = si.name and si.docstatus = 1 %s
|
||||
and si.is_pos = 1 and si.update_stock = 1
|
||||
order by si.posting_date desc, si.posting_time desc""" % (conditions,), filters, as_dict=1)
|
||||
|
||||
source = delivery_note_items + sales_invoice_items
|
||||
if len(source) > len(delivery_note_items):
|
||||
source.sort(key=lambda d: d.posting_datetime, reverse=True)
|
||||
|
||||
return source
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
report.customize_filters = function() {
|
||||
this.hide_all_filters();
|
||||
this.dt.set_no_limit(1);
|
||||
|
||||
// hide transaction based on permissions
|
||||
var all_transactions = ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice",
|
||||
|
||||
Reference in New Issue
Block a user