Merge branch 'develop' into FIX-ISS-23-24-00209

This commit is contained in:
Sagar Sharma 2023-04-20 15:46:01 +05:30 committed by GitHub
commit 81653e4762
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 132 additions and 15 deletions

View File

@ -60,6 +60,7 @@ class PaymentEntry(AccountsController):
def validate(self):
self.setup_party_account_field()
self.set_missing_values()
self.set_missing_ref_details()
self.validate_payment_type()
self.validate_party_details()
self.set_exchange_rate()
@ -219,11 +220,16 @@ class PaymentEntry(AccountsController):
else self.paid_to_account_currency
)
self.set_missing_ref_details()
def set_missing_ref_details(self, force=False):
def set_missing_ref_details(
self, force: bool = False, update_ref_details_only_for: list | None = None
) -> None:
for d in self.get("references"):
if d.allocated_amount:
if update_ref_details_only_for and (
not (d.reference_doctype, d.reference_name) in update_ref_details_only_for
):
continue
ref_details = get_reference_details(
d.reference_doctype, d.reference_name, self.party_account_currency
)
@ -1811,6 +1817,7 @@ def get_payment_entry(
pe.setup_party_account_field()
pe.set_missing_values()
pe.set_missing_ref_details()
update_accounting_dimensions(pe, doc)

View File

@ -646,6 +646,7 @@ def update_reference_in_payment_entry(d, payment_entry, do_not_save=False):
payment_entry.flags.ignore_validate_update_after_submit = True
payment_entry.setup_party_account_field()
payment_entry.set_missing_values()
payment_entry.set_missing_ref_details()
payment_entry.set_amounts()
if not do_not_save:

View File

@ -411,7 +411,6 @@ frappe.ui.form.on("BOM", {
}
frm.set_value("process_loss_qty", qty);
frm.set_value("add_process_loss_cost_in_fg", qty ? 1: 0);
}
});

View File

