perpetual inventory fix related to sub-contracting
Cherry-picked and modified by @anandpdoshi Conflicts: accounts/doctype/purchase_invoice/purchase_invoice.py controllers/buying_controller.py controllers/stock_controller.py
This commit is contained in:
parent
450d9d72d7
commit
a0c239db8d
@ -52,7 +52,6 @@ class PurchaseInvoice(BuyingController):
|
|||||||
self.set_aging_date()
|
self.set_aging_date()
|
||||||
self.set_against_expense_account()
|
self.set_against_expense_account()
|
||||||
self.validate_write_off_account()
|
self.validate_write_off_account()
|
||||||
self.update_raw_material_cost()
|
|
||||||
self.update_valuation_rate("entries")
|
self.update_valuation_rate("entries")
|
||||||
self.validate_multiple_billing("Purchase Receipt", "pr_detail", "amount",
|
self.validate_multiple_billing("Purchase Receipt", "pr_detail", "amount",
|
||||||
"purchase_receipt_details")
|
"purchase_receipt_details")
|
||||||
@ -321,7 +320,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
# expense will be booked in sales invoice
|
# expense will be booked in sales invoice
|
||||||
stock_item_and_auto_accounting_for_stock = True
|
stock_item_and_auto_accounting_for_stock = True
|
||||||
|
|
||||||
valuation_amt = flt(item.base_amount + item.item_tax_amount + item.rm_supp_cost,
|
valuation_amt = flt(item.base_amount + item.item_tax_amount,
|
||||||
self.precision("base_amount", item))
|
self.precision("base_amount", item))
|
||||||
|
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
@ -390,20 +389,6 @@ class PurchaseInvoice(BuyingController):
|
|||||||
def on_update(self):
|
def on_update(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def update_raw_material_cost(self):
|
|
||||||
if self.sub_contracted_items:
|
|
||||||
for d in self.get("entries"):
|
|
||||||
rm_cost = frappe.db.sql("""select raw_material_cost / quantity
|
|
||||||
from `tabBOM` where item = %s and is_default = 1 and docstatus = 1
|
|
||||||
and is_active = 1 """, (d.item_code,))
|
|
||||||
rm_cost = rm_cost and flt(rm_cost[0][0]) or 0
|
|
||||||
|
|
||||||
d.conversion_factor = d.conversion_factor or flt(frappe.db.get_value(
|
|
||||||
"UOM Conversion Detail", {"parent": d.item_code, "uom": d.uom},
|
|
||||||
"conversion_factor")) or 1
|
|
||||||
|
|
||||||
d.rm_supp_cost = rm_cost * flt(d.qty) * flt(d.conversion_factor)
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_expense_account(doctype, txt, searchfield, start, page_len, filters):
|
def get_expense_account(doctype, txt, searchfield, start, page_len, filters):
|
||||||
from erpnext.controllers.queries import get_match_cond
|
from erpnext.controllers.queries import get_match_cond
|
||||||
|
@ -190,7 +190,8 @@ class BuyingController(StockController):
|
|||||||
"UOM Conversion Detail", {"parent": item.item_code, "uom": item.uom},
|
"UOM Conversion Detail", {"parent": item.item_code, "uom": item.uom},
|
||||||
"conversion_factor")) or 1
|
"conversion_factor")) or 1
|
||||||
qty_in_stock_uom = flt(item.qty * item.conversion_factor)
|
qty_in_stock_uom = flt(item.qty * item.conversion_factor)
|
||||||
item.valuation_rate = ((item.base_amount + item.item_tax_amount + item.rm_supp_cost)
|
rm_supp_cost = item.rm_supp_cost if self.doctype=="Purchase Receipt" else 0.0
|
||||||
|
item.valuation_rate = ((item.base_amount + item.item_tax_amount + rm_supp_cost)
|
||||||
/ qty_in_stock_uom)
|
/ qty_in_stock_uom)
|
||||||
else:
|
else:
|
||||||
item.valuation_rate = 0.0
|
item.valuation_rate = 0.0
|
||||||
@ -207,9 +208,15 @@ class BuyingController(StockController):
|
|||||||
self.set(raw_material_table, [])
|
self.set(raw_material_table, [])
|
||||||
if self.is_subcontracted=="Yes":
|
if self.is_subcontracted=="Yes":
|
||||||
for item in self.get(self.fname):
|
for item in self.get(self.fname):
|
||||||
|
if self.doctype == "Purchase Receipt":
|
||||||
|
item.rm_supp_cost = 0.0
|
||||||
if item.item_code in self.sub_contracted_items:
|
if item.item_code in self.sub_contracted_items:
|
||||||
self.add_bom_items(item, raw_material_table)
|
self.add_bom_items(item, raw_material_table)
|
||||||
|
|
||||||
|
elif self.doctype == "Purchase Receipt":
|
||||||
|
for item in self.get(self.fname):
|
||||||
|
item.rm_supp_cost = 0.0
|
||||||
|
|
||||||
def add_bom_items(self, d, raw_material_table):
|
def add_bom_items(self, d, raw_material_table):
|
||||||
bom_items = self.get_items_from_default_bom(d.item_code)
|
bom_items = self.get_items_from_default_bom(d.item_code)
|
||||||
raw_materials_cost = 0
|
raw_materials_cost = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user