Merge https://github.com/frappe/erpnext into purchase-invoice-fix
This commit is contained in:
commit
bf4ceb981f
@ -135,8 +135,10 @@ def get_pricing_rule_for_item(args):
|
||||
frappe.throw(_("Item Group not mentioned in item master for item {0}").format(args.item_code))
|
||||
|
||||
if args.customer and not (args.customer_group and args.territory):
|
||||
args.customer_group, args.territory = frappe.db.get_value("Customer", args.customer,
|
||||
["customer_group", "territory"])
|
||||
customer = frappe.db.get_value("Customer", args.customer, ["customer_group", "territory"])
|
||||
if customer:
|
||||
args.customer_group, args.territory = customer
|
||||
|
||||
elif args.supplier and not args.supplier_type:
|
||||
args.supplier_type = frappe.db.get_value("Supplier", args.supplier, "supplier_type")
|
||||
|
||||
|
@ -263,10 +263,10 @@ class PurchaseInvoice(BuyingController):
|
||||
def make_gl_entries(self):
|
||||
auto_accounting_for_stock = \
|
||||
cint(frappe.defaults.get_global_default("auto_accounting_for_stock"))
|
||||
|
||||
|
||||
stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed")
|
||||
expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")
|
||||
|
||||
|
||||
gl_entries = []
|
||||
|
||||
# parent's gl entry
|
||||
@ -319,32 +319,31 @@ class PurchaseInvoice(BuyingController):
|
||||
"cost_center": item.cost_center
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
if auto_accounting_for_stock and item.item_code in stock_items and item.item_tax_amount:
|
||||
# Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt
|
||||
negative_expense_booked_in_pi = None
|
||||
if item.purchase_receipt:
|
||||
negative_expense_booked_in_pi = frappe.db.sql("""select name from `tabGL Entry`
|
||||
where voucher_type='Purchase Receipt' and voucher_no=%s and account=%s""",
|
||||
where voucher_type='Purchase Receipt' and voucher_no=%s and account=%s""",
|
||||
(item.purchase_receipt, expenses_included_in_valuation))
|
||||
|
||||
|
||||
if not negative_expense_booked_in_pi:
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": stock_received_but_not_billed,
|
||||
"against": self.credit_to,
|
||||
"debit": flt(item.item_tax_amount),
|
||||
"debit": flt(item.item_tax_amount, self.precision("item_tax_amount", item)),
|
||||
"remarks": self.remarks or "Accounting Entry for Stock"
|
||||
})
|
||||
)
|
||||
|
||||
negative_expense_to_be_booked += flt(item.item_tax_amount)
|
||||
|
||||
negative_expense_to_be_booked += flt(item.item_tax_amount, self.precision("item_tax_amount", item))
|
||||
|
||||
if negative_expense_to_be_booked and valuation_tax:
|
||||
# credit valuation tax amount in "Expenses Included In Valuation"
|
||||
# this will balance out valuation amount included in cost of goods sold
|
||||
|
||||
|
||||
total_valuation_amount = sum(valuation_tax.values())
|
||||
amount_including_divisional_loss = negative_expense_to_be_booked
|
||||
i = 1
|
||||
@ -354,7 +353,7 @@ class PurchaseInvoice(BuyingController):
|
||||
else:
|
||||
applicable_amount = negative_expense_to_be_booked * (amount / total_valuation_amount)
|
||||
amount_including_divisional_loss -= applicable_amount
|
||||
|
||||
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": expenses_included_in_valuation,
|
||||
@ -364,7 +363,7 @@ class PurchaseInvoice(BuyingController):
|
||||
"remarks": self.remarks or "Accounting Entry for Stock"
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
i += 1
|
||||
|
||||
# writeoff account includes petty difference in the invoice amount
|
||||
|
@ -4,6 +4,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.utils import flt
|
||||
from frappe import _
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters = {}
|
||||
@ -15,25 +16,38 @@ def execute(filters=None):
|
||||
data = get_entries(filters)
|
||||
|
||||
from erpnext.accounts.utils import get_balance_on
|
||||
balance_as_per_company = get_balance_on(filters["account"], filters["report_date"])
|
||||
balance_as_per_system = get_balance_on(filters["account"], filters["report_date"])
|
||||
|
||||
total_debit, total_credit = 0,0
|
||||
for d in data:
|
||||
total_debit += flt(d[2])
|
||||
total_credit += flt(d[3])
|
||||
|
||||
bank_bal = flt(balance_as_per_company) - flt(total_debit) + flt(total_credit)
|
||||
amounts_not_reflected_in_system = frappe.db.sql("""select sum(ifnull(jvd.debit, 0) - ifnull(jvd.credit, 0))
|
||||
from `tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv
|
||||
where jvd.parent = jv.name and jv.docstatus=1 and jvd.account=%s
|
||||
and jv.posting_date > %s and jv.clearance_date <= %s
|
||||
""", (filters["account"], filters["report_date"], filters["report_date"]))
|
||||
|
||||
amounts_not_reflected_in_system = flt(amounts_not_reflected_in_system[0][0]) \
|
||||
if amounts_not_reflected_in_system else 0.0
|
||||
|
||||
bank_bal = flt(balance_as_per_system) - flt(total_debit) + flt(total_credit) \
|
||||
+ amounts_not_reflected_in_system
|
||||
|
||||
data += [
|
||||
get_balance_row("Balance as per company books", balance_as_per_company),
|
||||
["", "Amounts not reflected in bank", total_debit, total_credit, "", "", "", ""],
|
||||
get_balance_row("Balance as per bank", bank_bal)
|
||||
get_balance_row(_("System Balance"), balance_as_per_system),
|
||||
[""]*len(columns),
|
||||
["", _("Amounts not reflected in bank"), total_debit, total_credit, "", "", "", ""],
|
||||
get_balance_row(_("Amounts not reflected in system"), amounts_not_reflected_in_system),
|
||||
[""]*len(columns),
|
||||
get_balance_row(_("Expected balance as per bank"), bank_bal)
|
||||
]
|
||||
|
||||
return columns, data
|
||||
|
||||
def get_columns():
|
||||
return ["Posting Date:Date:100", "Journal Voucher:Link/Journal Voucher:200",
|
||||
return ["Posting Date:Date:100", "Journal Voucher:Link/Journal Voucher:220",
|
||||
"Debit:Currency:120", "Credit:Currency:120",
|
||||
"Against Account:Link/Account:200", "Reference::100", "Ref Date:Date:110", "Clearance Date:Date:110"
|
||||
]
|
||||
@ -55,4 +69,4 @@ def get_balance_row(label, amount):
|
||||
if amount > 0:
|
||||
return ["", label, amount, 0, "", "", "", ""]
|
||||
else:
|
||||
return ["", label, 0, amount, "", "", "", ""]
|
||||
return ["", label, 0, abs(amount), "", "", "", ""]
|
||||
|
@ -209,7 +209,7 @@ class AccountsController(TransactionBase):
|
||||
|
||||
def calculate_taxes(self):
|
||||
# maintain actual tax rate based on idx
|
||||
actual_tax_dict = dict([[tax.idx, tax.rate] for tax in self.tax_doclist
|
||||
actual_tax_dict = dict([[tax.idx, flt(tax.rate, self.precision("tax_amount", tax))] for tax in self.tax_doclist
|
||||
if tax.charge_type == "Actual"])
|
||||
|
||||
for n, item in enumerate(self.item_doclist):
|
||||
|
@ -166,21 +166,19 @@ class StockController(AccountsController):
|
||||
|
||||
|
||||
def get_future_stock_vouchers(self):
|
||||
future_stock_vouchers = []
|
||||
|
||||
if hasattr(self, "fname"):
|
||||
condition = ""
|
||||
item_list = []
|
||||
if getattr(self, "fname", None):
|
||||
item_list = [d.item_code for d in self.get(self.fname)]
|
||||
condition = ''.join(['and item_code in (\'', '\', \''.join(item_list) ,'\')'])
|
||||
else:
|
||||
condition = ""
|
||||
if item_list:
|
||||
condition = "and item_code in ({})".format(", ".join(["%s"] * len(item_list)))
|
||||
|
||||
for d in frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no
|
||||
future_stock_vouchers = frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no
|
||||
from `tabStock Ledger Entry` sle
|
||||
where timestamp(sle.posting_date, sle.posting_time) >= timestamp(%s, %s) %s
|
||||
order by timestamp(sle.posting_date, sle.posting_time) asc, name asc""" %
|
||||
('%s', '%s', condition), (self.posting_date, self.posting_time),
|
||||
as_dict=True):
|
||||
future_stock_vouchers.append([d.voucher_type, d.voucher_no])
|
||||
where timestamp(sle.posting_date, sle.posting_time) >= timestamp(%s, %s) {condition}
|
||||
order by timestamp(sle.posting_date, sle.posting_time) asc, name asc""".format(
|
||||
condition=condition), tuple([self.posting_date, self.posting_date] + item_list),
|
||||
as_list=True)
|
||||
|
||||
return future_stock_vouchers
|
||||
|
||||
|
@ -324,7 +324,7 @@ class ProductionPlanningTool(Document):
|
||||
total_qty = sum([flt(d[0]) for d in so_item_qty])
|
||||
if total_qty > item_projected_qty.get(item, 0):
|
||||
# shortage
|
||||
requested_qty = total_qty - item_projected_qty.get(item, 0)
|
||||
requested_qty = total_qty - flt(item_projected_qty.get(item))
|
||||
# consider minimum order qty
|
||||
requested_qty = requested_qty > flt(so_item_qty[0][3]) and \
|
||||
requested_qty or flt(so_item_qty[0][3])
|
||||
|
@ -647,7 +647,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
||||
// maintain actual tax rate based on idx
|
||||
$.each(this.frm.tax_doclist, function(i, tax) {
|
||||
if (tax.charge_type == "Actual") {
|
||||
actual_tax_dict[tax.idx] = flt(tax.rate);
|
||||
actual_tax_dict[tax.idx] = flt(tax.rate, precision("tax_amount", tax));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -19,8 +19,7 @@ cur_frm.cscript.set_root_readonly = function(doc) {
|
||||
|
||||
//get query select Customer Group
|
||||
cur_frm.fields_dict['parent_customer_group'].get_query = function(doc,cdt,cdn) {
|
||||
return{
|
||||
searchfield:['name', 'parent_customer_group'],
|
||||
return {
|
||||
filters: {
|
||||
'is_group': "Yes"
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
|
||||
title: __("Get Items from BOM"),
|
||||
fields: [
|
||||
{"fieldname":"bom", "fieldtype":"Link", "label":__("BOM"),
|
||||
options:"BOM"},
|
||||
options:"BOM", reqd: 1},
|
||||
{"fieldname":"fetch_exploded", "fieldtype":"Check",
|
||||
"label":__("Fetch exploded BOM (including sub-assemblies)"), "default":1},
|
||||
{fieldname:"fetch", "label":__("Get Items from BOM"), "fieldtype":"Button"}
|
||||
|
Loading…
Reference in New Issue
Block a user