[fix] [minor] buying amount for sales bom item
This commit is contained in:
parent
da1e503f3d
commit
94c90bdbf9
@ -4,7 +4,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
from webnotes.utils import flt
|
from webnotes.utils import flt
|
||||||
from stock.utils import get_buying_amount
|
from stock.utils import get_buying_amount, get_sales_bom_buying_amount
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters = {}
|
if not filters: filters = {}
|
||||||
@ -21,10 +21,15 @@ def execute(filters=None):
|
|||||||
data = []
|
data = []
|
||||||
for row in source:
|
for row in source:
|
||||||
selling_amount = flt(row.amount)
|
selling_amount = flt(row.amount)
|
||||||
|
|
||||||
buying_amount = get_buying_amount(row.item_code, row.parenttype, row.name, row.item_row,
|
item_sales_bom_map = item_sales_bom.get(row.parenttype, {}).get(row.name, webnotes._dict())
|
||||||
stock_ledger_entries.get((row.item_code, row.warehouse), []),
|
|
||||||
item_sales_bom.get(row.parenttype, {}).get(row.name, webnotes._dict()))
|
if item_sales_bom_map.get(row.item_code):
|
||||||
|
buying_amount = get_sales_bom_buying_amount(row.item_code, row.warehouse,
|
||||||
|
row.parenttype, row.name, row.item_row, stock_ledger_entries, item_sales_bom_map)
|
||||||
|
else:
|
||||||
|
buying_amount = get_buying_amount(row.parenttype, row.name, row.item_row,
|
||||||
|
stock_ledger_entries.get((row.item_code, row.warehouse), []))
|
||||||
|
|
||||||
buying_amount = buying_amount > 0 and buying_amount or 0
|
buying_amount = buying_amount > 0 and buying_amount or 0
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ class SellingController(StockController):
|
|||||||
self.doc.grand_total_export or self.doc.rounded_total_export, self.doc.currency)
|
self.doc.grand_total_export or self.doc.rounded_total_export, self.doc.currency)
|
||||||
|
|
||||||
def set_buying_amount(self, stock_ledger_entries = None):
|
def set_buying_amount(self, stock_ledger_entries = None):
|
||||||
from stock.utils import get_buying_amount
|
from stock.utils import get_buying_amount, get_sales_bom_buying_amount
|
||||||
if not stock_ledger_entries:
|
if not stock_ledger_entries:
|
||||||
stock_ledger_entries = self.get_stock_ledger_entries()
|
stock_ledger_entries = self.get_stock_ledger_entries()
|
||||||
|
|
||||||
@ -99,13 +99,18 @@ class SellingController(StockController):
|
|||||||
for item in self.doclist.get({"parentfield": self.fname}):
|
for item in self.doclist.get({"parentfield": self.fname}):
|
||||||
if item.item_code in self.stock_items or \
|
if item.item_code in self.stock_items or \
|
||||||
(item_sales_bom and item_sales_bom.get(item.item_code)):
|
(item_sales_bom and item_sales_bom.get(item.item_code)):
|
||||||
buying_amount = get_buying_amount(item.item_code, self.doc.doctype, self.doc.name, item.name,
|
if item.item_code in self.stock_items:
|
||||||
stock_ledger_entries.get((item.item_code, item.warehouse), []),
|
buying_amount = get_buying_amount(self.doc.doctype, self.doc.name,
|
||||||
item_sales_bom)
|
item.name, stock_ledger_entries.get((item.item_code,
|
||||||
|
item.warehouse), []))
|
||||||
|
elif item_sales_bom and item_sales_bom.get(item.item_code):
|
||||||
|
buying_amount = get_sales_bom_buying_amount(item.item_code, item.warehouse,
|
||||||
|
self.doc.doctype, self.doc.name, item.name, stock_ledger_entries,
|
||||||
|
item_sales_bom)
|
||||||
|
|
||||||
item.buying_amount = buying_amount >= 0.01 and buying_amount or 0
|
item.buying_amount = buying_amount >= 0.01 and buying_amount or 0
|
||||||
webnotes.conn.set_value(item.doctype, item.name, "buying_amount",
|
webnotes.conn.set_value(item.doctype, item.name, "buying_amount",
|
||||||
item.buying_amount)
|
item.buying_amount)
|
||||||
|
|
||||||
def check_expense_account(self, item):
|
def check_expense_account(self, item):
|
||||||
if item.buying_amount and not item.expense_account:
|
if item.buying_amount and not item.expense_account:
|
||||||
|
@ -293,7 +293,7 @@ class DocType(StockController):
|
|||||||
|
|
||||||
self.doc.stock_value_difference = 0.0
|
self.doc.stock_value_difference = 0.0
|
||||||
for d in self.entries:
|
for d in self.entries:
|
||||||
self.doc.stock_value_difference -= get_buying_amount(d.item_code, self.doc.doctype, self.doc.name,
|
self.doc.stock_value_difference -= get_buying_amount(self.doc.doctype, self.doc.name,
|
||||||
d.voucher_detail_no, stock_ledger_entries.get((d.item_code, d.warehouse), []))
|
d.voucher_detail_no, stock_ledger_entries.get((d.item_code, d.warehouse), []))
|
||||||
webnotes.conn.set(self.doc, "stock_value_difference", self.doc.stock_value_difference)
|
webnotes.conn.set(self.doc, "stock_value_difference", self.doc.stock_value_difference)
|
||||||
|
|
||||||
|
@ -164,20 +164,18 @@ def validate_warehouse_user(warehouse):
|
|||||||
webnotes.throw(_("Not allowed entry in Warehouse") \
|
webnotes.throw(_("Not allowed entry in Warehouse") \
|
||||||
+ ": " + warehouse, UserNotAllowedForWarehouse)
|
+ ": " + warehouse, UserNotAllowedForWarehouse)
|
||||||
|
|
||||||
def get_buying_amount(item_code, voucher_type, voucher_no, voucher_detail_no,
|
def get_sales_bom_buying_amount(item_code, warehouse, voucher_type, voucher_no, voucher_detail_no,
|
||||||
stock_ledger_entries, item_sales_bom=None):
|
stock_ledger_entries, item_sales_bom):
|
||||||
if item_sales_bom and item_sales_bom.get(item_code):
|
# sales bom item
|
||||||
# sales bom item
|
buying_amount = 0.0
|
||||||
buying_amount = 0.0
|
for bom_item in item_sales_bom[item_code]:
|
||||||
for bom_item in item_sales_bom[item_code]:
|
if bom_item.get("parent_detail_docname")==voucher_detail_no:
|
||||||
if bom_item.get("parent_detail_docname")==voucher_detail_no:
|
buying_amount += get_buying_amount(voucher_type, voucher_no, voucher_detail_no,
|
||||||
buying_amount += _get_buying_amount(voucher_type, voucher_no, voucher_detail_no, stock_ledger_entries)
|
stock_ledger_entries.get((bom_item.item_code, warehouse), []))
|
||||||
return buying_amount
|
|
||||||
else:
|
return buying_amount
|
||||||
# doesn't have sales bom
|
|
||||||
return _get_buying_amount(voucher_type, voucher_no, voucher_detail_no, stock_ledger_entries)
|
|
||||||
|
|
||||||
def _get_buying_amount(voucher_type, voucher_no, item_row, stock_ledger_entries):
|
def get_buying_amount(voucher_type, voucher_no, item_row, stock_ledger_entries):
|
||||||
# IMP NOTE
|
# IMP NOTE
|
||||||
# stock_ledger_entries should already be filtered by item_code and warehouse and
|
# stock_ledger_entries should already be filtered by item_code and warehouse and
|
||||||
# sorted by posting_date desc, posting_time desc
|
# sorted by posting_date desc, posting_time desc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user