[fixes] fix perpetual inventory

This commit is contained in:
Saurabh 2016-03-18 14:40:03 +05:30 committed by Nabin Hait
parent bd5fc8ecbe
commit 4bd34a58ba
7 changed files with 139 additions and 188 deletions

View File

@ -25,22 +25,20 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
// Show / Hide button
this.show_general_ledger();
if(!doc.is_return) {
if(doc.docstatus==1) {
if(!doc.is_return && doc.docstatus==1) {
if(doc.outstanding_amount > 0) {
this.frm.add_custom_button(__('Payment'), this.make_bank_entry, __("Make"));
cur_frm.page.set_inner_btn_group_as_primary(__("Make"));
}
if (!doc.make_receipt) {
if(doc.outstanding_amount >= 0 || Math.abs(flt(doc.outstanding_amount)) < flt(doc.grand_total)) {
cur_frm.add_custom_button(__('Debit Note'), this.make_debit_note, __("Make"));
}
}
else {
cur_frm.add_custom_button(__('Return'), this.make_debit_note, __("Make"));
cur_frm.add_custom_button(doc.update_stock ? __('Purchase Return') : __('Debit Note'),
this.make_debit_note, __("Make"));
}
if(doc.update_stock==1) {
this.show_stock_ledger();
}
}
if(doc.docstatus===0) {
@ -71,53 +69,6 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
})
}, __("Get items from"));
}
}
if(doc.docstatus==1 && doc.make_receipt==1) {
this.show_stock_ledger();
}
},
received_qty: function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["qty", "received_qty"]);
item.qty = (item.qty < item.received_qty) ? item.qty : item.received_qty;
this.qty(doc, cdt, cdn);
},
qty: function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["qty", "received_qty"]);
if(!(item.received_qty || item.rejected_qty) && item.qty) {
item.received_qty = item.qty;
}
if(item.qty > item.received_qty) {
msgprint(__("Error: {0} > {1}", [__(frappe.meta.get_label(item.doctype, "qty", item.name)),
__(frappe.meta.get_label(item.doctype, "received_qty", item.name))]))
item.qty = item.rejected_qty = 0.0;
} else {
item.rejected_qty = flt(item.received_qty - item.qty, precision("rejected_qty", item));
}
this._super(doc, cdt, cdn);
},
rejected_qty: function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["received_qty", "rejected_qty"]);
if(item.rejected_qty > item.received_qty) {
msgprint(__("Error: {0} > {1}", [__(frappe.meta.get_label(item.doctype, "rejected_qty", item.name)),
__(frappe.meta.get_label(item.doctype, "received_qty", item.name))]));
item.qty = item.rejected_qty = 0.0;
} else {
item.qty = flt(item.received_qty - item.rejected_qty, precision("qty", item));
}
this.qty(doc, cdt, cdn);
},
supplier: function() {
@ -156,11 +107,11 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
}
},
is_cash: function() {
is_paid: function() {
cur_frm.cscript.hide_fields(this.frm.doc);
if(cint(this.frm.doc.is_cash)) {
if(cint(this.frm.doc.is_paid)) {
if(!this.frm.doc.company) {
this.frm.set_value("is_cash", 0);
this.frm.set_value("x", 0);
msgprint(__("Please specify Company to proceed"));
}
}
@ -216,7 +167,7 @@ cur_frm.script_manager.make(erpnext.accounts.PurchaseInvoice);
cur_frm.cscript.hide_fields = function(doc) {
par_flds = ['due_date', 'is_opening', 'advances_section', 'from_date', 'to_date'];
if(cint(doc.is_cash) == 1) {
if(cint(doc.is_paid) == 1) {
hide_field(par_flds);
} else {
for (i in par_flds) {
@ -226,21 +177,21 @@ cur_frm.cscript.hide_fields = function(doc) {
}
item_flds_stock = ['sc_wh', 'received_qty', 'rejected_qty'];
item_flds_stock = ['warehouse_section', 'received_qty', 'rejected_qty'];
//item_flds_stock = ['serial_no', 'batch_no', 'actual_qty', 'expense_account', 'warehouse', 'expense_account', 'warehouse']
cur_frm.fields_dict['items'].grid.set_column_disp(item_flds_stock,
(cint(doc.make_receipt)==1 ? true : false));
(cint(doc.update_stock)==1 ? true : false));
cur_frm.refresh_fields();
}
cur_frm.cscript.make_receipt = function(doc, dt, dn) {
cur_frm.cscript.update_stock = function(doc, dt, dn) {
cur_frm.cscript.hide_fields(doc, dt, dn);
}
cur_frm.cscript.mode_of_payment = function(doc) {
if(doc.is_cash) {
if(doc.is_paid) {
return cur_frm.call({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
args: {

View File

@ -276,14 +276,15 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "is_return",
"default": "0",
"fieldname": "is_paid",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Is Return",
"label": "Is Paid",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@ -805,14 +806,14 @@
"bold": 0,
"collapsible": 0,
"default": "0",
"fieldname": "make_receipt",
"fieldname": "update_stock",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Make Receipt (Update Stock)",
"label": "Update Stock",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@ -1691,8 +1692,8 @@
"bold": 0,
"collapsible": 1,
"collapsible_depends_on": "paid_amount",
"depends_on": "eval:doc.is_cash===1",
"fieldname": "sc_br_payments",
"depends_on": "eval:doc.is_paid===1",
"fieldname": "payments_section",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
@ -2440,33 +2441,6 @@
"unique": 0,
"width": "100px"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "fiscal_year",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 1,
"in_list_view": 0,
"label": "Fiscal Year",
"length": 0,
"no_copy": 0,
"oldfieldname": "fiscal_year",
"oldfieldtype": "Select",
"options": "Fiscal Year",
"permlevel": 0,
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@ -2953,7 +2927,7 @@
],
"read_only": 0,
"read_only_onload": 1,
"search_fields": "posting_date, supplier, fiscal_year, bill_no, base_grand_total, outstanding_amount",
"search_fields": "posting_date, supplier, bill_no, base_grand_total, outstanding_amount",
"sort_field": "modified",
"sort_order": "DESC",
"timeline_field": "supplier",

View File

@ -12,6 +12,7 @@ from erpnext.controllers.buying_controller import BuyingController
from erpnext.accounts.party import get_party_account, get_due_date
from erpnext.accounts.utils import get_account_currency, get_fiscal_year
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import update_billed_amount_based_on_po
from erpnext.controllers.stock_controller import get_warehouse_account
form_grid_templates = {
@ -47,11 +48,11 @@ class PurchaseInvoice(BuyingController):
self.validate_advance_jv("Purchase Order")
# validate cash purchase
if (self.is_cash == 1):
if (self.is_paid == 1):
self.validate_cash()
# validate stock items
if (self.make_receipt == 1):
if (self.update_stock == 1):
self.validate_purchase_return()
self.validate_rejected_warehouse()
self.validate_accepted_rejected_qty()
@ -286,7 +287,7 @@ class PurchaseInvoice(BuyingController):
reconcile_against_document(lst)
def update_status_updater_args(self):
if cint(self.make_receipt):
if cint(self.update_stock):
self.status_updater.extend([{
'source_dt': 'Purchase Invoice Item',
'target_dt': 'Purchase Order Item',
@ -300,7 +301,7 @@ class PurchaseInvoice(BuyingController):
# 'percent_join_field': 'prevdoc_docname',
'overflow_type': 'receipt',
'extra_cond': """ and exists(select name from `tabPurchase Invoice`
where name=`tabPurchase Invoice Item`.parent and make_receipt = 1)"""
where name=`tabPurchase Invoice Item`.parent and update_stock = 1)"""
},
{
'source_dt': 'Purchase Invoice Item',
@ -362,17 +363,17 @@ class PurchaseInvoice(BuyingController):
self.company, self.base_grand_total)
# make purchase receipt
if (self.make_receipt == 1):
if (self.update_stock == 1):
# from erpnext.stock.doctype.purchase_receipt.purchase_receipt import update_stock_ledger
self.update_stock_ledger()
self.make_gl_entries()
from erpnext.stock.doctype.serial_no.serial_no import update_serial_nos_after_submit
update_serial_nos_after_submit(self, "items")
self.update_status_updater_args()
self.update_prevdoc_status()
# this sequence because outstanding may get -negative
self.make_gl_entries1()
self.make_gl_entries()
if not self.is_return:
self.update_against_document_in_jv()
self.update_prevdoc_status()
@ -380,6 +381,7 @@ class PurchaseInvoice(BuyingController):
self.update_billing_status_in_pr()
self.update_project()
<<<<<<< 1b49ed56bdbd4a6cdf93ede3bfa252e5a954ed41
def validate_asset(self):
for d in self.get("items"):
@ -408,6 +410,22 @@ class PurchaseInvoice(BuyingController):
if self.docstatus==1 and not asset.supplier:
frappe.db.set_value("Asset", asset.name, "supplier", self.supplier)
=======
def on_cancel(self):
if not self.is_return:
from erpnext.accounts.utils import remove_against_link_from_jv
remove_against_link_from_jv(self.doctype, self.name)
self.update_prevdoc_status()
self.update_billing_status_for_zero_amount_refdoc("Purchase Order")
self.update_billing_status_in_pr()
self.update_stock_ledger()
self.make_gl_entries_on_cancel()
self.update_project()
>>>>>>> [fixes] fix perpetual inventory
def make_gl_entries(self):
auto_accounting_for_stock = \
cint(frappe.defaults.get_global_default("auto_accounting_for_stock"))
@ -418,7 +436,7 @@ class PurchaseInvoice(BuyingController):
gl_entries = []
# Make Cash GL Entries
if cint(self.is_cash) and self.cash_bank_account and self.paid_amount:
if cint(self.is_paid) and self.cash_bank_account and self.paid_amount:
bank_account_currency = get_account_currency(self.cash_bank_account)
# CASH, make payment entries
gl_entries.append(
@ -434,6 +452,7 @@ class PurchaseInvoice(BuyingController):
"against_voucher_type": self.doctype,
}, self.party_account_currency)
)
gl_entries.append(
self.get_gl_dict({
"account": self.cash_bank_account,
@ -463,7 +482,6 @@ class PurchaseInvoice(BuyingController):
"against_voucher_type": self.doctype,
}, self.party_account_currency)
)
# tax table gl entries
valuation_tax = {}
for tax in self.get("taxes"):
@ -483,7 +501,6 @@ class PurchaseInvoice(BuyingController):
"cost_center": tax.cost_center
}, account_currency)
)
# accumulate valuation tax
if self.is_opening == "No" and tax.category in ("Valuation", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
if auto_accounting_for_stock and not tax.cost_center:
@ -491,16 +508,17 @@ class PurchaseInvoice(BuyingController):
valuation_tax.setdefault(tax.cost_center, 0)
valuation_tax[tax.cost_center] += \
(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.base_tax_amount_after_discount_amount)
# item gl entries
negative_expense_to_be_booked = 0.0
stock_items = self.get_stock_items()
warehouse_account = get_warehouse_account()
for item in self.get("items"):
if flt(item.base_net_amount):
account_currency = get_account_currency(item.expense_account)
gl_entries.append(
self.get_gl_dict({
"account": item.expense_account,
"account": item.expense_account if not self.update_stock else warehouse_account[item.warehouse]["name"],
"against": self.supplier,
"debit": item.base_net_amount,
"debit_in_account_currency": item.base_net_amount \

View File

@ -221,6 +221,7 @@
"fieldtype": "Float",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Received Qty",
@ -271,6 +272,7 @@
"fieldtype": "Float",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Rejected Qty",
@ -815,10 +817,11 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "sc_wh",
"fieldname": "warehouse_section",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Warehouse",
@ -844,6 +847,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Accepted Warehouse",
@ -869,6 +873,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Rejected Warehouse",
@ -894,6 +899,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Batch No",
@ -919,6 +925,7 @@
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "",
@ -943,6 +950,7 @@
"fieldtype": "Text",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Serial No",
@ -967,6 +975,7 @@
"fieldtype": "Text",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Rejected Serial No",

View File

@ -114,8 +114,49 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
},
qty: function(doc, cdt, cdn) {
if ((doc.doctype == "Purchase Receipt") || (doc.doctype == "Purchase Invoice" && doc.update_stock)) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["qty", "received_qty"]);
if(!(item.received_qty || item.rejected_qty) && item.qty) {
item.received_qty = item.qty;
}
if(item.qty > item.received_qty) {
msgprint(__("Error: {0} > {1}", [__(frappe.meta.get_label(item.doctype, "qty", item.name)),
__(frappe.meta.get_label(item.doctype, "received_qty", item.name))]))
item.qty = item.rejected_qty = 0.0;
} else {
item.rejected_qty = flt(item.received_qty - item.qty, precision("rejected_qty", item));
}
}
this._super(doc, cdt, cdn);
this.conversion_factor(doc, cdt, cdn);
},
received_qty: function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["qty", "received_qty"]);
item.qty = (item.qty < item.received_qty) ? item.qty : item.received_qty;
this.qty(doc, cdt, cdn);
},
rejected_qty: function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["received_qty", "rejected_qty"]);
if(item.rejected_qty > item.received_qty) {
msgprint(__("Error: {0} > {1}", [__(frappe.meta.get_label(item.doctype, "rejected_qty", item.name)),
__(frappe.meta.get_label(item.doctype, "received_qty", item.name))]));
item.qty = item.rejected_qty = 0.0;
} else {
item.qty = flt(item.received_qty - item.rejected_qty, precision("qty", item));
}
this.qty(doc, cdt, cdn);
},
conversion_factor: function(doc, cdt, cdn) {

View File

@ -519,7 +519,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
if(this.frm.doc.doctype == "Sales Invoice" || this.frm.doc.doctype == "Purchase Invoice") {
frappe.model.round_floats_in(this.frm.doc, ["paid_amount"]);
if(this.frm.doc.is_pos || this.frm.doc.is_cash) {
if(this.frm.doc.is_pos || this.frm.doc.is_paid) {
if(!this.frm.doc.paid_amount || update_paid_amount===undefined || update_paid_amount) {
this.frm.doc.paid_amount = flt(total_amount_to_pay);
}

View File

@ -76,48 +76,6 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend
this.frm.toggle_reqd("supplier_warehouse", this.frm.doc.is_subcontracted==="Yes");
},
received_qty: function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["qty", "received_qty"]);
item.qty = (item.qty < item.received_qty) ? item.qty : item.received_qty;
this.qty(doc, cdt, cdn);
},
qty: function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["qty", "received_qty"]);
if(!(item.received_qty || item.rejected_qty) && item.qty) {
item.received_qty = item.qty;
}
if(item.qty > item.received_qty) {
msgprint(__("Error: {0} > {1}", [__(frappe.meta.get_label(item.doctype, "qty", item.name)),
__(frappe.meta.get_label(item.doctype, "received_qty", item.name))]))
item.qty = item.rejected_qty = 0.0;
} else {
item.rejected_qty = flt(item.received_qty - item.qty, precision("rejected_qty", item));
}
this._super(doc, cdt, cdn);
},
rejected_qty: function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["received_qty", "rejected_qty"]);
if(item.rejected_qty > item.received_qty) {
msgprint(__("Error: {0} > {1}", [__(frappe.meta.get_label(item.doctype, "rejected_qty", item.name)),
__(frappe.meta.get_label(item.doctype, "received_qty", item.name))]));
item.qty = item.rejected_qty = 0.0;
} else {
item.qty = flt(item.received_qty - item.rejected_qty, precision("qty", item));
}
this.qty(doc, cdt, cdn);
},
make_purchase_invoice: function() {
frappe.model.open_mapped_doc({
method: "erpnext.stock.doctype.purchase_receipt.purchase_receipt.make_purchase_invoice",