Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable/disable gl entry posting for change given in pos #25822

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"delete_linked_ledger_entries",
"book_asset_depreciation_entry_automatically",
"unlink_advance_payment_on_cancelation_of_order",
"post_change_gl_entries",
"tax_settings_section",
"determine_address_tax_category_from",
"column_break_19",
Expand Down Expand Up @@ -253,14 +254,20 @@
{
"fieldname": "column_break_19",
"fieldtype": "Column Break"
},
{
"default": "1",
"fieldname": "post_change_gl_entries",
"fieldtype": "Check",
"label": "Post Ledger Entries for Given Change"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nextchamp-saqib Please add field description, no context for Change in Accounts Settings. The label can be "Create Ledger Entries for Change Amount"

}
],
"icon": "icon-cog",
"idx": 1,
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2021-04-30 15:25:10.381008",
"modified": "2021-05-25 12:34:05.858669",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Accounts Settings",
Expand Down
12 changes: 10 additions & 2 deletions erpnext/accounts/doctype/sales_invoice/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,6 @@ def get_gl_entries(self, warehouse_account=None):

self.make_loyalty_point_redemption_gle(gl_entries)
self.make_pos_gl_entries(gl_entries)
self.make_gle_for_change_amount(gl_entries)

self.make_write_off_gl_entry(gl_entries)
self.make_gle_for_rounding_adjustment(gl_entries)
Expand Down Expand Up @@ -983,7 +982,13 @@ def make_loyalty_point_redemption_gle(self, gl_entries):

def make_pos_gl_entries(self, gl_entries):
if cint(self.is_pos):

skip_change_gl_entries = not cint(frappe.db.get_single_value('Accounts Settings', 'post_change_gl_entries'))

for payment_mode in self.payments:
if skip_change_gl_entries and payment_mode.account == self.account_for_change_amount:
payment_mode.base_amount -= self.change_amount

if payment_mode.amount:
# POS, make payment entries
gl_entries.append(
Expand Down Expand Up @@ -1015,8 +1020,11 @@ def make_pos_gl_entries(self, gl_entries):
}, payment_mode_account_currency, item=self)
)

if not skip_change_gl_entries:
self.make_gle_for_change_amount(gl_entries)

def make_gle_for_change_amount(self, gl_entries):
if cint(self.is_pos) and self.change_amount:
if self.change_amount:
if self.account_for_change_amount:
gl_entries.append(
self.get_gl_dict({
Expand Down
44 changes: 41 additions & 3 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def test_pos_gl_entry_with_perpetual_inventory(self):
si.submit()
self.assertEqual(si.paid_amount, 100.0)

self.pos_gl_entry(si, pos, 50)
self.validate_pos_gl_entry(si, pos, 50)

def test_pos_returns_with_repayment(self):
from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_sales_return
Expand Down Expand Up @@ -749,7 +749,7 @@ def test_pos_change_amount(self):
make_pos_profile(company="_Test Company with perpetual inventory", income_account = "Sales - TCP1",
expense_account = "Cost of Goods Sold - TCP1", warehouse="Stores - TCP1", cost_center = "Main - TCP1", write_off_account="_Test Write Off - TCP1")

pr = make_purchase_receipt(company= "_Test Company with perpetual inventory",
make_purchase_receipt(company= "_Test Company with perpetual inventory",
item_code= "_Test FG Item",warehouse= "Stores - TCP1", cost_center= "Main - TCP1")

pos = create_sales_invoice(company= "_Test Company with perpetual inventory",
Expand All @@ -770,7 +770,45 @@ def test_pos_change_amount(self):
self.assertEqual(pos.grand_total, 100.0)
self.assertEqual(pos.write_off_amount, -5)

def pos_gl_entry(self, si, pos, cash_amount):
def test_pos_with_no_gl_entry_for_change_amount(self):
frappe.db.set_value('Accounts Settings', None, 'post_change_gl_entries', 0)

make_pos_profile(company="_Test Company with perpetual inventory", income_account = "Sales - TCP1",
expense_account = "Cost of Goods Sold - TCP1", warehouse="Stores - TCP1", cost_center = "Main - TCP1", write_off_account="_Test Write Off - TCP1")

make_purchase_receipt(company= "_Test Company with perpetual inventory",
item_code= "_Test FG Item",warehouse= "Stores - TCP1", cost_center= "Main - TCP1")

pos = create_sales_invoice(company= "_Test Company with perpetual inventory",
debit_to="Debtors - TCP1", item_code= "_Test FG Item", warehouse="Stores - TCP1",
income_account = "Sales - TCP1", expense_account = "Cost of Goods Sold - TCP1",
cost_center = "Main - TCP1", do_not_save=True)

pos.is_pos = 1
pos.update_stock = 1

taxes = get_taxes_and_charges()
pos.taxes = []
for tax in taxes:
pos.append("taxes", tax)

pos.append("payments", {'mode_of_payment': 'Bank Draft', 'account': '_Test Bank - TCP1', 'amount': 50})
pos.append("payments", {'mode_of_payment': 'Cash', 'account': 'Cash - TCP1', 'amount': 60})

pos.insert()
pos.submit()

self.assertEqual(pos.grand_total, 100.0)
self.assertEqual(pos.change_amount, 10)

self.validate_pos_gl_entry(pos, pos, 60, validate_without_change_gle=True)

frappe.db.set_value('Accounts Settings', None, 'post_change_gl_entries', 1)

def validate_pos_gl_entry(self, si, pos, cash_amount, validate_without_change_gle=False):
if validate_without_change_gle:
cash_amount -= pos.change_amount

# check stock ledger entries
sle = frappe.db.sql("""select * from `tabStock Ledger Entry`
where voucher_type = 'Sales Invoice' and voucher_no = %s""",
Expand Down