@ -559,8 +559,10 @@ erpnext.PointOfSale.Controller = class {
item_row = this.frm.add_child('items', new_item);
if (field === 'qty' && value !== 0 && !this.allow_negative_stock)
await this.check_stock_availability(item_row, value, this.frm.doc.set_warehouse);
if (field === 'qty' && value !== 0 && !this.allow_negative_stock) {
const qty_needed = value * item_row.conversion_factor;
await this.check_stock_availability(item_row, qty_needed, this.frm.doc.set_warehouse);
}
await this.trigger_new_item_events(item_row);

View File

@ -6,7 +6,7 @@ import frappe
from frappe import _
from frappe.model.document import Document
from frappe.model.naming import make_autoname, revert_series_if_last
from frappe.query_builder.functions import CurDate, Sum, Timestamp
from frappe.query_builder.functions import CombineDatetime, CurDate, Sum
from frappe.utils import cint, flt, get_link_to_form, nowtime
from frappe.utils.data import add_days
from frappe.utils.jinja import render_template
@ -192,7 +192,8 @@ def get_batch_qty(
posting_time = nowtime()
query = query.where(
Timestamp(sle.posting_date, sle.posting_time) <= Timestamp(posting_date, posting_time)
CombineDatetime(sle.posting_date, sle.posting_time)
<= CombineDatetime(posting_date, posting_time)
)
out = query.run(as_list=True)[0][0] or 0
@ -376,7 +377,7 @@ def get_pos_reserved_batch_qty(filters):
p = frappe.qb.DocType("POS Invoice").as_("p")
item = frappe.qb.DocType("POS Invoice Item").as_("item")
sum_qty = frappe.query_builder.functions.Sum(item.qty).as_("qty")
sum_qty = frappe.query_builder.functions.Sum(item.stock_qty).as_("qty")
reserved_batch_qty = (
frappe.qb.from_(p)

View File

@ -380,7 +380,19 @@ class PurchaseReceipt(BuyingController):
outgoing_amount = d.base_net_amount
if self.is_internal_supplier and d.valuation_rate:
outgoing_amount = d.valuation_rate * d.stock_qty
outgoing_amount = abs(
frappe.db.get_value(
"Stock Ledger Entry",
{
"voucher_type": "Purchase Receipt",
"voucher_no": self.name,
"voucher_detail_no": d.name,
"warehouse": d.from_warehouse,
"is_cancelled": 0,
},
"stock_value_difference",
)
)
credit_amount = outgoing_amount
if credit_amount:

View File

@ -1610,6 +1610,89 @@ class TestPurchaseReceipt(FrappeTestCase):
frappe.db.set_single_value("Stock Settings", "over_delivery_receipt_allowance", 0)
def test_internal_pr_gl_entries(self):
from erpnext.stock import get_warehouse_account_map
from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt
from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import (
create_stock_reconciliation,
)
prepare_data_for_internal_transfer()
customer = "_Test Internal Customer 2"
company = "_Test Company with perpetual inventory"
from_warehouse = create_warehouse("_Test Internal From Warehouse New", company=company)
target_warehouse = create_warehouse("_Test Internal GIT Warehouse New", company=company)
to_warehouse = create_warehouse("_Test Internal To Warehouse New", company=company)
item = make_item(properties={"is_stock_item": 1, "valuation_rate": 100})
make_stock_entry(
purpose="Material Receipt",
item_code=item.name,
qty=10,
company=company,
to_warehouse=from_warehouse,
posting_date=add_days(today(), -3),
)
# Step - 1: Create Delivery Note with Internal Customer
dn = create_delivery_note(
item_code=item.name,
company=company,
customer=customer,
cost_center="Main - TCP1",
expense_account="Cost of Goods Sold - TCP1",
qty=10,
rate=100,
warehouse=from_warehouse,
target_warehouse=target_warehouse,
posting_date=add_days(today(), -2),
)
# Step - 2: Create Internal Purchase Receipt
pr = make_inter_company_purchase_receipt(dn.name)
pr.items[0].qty = 10
pr.items[0].from_warehouse = target_warehouse
pr.items[0].warehouse = to_warehouse
pr.items[0].rejected_warehouse = from_warehouse
pr.save()
pr.submit()
# Step - 3: Create back-date Stock Reconciliation [After DN and Before PR]
create_stock_reconciliation(
item_code=item,
warehouse=target_warehouse,
qty=10,
rate=50,
company=company,
posting_date=add_days(today(), -1),
)
warehouse_account = get_warehouse_account_map(company)
stock_account_value = frappe.db.get_value(
"GL Entry",
{
"account": warehouse_account[target_warehouse]["account"],
"voucher_type": "Purchase Receipt",
"voucher_no": pr.name,
"is_cancelled": 0,
},
fieldname=["credit"],
)
stock_diff = frappe.db.get_value(
"Stock Ledger Entry",
{
"voucher_type": "Purchase Receipt",
"voucher_no": pr.name,
"is_cancelled": 0,
},
fieldname=["sum(stock_value_difference)"],
)
# Value of Stock Account should be equal to the sum of Stock Value Difference
self.assertEqual(stock_account_value, stock_diff)
def prepare_data_for_internal_transfer():
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier

View File

@ -530,7 +530,9 @@ class TestStockReconciliation(FrappeTestCase, StockTestMixin):
# check if cancellation of stock reco is blocked
self.assertRaises(NegativeStockError, sr.cancel)
repost_exists = bool(frappe.db.exists("Repost Item Valuation", {"voucher_no": sr.name}))
repost_exists = bool(
frappe.db.exists("Repost Item Valuation", {"voucher_no": sr.name, "status": "Queued"})
)
self.assertFalse(repost_exists, msg="Negative stock validation not working on reco cancellation")
def test_intermediate_sr_bin_update(self):

View File

@ -5,7 +5,7 @@
import frappe
from frappe import _
from frappe.query_builder import Field
from frappe.query_builder.functions import Min, Timestamp
from frappe.query_builder.functions import CombineDatetime, Min
from frappe.utils import add_days, getdate, today
import erpnext
@ -75,7 +75,7 @@ def get_data(report_filters):
& (sle.company == report_filters.company)
& (sle.is_cancelled == 0)
)
.orderby(Timestamp(sle.posting_date, sle.posting_time), sle.creation)
.orderby(CombineDatetime(sle.posting_date, sle.posting_time), sle.creation)
).run(as_dict=True)
for d in data:

View File

@ -41,7 +41,7 @@ def get_data(report_filters):
key = (d.voucher_type, d.voucher_no)
gl_data = voucher_wise_gl_data.get(key) or {}
d.account_value = gl_data.get("account_value", 0)
d.difference_value = d.stock_value - d.account_value
d.difference_value = abs(d.stock_value) - abs(d.account_value)
if abs(d.difference_value) > 0.1:
data.append(d)

View File

@ -1453,10 +1453,11 @@ def get_next_stock_reco(kwargs):
)
.orderby(CombineDatetime(sle.posting_date, sle.posting_time))
.orderby(sle.creation)
.limit(1)
)
if kwargs.get("batch_no"):
query.where(sle.batch_no == kwargs.get("batch_no"))
query = query.where(sle.batch_no == kwargs.get("batch_no"))
return query.run(as_dict=True)

View File

@ -67,6 +67,15 @@ frappe.ui.form.on('Subcontracting Receipt', {
}
});
frm.set_query('batch_no', 'supplied_items', function(doc, cdt, cdn) {
var row = locals[cdt][cdn];
return {
filters: {
item: row.rm_item_code
}
}
});
let batch_no_field = frm.get_docfield("items", "batch_no");
if (batch_no_field) {
batch_no_field.get_route_options_for_new_doc = function(row) {