fix: create entries for only PR items present in LCV (#36852)
* fix: check if item code exists in lcv before creating gle * refactor: use qb to fetch lcv items
This commit is contained in:
parent
3a2933db4d
commit
26e8b8f959
@ -759,21 +759,22 @@ class PurchaseInvoice(BuyingController):
|
|||||||
|
|
||||||
# Amount added through landed-cost-voucher
|
# Amount added through landed-cost-voucher
|
||||||
if landed_cost_entries:
|
if landed_cost_entries:
|
||||||
for account, amount in landed_cost_entries[(item.item_code, item.name)].items():
|
if (item.item_code, item.name) in landed_cost_entries:
|
||||||
gl_entries.append(
|
for account, amount in landed_cost_entries[(item.item_code, item.name)].items():
|
||||||
self.get_gl_dict(
|
gl_entries.append(
|
||||||
{
|
self.get_gl_dict(
|
||||||
"account": account,
|
{
|
||||||
"against": item.expense_account,
|
"account": account,
|
||||||
"cost_center": item.cost_center,
|
"against": item.expense_account,
|
||||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
"cost_center": item.cost_center,
|
||||||
"credit": flt(amount["base_amount"]),
|
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||||
"credit_in_account_currency": flt(amount["amount"]),
|
"credit": flt(amount["base_amount"]),
|
||||||
"project": item.project or self.project,
|
"credit_in_account_currency": flt(amount["amount"]),
|
||||||
},
|
"project": item.project or self.project,
|
||||||
item=item,
|
},
|
||||||
|
item=item,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# sub-contracting warehouse
|
# sub-contracting warehouse
|
||||||
if flt(item.rm_supp_cost):
|
if flt(item.rm_supp_cost):
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.model.meta import get_field_precision
|
from frappe.model.meta import get_field_precision
|
||||||
|
from frappe.query_builder.custom import ConstantColumn
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
@ -19,19 +20,7 @@ class LandedCostVoucher(Document):
|
|||||||
self.set("items", [])
|
self.set("items", [])
|
||||||
for pr in self.get("purchase_receipts"):
|
for pr in self.get("purchase_receipts"):
|
||||||
if pr.receipt_document_type and pr.receipt_document:
|
if pr.receipt_document_type and pr.receipt_document:
|
||||||
pr_items = frappe.db.sql(
|
pr_items = get_pr_items(pr)
|
||||||
"""select pr_item.item_code, pr_item.description,
|
|
||||||
pr_item.qty, pr_item.base_rate, pr_item.base_amount, pr_item.name,
|
|
||||||
pr_item.cost_center, pr_item.is_fixed_asset
|
|
||||||
from `tab{doctype} Item` pr_item where parent = %s
|
|
||||||
and exists(select name from tabItem
|
|
||||||
where name = pr_item.item_code and (is_stock_item = 1 or is_fixed_asset=1))
|
|
||||||
""".format(
|
|
||||||
doctype=pr.receipt_document_type
|
|
||||||
),
|
|
||||||
pr.receipt_document,
|
|
||||||
as_dict=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
for d in pr_items:
|
for d in pr_items:
|
||||||
item = self.append("items")
|
item = self.append("items")
|
||||||
@ -247,3 +236,30 @@ class LandedCostVoucher(Document):
|
|||||||
),
|
),
|
||||||
tuple([item.valuation_rate] + serial_nos),
|
tuple([item.valuation_rate] + serial_nos),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_pr_items(purchase_receipt):
|
||||||
|
item = frappe.qb.DocType("Item")
|
||||||
|
pr_item = frappe.qb.DocType(purchase_receipt.receipt_document_type + " Item")
|
||||||
|
return (
|
||||||
|
frappe.qb.from_(pr_item)
|
||||||
|
.inner_join(item)
|
||||||
|
.on(item.name == pr_item.item_code)
|
||||||
|
.select(
|
||||||
|
pr_item.item_code,
|
||||||
|
pr_item.description,
|
||||||
|
pr_item.qty,
|
||||||
|
pr_item.base_rate,
|
||||||
|
pr_item.base_amount,
|
||||||
|
pr_item.name,
|
||||||
|
pr_item.cost_center,
|
||||||
|
pr_item.is_fixed_asset,
|
||||||
|
ConstantColumn(purchase_receipt.receipt_document_type).as_("receipt_document_type"),
|
||||||
|
ConstantColumn(purchase_receipt.receipt_document).as_("receipt_document"),
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
(pr_item.parent == purchase_receipt.receipt_document)
|
||||||
|
& ((item.is_stock_item == 1) | (item.is_fixed_asset == 1))
|
||||||
|
)
|
||||||
|
.run(as_dict=True)
|
||||||
|
)
|
||||||
|
|||||||
@ -470,27 +470,28 @@ class PurchaseReceipt(BuyingController):
|
|||||||
|
|
||||||
# Amount added through landed-cos-voucher
|
# Amount added through landed-cos-voucher
|
||||||
if d.landed_cost_voucher_amount and landed_cost_entries:
|
if d.landed_cost_voucher_amount and landed_cost_entries:
|
||||||
for account, amount in landed_cost_entries[(d.item_code, d.name)].items():
|
if (d.item_code, d.name) in landed_cost_entries:
|
||||||
account_currency = get_account_currency(account)
|
for account, amount in landed_cost_entries[(d.item_code, d.name)].items():
|
||||||
credit_amount = (
|
account_currency = get_account_currency(account)
|
||||||
flt(amount["base_amount"])
|
credit_amount = (
|
||||||
if (amount["base_amount"] or account_currency != self.company_currency)
|
flt(amount["base_amount"])
|
||||||
else flt(amount["amount"])
|
if (amount["base_amount"] or account_currency != self.company_currency)
|
||||||
)
|
else flt(amount["amount"])
|
||||||
|
)
|
||||||
|
|
||||||
self.add_gl_entry(
|
self.add_gl_entry(
|
||||||
gl_entries=gl_entries,
|
gl_entries=gl_entries,
|
||||||
account=account,
|
account=account,
|
||||||
cost_center=d.cost_center,
|
cost_center=d.cost_center,
|
||||||
debit=0.0,
|
debit=0.0,
|
||||||
credit=credit_amount,
|
credit=credit_amount,
|
||||||
remarks=remarks,
|
remarks=remarks,
|
||||||
against_account=warehouse_account_name,
|
against_account=warehouse_account_name,
|
||||||
credit_in_account_currency=flt(amount["amount"]),
|
credit_in_account_currency=flt(amount["amount"]),
|
||||||
account_currency=account_currency,
|
account_currency=account_currency,
|
||||||
project=d.project,
|
project=d.project,
|
||||||
item=d,
|
item=d,
|
||||||
)
|
)
|
||||||
|
|
||||||
if d.rate_difference_with_purchase_invoice and stock_rbnb:
|
if d.rate_difference_with_purchase_invoice and stock_rbnb:
|
||||||
account_currency = get_account_currency(stock_rbnb)
|
account_currency = get_account_currency(stock_rbnb)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user