chore: rearrange functions
This commit is contained in:
parent
e15546b42f
commit
7f1d916f04
@ -323,7 +323,6 @@ class PurchaseReceipt(BuyingController):
|
|||||||
|
|
||||||
is_asset_pr = any(d.is_fixed_asset for d in self.get("items"))
|
is_asset_pr = any(d.is_fixed_asset for d in self.get("items"))
|
||||||
stock_asset_rbnb = None
|
stock_asset_rbnb = None
|
||||||
stock_asset_account_name = None
|
|
||||||
remarks = self.get("remarks") or _("Accounting Entry for {0}").format(
|
remarks = self.get("remarks") or _("Accounting Entry for {0}").format(
|
||||||
"Asset" if is_asset_pr else "Stock"
|
"Asset" if is_asset_pr else "Stock"
|
||||||
)
|
)
|
||||||
@ -360,12 +359,13 @@ class PurchaseReceipt(BuyingController):
|
|||||||
item=item,
|
item=item,
|
||||||
)
|
)
|
||||||
|
|
||||||
def make_stock_received_but_not_billed_entry(item, outgoing_amount):
|
def make_stock_received_but_not_billed_entry(item):
|
||||||
account = (
|
account = (
|
||||||
warehouse_account[item.from_warehouse]["account"] if item.from_warehouse else stock_asset_rbnb
|
warehouse_account[item.from_warehouse]["account"] if item.from_warehouse else stock_asset_rbnb
|
||||||
)
|
)
|
||||||
account_currency = get_account_currency(account)
|
account_currency = get_account_currency(account)
|
||||||
|
|
||||||
|
outgoing_amount = item.base_net_amount
|
||||||
# GL Entry for from warehouse or Stock Received but not billed
|
# GL Entry for from warehouse or Stock Received but not billed
|
||||||
# Intentionally passed negative debit amount to avoid incorrect GL Entry validation
|
# Intentionally passed negative debit amount to avoid incorrect GL Entry validation
|
||||||
credit_amount = (
|
credit_amount = (
|
||||||
@ -375,9 +375,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if self.is_internal_transfer() and item.valuation_rate:
|
if self.is_internal_transfer() and item.valuation_rate:
|
||||||
outgoing_amount = abs(
|
outgoing_amount = abs(get_stock_value_difference(self.name, item.name, item.from_warehouse))
|
||||||
get_stock_value_difference(self.name, item.name, item.from_warehouse) or 0
|
|
||||||
)
|
|
||||||
credit_amount = outgoing_amount
|
credit_amount = outgoing_amount
|
||||||
|
|
||||||
if credit_amount:
|
if credit_amount:
|
||||||
@ -496,7 +494,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
# divisional loss adjustment
|
# divisional loss adjustment
|
||||||
expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")
|
expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")
|
||||||
valuation_amount_as_per_doc = (
|
valuation_amount_as_per_doc = (
|
||||||
flt(outgoing_amount, d.precision("base_net_amount"))
|
flt(item.base_net_amount, d.precision("base_net_amount"))
|
||||||
+ flt(item.landed_cost_voucher_amount)
|
+ flt(item.landed_cost_voucher_amount)
|
||||||
+ flt(item.rm_supp_cost)
|
+ flt(item.rm_supp_cost)
|
||||||
+ flt(item.item_tax_amount)
|
+ flt(item.item_tax_amount)
|
||||||
@ -534,11 +532,37 @@ class PurchaseReceipt(BuyingController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for d in self.get("items"):
|
for d in self.get("items"):
|
||||||
if d.item_code in stock_items or d.is_fixed_asset:
|
if (
|
||||||
if warehouse_account.get(d.warehouse):
|
d.item_code not in stock_items
|
||||||
stock_value_diff = get_stock_value_difference(self.name, d.name, d.warehouse)
|
and flt(d.qty)
|
||||||
outgoing_amount = d.base_net_amount + d.item_tax_amount
|
and provisional_accounting_for_non_stock_items
|
||||||
|
and d.get("provisional_expense_account")
|
||||||
|
):
|
||||||
|
self.add_provisional_gl_entry(
|
||||||
|
d, gl_entries, self.posting_date, d.get("provisional_expense_account")
|
||||||
|
)
|
||||||
|
elif flt(d.qty) and (flt(d.valuation_rate) or self.is_return):
|
||||||
|
if d.is_fixed_asset:
|
||||||
|
stock_asset_account_name = (
|
||||||
|
get_asset_category_account(
|
||||||
|
asset_category=d.asset_category,
|
||||||
|
fieldname="capital_work_in_progress_account",
|
||||||
|
company=self.company,
|
||||||
|
)
|
||||||
|
if is_cwip_accounting_enabled(d.asset_category)
|
||||||
|
else get_asset_category_account(
|
||||||
|
asset_category=d.asset_category, fieldname="fixed_asset_account", company=self.company
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
stock_value_diff = flt(d.net_amount) + flt(d.item_tax_amount / self.conversion_rate)
|
||||||
|
elif (
|
||||||
|
(flt(d.valuation_rate) or self.is_return)
|
||||||
|
and flt(d.qty)
|
||||||
|
and warehouse_account.get(d.warehouse)
|
||||||
|
):
|
||||||
|
stock_value_diff = get_stock_value_difference(self.name, d.name, d.warehouse)
|
||||||
|
stock_asset_account_name = warehouse_account[d.warehouse]["account"]
|
||||||
supplier_warehouse_account = warehouse_account.get(self.supplier_warehouse, {}).get("account")
|
supplier_warehouse_account = warehouse_account.get(self.supplier_warehouse, {}).get("account")
|
||||||
supplier_warehouse_account_currency = warehouse_account.get(self.supplier_warehouse, {}).get(
|
supplier_warehouse_account_currency = warehouse_account.get(self.supplier_warehouse, {}).get(
|
||||||
"account_currency"
|
"account_currency"
|
||||||
@ -554,44 +578,17 @@ class PurchaseReceipt(BuyingController):
|
|||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if d.is_fixed_asset:
|
make_item_asset_inward_entries(d, stock_value_diff, stock_asset_account_name)
|
||||||
stock_asset_account_name = (
|
make_stock_received_but_not_billed_entry(d)
|
||||||
get_asset_category_account(
|
make_landed_cost_gl_entries(d)
|
||||||
asset_category=d.asset_category,
|
make_rate_difference_entry(d)
|
||||||
fieldname="capital_work_in_progress_account",
|
make_sub_contracting_gl_entries(d)
|
||||||
company=self.company,
|
make_divisional_loss_gl_entry(d)
|
||||||
)
|
|
||||||
if is_cwip_accounting_enabled(d.asset_category)
|
|
||||||
else get_asset_category_account(
|
|
||||||
asset_category=d.asset_category, fieldname="fixed_asset_account", company=self.company
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
stock_value_diff = flt(d.net_amount) + flt(d.item_tax_amount / self.conversion_rate)
|
|
||||||
elif (flt(d.valuation_rate) or self.is_return) and flt(d.qty):
|
|
||||||
stock_asset_account_name = warehouse_account[d.warehouse]["account"]
|
|
||||||
|
|
||||||
make_item_asset_inward_entries(d, stock_value_diff, stock_asset_account_name)
|
|
||||||
make_stock_received_but_not_billed_entry(d, outgoing_amount)
|
|
||||||
make_landed_cost_gl_entries(d)
|
|
||||||
make_rate_difference_entry(d)
|
|
||||||
make_sub_contracting_gl_entries(d)
|
|
||||||
make_divisional_loss_gl_entry(d)
|
|
||||||
elif (
|
|
||||||
d.warehouse not in warehouse_with_no_account
|
|
||||||
or d.rejected_warehouse not in warehouse_with_no_account
|
|
||||||
):
|
|
||||||
warehouse_with_no_account.append(d.warehouse)
|
|
||||||
elif (
|
elif (
|
||||||
d.item_code not in stock_items
|
d.warehouse not in warehouse_with_no_account
|
||||||
and not d.is_fixed_asset
|
or d.rejected_warehouse not in warehouse_with_no_account
|
||||||
and flt(d.qty)
|
|
||||||
and provisional_accounting_for_non_stock_items
|
|
||||||
and d.get("provisional_expense_account")
|
|
||||||
):
|
):
|
||||||
self.add_provisional_gl_entry(
|
warehouse_with_no_account.append(d.warehouse)
|
||||||
d, gl_entries, self.posting_date, d.get("provisional_expense_account")
|
|
||||||
)
|
|
||||||
|
|
||||||
if d.is_fixed_asset:
|
if d.is_fixed_asset:
|
||||||
self.update_assets(d, d.valuation_rate)
|
self.update_assets(d, d.valuation_rate)
|
||||||
@ -754,7 +751,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
|
|
||||||
|
|
||||||
def get_stock_value_difference(voucher_no, voucher_detail_no, warehouse):
|
def get_stock_value_difference(voucher_no, voucher_detail_no, warehouse):
|
||||||
frappe.db.get_value(
|
return frappe.db.get_value(
|
||||||
"Stock Ledger Entry",
|
"Stock Ledger Entry",
|
||||||
{
|
{
|
||||||
"voucher_type": "Purchase Receipt",
|
"voucher_type": "Purchase Receipt",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user