Skip to content

Commit

Permalink
fix: Subcontracting Receipt GL Entries
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Mar 29, 2024
1 parent 8e52218 commit 7faf824
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,8 @@ def get_gl_entries(self, warehouse_account=None):
return process_gl_map(gl_entries)

def make_item_gl_entries(self, gl_entries, warehouse_account=None):
stock_rbnb = self.get_company_default("stock_received_but_not_billed")

warehouse_with_no_account = []
stock_rbnb = self.get_company_default("stock_received_but_not_billed")

for item in self.items:
if flt(item.rate) and flt(item.qty):
Expand All @@ -517,44 +516,66 @@ def make_item_gl_entries(self, gl_entries, warehouse_account=None):
"stock_value_difference",
)

warehouse_account_name = warehouse_account[item.warehouse]["account"]
warehouse_account_currency = warehouse_account[item.warehouse]["account_currency"]
accepted_warehouse_account = warehouse_account[item.warehouse]["account"]
supplier_warehouse_account = warehouse_account.get(self.supplier_warehouse, {}).get(
"account"
)
supplier_warehouse_account_currency = warehouse_account.get(
self.supplier_warehouse, {}
).get("account_currency")
remarks = self.get("remarks") or _("Accounting Entry for Stock")

# FG Warehouse Account (Debit)
# Accepted Warehouse Account (Debit)
self.add_gl_entry(
gl_entries=gl_entries,
account=warehouse_account_name,
account=accepted_warehouse_account,
cost_center=item.cost_center,
debit=stock_value_diff,
credit=0.0,
remarks=remarks,
against_account=stock_rbnb,
account_currency=warehouse_account_currency,
account_currency=get_account_currency(accepted_warehouse_account),
project=item.project,
item=item,
)
self.add_gl_entry(
gl_entries=gl_entries,
account=stock_rbnb,
cost_center=item.cost_center,
debit=-1 * stock_value_diff,
credit=0.0,
remarks=remarks,
against_account=accepted_warehouse_account,
account_currency=get_account_currency(stock_rbnb),
project=item.project,
item=item,
)

# Supplier Warehouse Account (Credit)
if flt(item.rm_supp_cost) and warehouse_account.get(self.supplier_warehouse):
if flt(item.rm_supp_cost) and supplier_warehouse_account:
self.add_gl_entry(
gl_entries=gl_entries,
account=supplier_warehouse_account,
cost_center=item.cost_center,
debit=0.0,
credit=flt(item.rm_supp_cost),
remarks=remarks,
against_account=warehouse_account_name,
account_currency=supplier_warehouse_account_currency,
against_account=accepted_warehouse_account,
account_currency=get_account_currency(supplier_warehouse_account),
project=item.project,
item=item,
)
self.add_gl_entry(
gl_entries=gl_entries,
account=accepted_warehouse_account,
cost_center=item.cost_center,
debit=0.0,
credit=-1 * flt(item.rm_supp_cost),
remarks=remarks,
against_account=supplier_warehouse_account,
account_currency=get_account_currency(accepted_warehouse_account),
project=item.project,
item=item,
)

# Expense Account (Credit)
# Expense Account [Service Cost] (Credit)
if flt(item.service_cost_per_qty):
self.add_gl_entry(
gl_entries=gl_entries,
Expand All @@ -563,29 +584,63 @@ def make_item_gl_entries(self, gl_entries, warehouse_account=None):
debit=0.0,
credit=flt(item.service_cost_per_qty) * flt(item.qty),
remarks=remarks,
against_account=warehouse_account_name,
against_account=accepted_warehouse_account,
account_currency=get_account_currency(item.expense_account),
project=item.project,
item=item,
)
self.add_gl_entry(
gl_entries=gl_entries,
account=accepted_warehouse_account,
cost_center=item.cost_center,
debit=0.0,
credit=-1 * (flt(item.service_cost_per_qty) * flt(item.qty)),
remarks=remarks,
against_account=item.expense_account,
account_currency=get_account_currency(accepted_warehouse_account),
project=item.project,
item=item,
)

# Loss Account (Credit)
divisional_loss = flt(item.amount - stock_value_diff, item.precision("amount"))

if divisional_loss:
loss_account = item.expense_account

if divisional_loss := flt(item.amount - stock_value_diff, item.precision("amount")):
self.add_gl_entry(
gl_entries=gl_entries,
account=loss_account,
account=item.expense_account,
cost_center=item.cost_center,
debit=divisional_loss,
credit=0.0,
remarks=remarks,
against_account=warehouse_account_name,
account_currency=get_account_currency(loss_account),
against_account=accepted_warehouse_account,
account_currency=get_account_currency(item.expense_account),
project=item.project,
item=item,
)
self.add_gl_entry(
gl_entries=gl_entries,
account=accepted_warehouse_account,
cost_center=item.cost_center,
debit=-1 * divisional_loss,
credit=0.0,
remarks=remarks,
against_account=item.expense_account,
account_currency=get_account_currency(accepted_warehouse_account),
project=item.project,
item=item,
)

# Additional Costs (Credit)
if item.additional_cost_per_qty:
self.add_gl_entry(
gl_entries=gl_entries,
account=accepted_warehouse_account,
cost_center=self.cost_center or self.get_company_default("cost_center"),
debit=0.0,
credit=-1 * item.qty * item.additional_cost_per_qty,
remarks=remarks,
against_account=None,
account_currency=get_account_currency(accepted_warehouse_account),
)
elif (
item.warehouse not in warehouse_with_no_account
or item.rejected_warehouse not in warehouse_with_no_account
Expand All @@ -608,6 +663,7 @@ def make_item_gl_entries(self, gl_entries, warehouse_account=None):
credit=credit_amount,
remarks=remarks,
against_account=None,
account_currency=get_account_currency(row.expense_account),
)

if warehouse_with_no_account:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import erpnext
from erpnext.accounts.doctype.account.test_account import get_inventory_account
from erpnext.accounts.utils import get_company_default
from erpnext.controllers.sales_and_purchase_return import make_return_doc
from erpnext.controllers.tests.test_subcontracting_controller import (
get_rm_items,
Expand Down Expand Up @@ -355,22 +356,15 @@ def test_subcontracting_receipt_gl_entry(self):
self.assertTrue(gl_entries)

fg_warehouse_ac = get_inventory_account(scr.company, scr.items[0].warehouse)
supplier_warehouse_ac = get_inventory_account(scr.company, scr.supplier_warehouse)
expense_account = scr.items[0].expense_account

if fg_warehouse_ac == supplier_warehouse_ac:
expected_values = {
fg_warehouse_ac: [2100.0, 1000.0], # FG Amount (D), RM Cost (C)
expense_account: [0.0, 1000.0], # Service Cost (C)
additional_costs_expense_account: [0.0, 100.0], # Additional Cost (C)
}
else:
expected_values = {
fg_warehouse_ac: [2100.0, 0.0], # FG Amount (D)
supplier_warehouse_ac: [0.0, 1000.0], # RM Cost (C)
expense_account: [0.0, 1000.0], # Service Cost (C)
additional_costs_expense_account: [0.0, 100.0], # Additional Cost (C)
}
stock_rbnb = get_company_default(scr.company, "stock_received_but_not_billed")
expected_values = {
fg_warehouse_ac: [3200.0, 0.0],
stock_rbnb: [0.0, 2100.0],
expense_account: [0.0, 1000.0],
additional_costs_expense_account: [0.0, 100.0],
}

for gle in gl_entries:
self.assertEqual(expected_values[gle.account][0], gle.debit)
Expand Down

0 comments on commit 7faf824

Please sign in to comment.