landed cost fix

This commit is contained in:
nabinhait 2014-07-17 19:16:38 +05:30 committed by Nabin Hait
parent 87f2401c1e
commit cc0692d714
4 changed files with 33 additions and 21 deletions

View File

@ -14,10 +14,10 @@ class LandedCostVoucher(Document):
def get_items_from_purchase_receipts(self):
self.set("landed_cost_items", [])
for pr in self.get("landed_cost_purchase_receipts"):
pr_items = frappe.db.sql("""select pr_tem.item_code, pr_tem.description,
pr_tem.qty, pr_tem.rate, pr_tem.amount, pr_tem.name
pr_items = frappe.db.sql("""select pr_item.item_code, pr_item.description,
pr_item.qty, pr_item.rate, pr_item.amount, pr_item.name
from `tabPurchase Receipt Item` pr_item where parent = %s
and (select name form tabItem where name = pr_item.item_code and is_stock_item = 'Yes')""",
and exists(select name from tabItem where name = pr_item.item_code and is_stock_item = 'Yes')""",
pr.purchase_receipt, as_dict=True)
for d in pr_items:
@ -75,11 +75,19 @@ class LandedCostVoucher(Document):
item.applicable_charges = flt(item.amount) * flt(self.total_taxes_and_charges) / flt(total_item_cost)
def on_submit(self):
self.update_landed_cost()
def on_cancel(self):
self.update_landed_cost()
def update_landed_cost(self):
purchase_receipts = list(set([d.purchase_receipt for d in self.get("landed_cost_items")]))
self.delete_sle_and_gle(purchase_receipts)
for purchase_receipt in purchase_receipts:
pr = frappe.get_doc("Purchase Receipt", purchase_receipt)
pr.update_valuation_rate()
pr.set_landed_cost_voucher_amount()
pr.update_valuation_rate("purchase_receipt_details")
pr.save()
pr.update_stock()
pr.make_gl_entries()

View File

@ -70,11 +70,11 @@ class PurchaseReceipt(BuyingController):
self.set_landed_cost_voucher_amount()
self.update_valuation_rate("purchase_receipt_details")
def set_landed_cost_voucher_amount(self, voucher_detail):
def set_landed_cost_voucher_amount(self):
for d in self.get("purchase_receipt_details"):
lc_voucher_amount = frappe.db.sql("""select sum(ifnull(applicable_charges))
lc_voucher_amount = frappe.db.sql("""select sum(ifnull(applicable_charges, 0))
from `tabLanded Cost Item`
where docstatus = 1 and pr_item_row_id = %s""", voucher_detail)
where docstatus = 1 and pr_item_row_id = %s""", d.name)
d.landed_cost_voucher_amount = lc_voucher_amount[0][0] if lc_voucher_amount else 0.0
def validate_rejected_warehouse(self):
@ -297,42 +297,41 @@ class PurchaseReceipt(BuyingController):
for d in self.get("purchase_receipt_details"):
if d.item_code in stock_items and flt(d.valuation_rate):
if warehouse_account.get(d.warehouse) or warehouse_account.get(d.rejected_warehouse):
self.check_expense_account(d)
# warehouse account
if flt(d.qty):
gl_list.append(self.get_gl_dict({
gl_entries.append(self.get_gl_dict({
"account": warehouse_account[d.warehouse],
"against": against_expense_account,
"cost_center": default_cost_center,
"cost_center": d.cost_center,
"remarks": self.get("remarks") or "Accounting Entry for Stock",
"debit": flt(d.valuation_rate) * flt(d.qty) * flt(d.conversion_factor)
}))
# rejected warehouse
if flt(d.rejected_qty):
gl_list.append(self.get_gl_dict({
gl_entries.append(self.get_gl_dict({
"account": warehouse_account[d.rejected_warehouse],
"against": against_expense_account,
"cost_center": default_cost_center,
"cost_center": d.cost_center,
"remarks": self.get("remarks") or "Accounting Entry for Stock",
"debit": flt(d.valuation_rate) * flt(d.rejected_qty) * flt(d.conversion_factor)
}))
# stock received but not billed
gl_list.append(self.get_gl_dict({
gl_entries.append(self.get_gl_dict({
"account": stock_rbnb,
"against": warehouse_account[d.warehouse],
"cost_center": default_cost_center,
"cost_center": d.cost_center,
"remarks": self.get("remarks") or "Accounting Entry for Stock",
"credit": flt(d.base_amount, 2)
}))
if flt(d.landed_cost_voucher_amount):
gl_list.append(self.get_gl_dict({
gl_entries.append(self.get_gl_dict({
"account": expenses_included_in_valuation,
"against": warehouse_account[d.warehouse],
"cost_center": default_cost_center,
"cost_center": d.cost_center,
"remarks": self.get("remarks") or "Accounting Entry for Stock",
"credit": flt(d.landed_cost_voucher_amount)
}))
@ -354,6 +353,9 @@ class PurchaseReceipt(BuyingController):
valuation_tax[tax.cost_center] += \
(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount)
if frappe.db.get_value("Purchase Invoice Item", {"purchase_receipt": self.name, "docstatus": 1}):
expenses_included_in_valuation = stock_rbnb
for cost_center, amount in valuation_tax.items():
gl_entries.append(
self.get_gl_dict({

View File

@ -502,6 +502,7 @@
"width": "150px"
},
{
"allow_on_submit": 1,
"fieldname": "landed_cost_voucher_amount",
"fieldtype": "Currency",
"label": "Landed Cost Voucher Amount",
@ -509,6 +510,7 @@
"read_only": 1
},
{
"allow_on_submit": 1,
"fieldname": "valuation_rate",
"fieldtype": "Currency",
"hidden": 1,