fix: stock and account balance syncing (#24644)
* fix: stock and account balance syncing * fix: stock and account balance syncing * fix: stock and account balance syncing * fix: minor fix
This commit is contained in:
parent
f1c0f680f4
commit
9b178bcd10
@ -888,18 +888,22 @@ def get_coa(doctype, parent, is_root, chart=None):
|
|||||||
|
|
||||||
def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for_items=None,
|
def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for_items=None,
|
||||||
warehouse_account=None, company=None):
|
warehouse_account=None, company=None):
|
||||||
|
stock_vouchers = get_future_stock_vouchers(posting_date, posting_time, for_warehouses, for_items, company)
|
||||||
|
repost_gle_for_stock_vouchers(stock_vouchers, posting_date, company, warehouse_account)
|
||||||
|
|
||||||
|
|
||||||
|
def repost_gle_for_stock_vouchers(stock_vouchers, posting_date, company=None, warehouse_account=None):
|
||||||
def _delete_gl_entries(voucher_type, voucher_no):
|
def _delete_gl_entries(voucher_type, voucher_no):
|
||||||
frappe.db.sql("""delete from `tabGL Entry`
|
frappe.db.sql("""delete from `tabGL Entry`
|
||||||
where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no))
|
where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no))
|
||||||
|
|
||||||
|
|
||||||
if not warehouse_account:
|
if not warehouse_account:
|
||||||
warehouse_account = get_warehouse_account_map(company)
|
warehouse_account = get_warehouse_account_map(company)
|
||||||
|
|
||||||
future_stock_vouchers = get_future_stock_vouchers(posting_date, posting_time,
|
gle = get_voucherwise_gl_entries(stock_vouchers, posting_date)
|
||||||
for_warehouses, for_items, company)
|
|
||||||
gle = get_voucherwise_gl_entries(future_stock_vouchers, posting_date)
|
|
||||||
|
|
||||||
for voucher_type, voucher_no in future_stock_vouchers:
|
for voucher_type, voucher_no in stock_vouchers:
|
||||||
existing_gle = gle.get((voucher_type, voucher_no), [])
|
existing_gle = gle.get((voucher_type, voucher_no), [])
|
||||||
voucher_obj = frappe.get_doc(voucher_type, voucher_no)
|
voucher_obj = frappe.get_doc(voucher_type, voucher_no)
|
||||||
expected_gle = voucher_obj.get_gl_entries(warehouse_account)
|
expected_gle = voucher_obj.get_gl_entries(warehouse_account)
|
||||||
@ -924,7 +928,7 @@ def get_future_stock_vouchers(posting_date, posting_time, for_warehouses=None, f
|
|||||||
values += for_warehouses
|
values += for_warehouses
|
||||||
|
|
||||||
if company:
|
if company:
|
||||||
condition += " and company = %s "
|
condition += " and company = %s"
|
||||||
values.append(company)
|
values.append(company)
|
||||||
|
|
||||||
for d in frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no
|
for d in frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no
|
||||||
|
|||||||
@ -488,13 +488,12 @@ class StockController(AccountsController):
|
|||||||
"voucher_no": self.name,
|
"voucher_no": self.name,
|
||||||
"company": self.company
|
"company": self.company
|
||||||
})
|
})
|
||||||
|
|
||||||
if check_if_future_sle_exists(args):
|
if check_if_future_sle_exists(args):
|
||||||
create_repost_item_valuation_entry(args)
|
create_repost_item_valuation_entry(args)
|
||||||
elif not is_reposting_pending():
|
elif not is_reposting_pending():
|
||||||
check_if_stock_and_account_balance_synced(self.posting_date,
|
check_if_stock_and_account_balance_synced(self.posting_date,
|
||||||
self.company, self.doctype, self.name)
|
self.company, self.doctype, self.name)
|
||||||
|
|
||||||
def is_reposting_pending():
|
def is_reposting_pending():
|
||||||
return frappe.db.exists("Repost Item Valuation",
|
return frappe.db.exists("Repost Item Valuation",
|
||||||
{'docstatus': 1, 'status': ['in', ['Queued','In Progress']]})
|
{'docstatus': 1, 'status': ['in', ['Queued','In Progress']]})
|
||||||
|
|||||||
@ -121,6 +121,7 @@ class ClinicalProcedure(Document):
|
|||||||
|
|
||||||
stock_entry.stock_entry_type = 'Material Receipt'
|
stock_entry.stock_entry_type = 'Material Receipt'
|
||||||
stock_entry.to_warehouse = self.warehouse
|
stock_entry.to_warehouse = self.warehouse
|
||||||
|
stock_entry.company = self.company
|
||||||
expense_account = get_account(None, 'expense_account', 'Healthcare Settings', self.company)
|
expense_account = get_account(None, 'expense_account', 'Healthcare Settings', self.company)
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
if item.qty > item.actual_qty:
|
if item.qty > item.actual_qty:
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2017, ESS LLP and Contributors
|
# Copyright (c) 2017, ESS LLP and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
@ -60,6 +60,7 @@ def create_procedure(procedure_template, patient, practitioner):
|
|||||||
procedure.practitioner = practitioner
|
procedure.practitioner = practitioner
|
||||||
procedure.consume_stock = procedure_template.allow_stock_consumption
|
procedure.consume_stock = procedure_template.allow_stock_consumption
|
||||||
procedure.items = procedure_template.items
|
procedure.items = procedure_template.items
|
||||||
procedure.warehouse = frappe.db.get_single_value('Stock Settings', 'default_warehouse')
|
procedure.company = "_Test Company"
|
||||||
|
procedure.warehouse = "_Test Warehouse - _TC"
|
||||||
procedure.submit()
|
procedure.submit()
|
||||||
return procedure
|
return procedure
|
||||||
@ -3,7 +3,6 @@ from frappe import _
|
|||||||
from erpnext.stock.stock_ledger import update_entries_after
|
from erpnext.stock.stock_ledger import update_entries_after
|
||||||
from erpnext.accounts.utils import update_gl_entries_after
|
from erpnext.accounts.utils import update_gl_entries_after
|
||||||
|
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
data = frappe.db.sql(''' SELECT name, item_code, warehouse, voucher_type, voucher_no, posting_date, posting_time
|
data = frappe.db.sql(''' SELECT name, item_code, warehouse, voucher_type, voucher_no, posting_date, posting_time
|
||||||
from `tabStock Ledger Entry` where creation > '2020-12-26 12:58:55.903836' and is_cancelled = 0
|
from `tabStock Ledger Entry` where creation > '2020-12-26 12:58:55.903836' and is_cancelled = 0
|
||||||
|
|||||||
@ -64,7 +64,7 @@ def get_warehouse_account(warehouse, warehouse_account=None):
|
|||||||
if not account and warehouse.company:
|
if not account and warehouse.company:
|
||||||
account = get_company_default_inventory_account(warehouse.company)
|
account = get_company_default_inventory_account(warehouse.company)
|
||||||
|
|
||||||
if not account and warehouse.company:
|
if not account and warehouse.company and not warehouse.is_group:
|
||||||
frappe.throw(_("Please set Account in Warehouse {0} or Default Inventory Account in Company {1}")
|
frappe.throw(_("Please set Account in Warehouse {0} or Default Inventory Account in Company {1}")
|
||||||
.format(warehouse.name, warehouse.company))
|
.format(warehouse.name, warehouse.company))
|
||||||
return account
|
return account
|
||||||
|
|||||||
@ -298,9 +298,9 @@ class TestBatch(unittest.TestCase):
|
|||||||
self.assertEqual(details.get('price_list_rate'), 400)
|
self.assertEqual(details.get('price_list_rate'), 400)
|
||||||
|
|
||||||
def create_batch(item_code, rate, create_item_price_for_batch):
|
def create_batch(item_code, rate, create_item_price_for_batch):
|
||||||
pi = make_purchase_invoice(company="_Test Company with perpetual inventory",
|
pi = make_purchase_invoice(company="_Test Company",
|
||||||
warehouse= "Stores - TCP1", cost_center = "Main - TCP1", update_stock=1,
|
warehouse= "Stores - _TC", cost_center = "Main - _TC", update_stock=1,
|
||||||
expense_account ="_Test Account Cost for Goods Sold - TCP1", item_code=item_code)
|
expense_account ="_Test Account Cost for Goods Sold - _TC", item_code=item_code)
|
||||||
|
|
||||||
batch = frappe.db.get_value('Batch', {'item': item_code, 'reference_name': pi.name})
|
batch = frappe.db.get_value('Batch', {'item': item_code, 'reference_name': pi.name})
|
||||||
|
|
||||||
|
|||||||
@ -148,7 +148,6 @@ class TestLandedCostVoucher(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
def test_landed_cost_voucher_for_odd_numbers (self):
|
def test_landed_cost_voucher_for_odd_numbers (self):
|
||||||
|
|
||||||
pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1", do_not_save=True)
|
pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1", do_not_save=True)
|
||||||
pr.items[0].cost_center = "Main - TCP1"
|
pr.items[0].cost_center = "Main - TCP1"
|
||||||
for x in range(2):
|
for x in range(2):
|
||||||
@ -208,6 +207,10 @@ class TestLandedCostVoucher(unittest.TestCase):
|
|||||||
self.assertEqual(pr.items[1].landed_cost_voucher_amount, 100)
|
self.assertEqual(pr.items[1].landed_cost_voucher_amount, 100)
|
||||||
|
|
||||||
def test_multi_currency_lcv(self):
|
def test_multi_currency_lcv(self):
|
||||||
|
from erpnext.setup.doctype.currency_exchange.test_currency_exchange import test_records, save_new_records
|
||||||
|
|
||||||
|
save_new_records(test_records)
|
||||||
|
|
||||||
## Create USD Shipping charges_account
|
## Create USD Shipping charges_account
|
||||||
usd_shipping = create_account(account_name="Shipping Charges USD",
|
usd_shipping = create_account(account_name="Shipping Charges USD",
|
||||||
parent_account="Duties and Taxes - TCP1", company="_Test Company with perpetual inventory",
|
parent_account="Duties and Taxes - TCP1", company="_Test Company with perpetual inventory",
|
||||||
|
|||||||
@ -64,7 +64,7 @@ def repost(doc):
|
|||||||
message += "<br>" + "Traceback: <br>" + traceback
|
message += "<br>" + "Traceback: <br>" + traceback
|
||||||
frappe.db.set_value(doc.doctype, doc.name, 'error_log', message)
|
frappe.db.set_value(doc.doctype, doc.name, 'error_log', message)
|
||||||
|
|
||||||
notify_error_to_stock_managers(doc)
|
notify_error_to_stock_managers(doc, message)
|
||||||
doc.set_status('Failed')
|
doc.set_status('Failed')
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@ -190,6 +190,7 @@ def create_shipment_company(company_name, abbr):
|
|||||||
company.abbr = abbr
|
company.abbr = abbr
|
||||||
company.default_currency = 'EUR'
|
company.default_currency = 'EUR'
|
||||||
company.country = 'Germany'
|
company.country = 'Germany'
|
||||||
|
company.enable_perpetual_inventory = 0
|
||||||
company.insert()
|
company.insert()
|
||||||
return company
|
return company
|
||||||
|
|
||||||
|
|||||||
@ -204,7 +204,8 @@ class update_entries_after(object):
|
|||||||
where
|
where
|
||||||
item_code = %(item_code)s
|
item_code = %(item_code)s
|
||||||
and warehouse = %(warehouse)s
|
and warehouse = %(warehouse)s
|
||||||
and timestamp(posting_date, time_format(posting_time, %(time_format)s)) = timestamp(%(posting_date)s, time_format(%(posting_time)s, %(time_format)s))
|
and voucher_type = %(voucher_type)s
|
||||||
|
and voucher_no = %(voucher_no)s
|
||||||
order by
|
order by
|
||||||
creation ASC
|
creation ASC
|
||||||
for update
|
for update
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user