mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-03 13:38:27 +00:00
Merge branch 'master' of github.com:webnotes/erpnext into wsgi
Conflicts: accounts/doctype/purchase_invoice/purchase_invoice.py accounts/doctype/sales_invoice/sales_invoice.txt selling/doctype/lead/lead.txt selling/doctype/opportunity/opportunity.txt stock/doctype/warehouse/warehouse.py
This commit is contained in:
@@ -15,7 +15,7 @@ class DocType:
|
||||
self.doclist = doclist
|
||||
|
||||
def validate(self):
|
||||
if not self.doc.stock_uom:
|
||||
if self.doc.fields.get("__islocal") or not self.doc.stock_uom:
|
||||
self.doc.stock_uom = webnotes.conn.get_value('Item', self.doc.item_code, 'stock_uom')
|
||||
|
||||
self.validate_mandatory()
|
||||
|
||||
@@ -10,6 +10,7 @@ cur_frm.cscript.sales_team_fname = "sales_team";
|
||||
wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
|
||||
wn.require('app/utilities/doctype/sms_control/sms_control.js');
|
||||
wn.require('app/selling/doctype/sales_common/sales_common.js');
|
||||
wn.require('app/accounts/doctype/sales_invoice/pos.js');
|
||||
|
||||
wn.provide("erpnext.stock");
|
||||
erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend({
|
||||
|
||||
@@ -347,9 +347,16 @@ def make_supplier_quotation(source_name, target_doclist=None):
|
||||
@webnotes.whitelist()
|
||||
def make_stock_entry(source_name, target_doclist=None):
|
||||
from webnotes.model.mapper import get_mapped_doclist
|
||||
|
||||
def set_purpose(source, target):
|
||||
|
||||
def update_item(obj, target, source_parent):
|
||||
target.conversion_factor = 1
|
||||
target.qty = flt(obj.qty) - flt(obj.ordered_qty)
|
||||
target.transfer_qty = flt(obj.qty) - flt(obj.ordered_qty)
|
||||
|
||||
def set_missing_values(source, target):
|
||||
target[0].purpose = "Material Transfer"
|
||||
se = webnotes.bean(target)
|
||||
se.run_method("get_stock_and_rate")
|
||||
|
||||
doclist = get_mapped_doclist("Material Request", source_name, {
|
||||
"Material Request": {
|
||||
@@ -369,6 +376,6 @@ def make_stock_entry(source_name, target_doclist=None):
|
||||
},
|
||||
"postprocess": update_item
|
||||
}
|
||||
}, target_doclist, set_purpose)
|
||||
}, target_doclist, set_missing_values)
|
||||
|
||||
return [d.fields for d in doclist]
|
||||
@@ -8,6 +8,7 @@ cur_frm.cscript.other_fname = "purchase_tax_details";
|
||||
wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
|
||||
wn.require('app/utilities/doctype/sms_control/sms_control.js');
|
||||
wn.require('app/buying/doctype/purchase_common/purchase_common.js');
|
||||
wn.require('app/accounts/doctype/sales_invoice/pos.js');
|
||||
|
||||
wn.provide("erpnext.stock");
|
||||
erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend({
|
||||
|
||||
@@ -117,8 +117,7 @@ class DocType(BuyingController):
|
||||
},
|
||||
"Purchase Order Item": {
|
||||
"ref_dn_field": "prevdoc_detail_docname",
|
||||
"compare_fields": [["project_name", "="], ["warehouse", "="],
|
||||
["uom", "="], ["item_code", "="]],
|
||||
"compare_fields": [["project_name", "="], ["uom", "="], ["item_code", "="]],
|
||||
"is_child_table": True
|
||||
}
|
||||
})
|
||||
@@ -165,34 +164,43 @@ class DocType(BuyingController):
|
||||
|
||||
self.bk_flush_supp_wh(sl_entries)
|
||||
self.make_sl_entries(sl_entries)
|
||||
|
||||
def update_ordered_qty(self, is_cancelled="No"):
|
||||
pc_obj = get_obj('Purchase Common')
|
||||
|
||||
def update_ordered_qty(self):
|
||||
stock_items = self.get_stock_items()
|
||||
for d in getlist(self.doclist, 'purchase_receipt_details'):
|
||||
for d in self.doclist.get({"parentfield": "purchase_receipt_details"}):
|
||||
if d.item_code in stock_items and d.warehouse \
|
||||
and cstr(d.prevdoc_doctype) == 'Purchase Order':
|
||||
pr_qty = flt(d.qty) * flt(d.conversion_factor)
|
||||
|
||||
# get qty and pending_qty of prevdoc
|
||||
curr_ref_qty = pc_obj.get_qty(d.doctype, 'prevdoc_detail_docname',
|
||||
d.prevdoc_detail_docname, 'Purchase Order Item',
|
||||
'Purchase Order - Purchase Receipt', self.doc.name)
|
||||
max_qty, qty, curr_qty = flt(curr_ref_qty.split('~~~')[1]), \
|
||||
flt(curr_ref_qty.split('~~~')[0]), 0
|
||||
|
||||
if flt(qty) + flt(pr_qty) > flt(max_qty):
|
||||
curr_qty = (flt(max_qty) - flt(qty)) * flt(d.conversion_factor)
|
||||
|
||||
already_received_qty = self.get_already_received_qty(d.prevdoc_docname,
|
||||
d.prevdoc_detail_docname)
|
||||
po_qty, ordered_warehouse = self.get_po_qty_and_warehouse(d.prevdoc_detail_docname)
|
||||
|
||||
if not ordered_warehouse:
|
||||
webnotes.throw(_("Warehouse is missing in Purchase Order"))
|
||||
|
||||
if already_received_qty + d.qty > po_qty:
|
||||
ordered_qty = - (po_qty - already_received_qty) * flt(d.conversion_factor)
|
||||
else:
|
||||
curr_qty = flt(pr_qty)
|
||||
|
||||
args = {
|
||||
ordered_qty = - flt(d.qty) * flt(d.conversion_factor)
|
||||
|
||||
update_bin({
|
||||
"item_code": d.item_code,
|
||||
"warehouse": d.warehouse,
|
||||
"warehouse": ordered_warehouse,
|
||||
"posting_date": self.doc.posting_date,
|
||||
"ordered_qty": (is_cancelled=="Yes" and -1 or 1)*flt(curr_qty)
|
||||
}
|
||||
update_bin(args)
|
||||
"ordered_qty": flt(ordered_qty) if self.doc.docstatus==1 else -flt(ordered_qty)
|
||||
})
|
||||
|
||||
def get_already_received_qty(self, po, po_detail):
|
||||
qty = webnotes.conn.sql("""select sum(qty) from `tabPurchase Receipt Item`
|
||||
where prevdoc_detail_docname = %s and docstatus = 1
|
||||
and prevdoc_doctype='Purchase Order' and prevdoc_docname=%s
|
||||
and parent != %s""", (po_detail, po, self.doc.name))
|
||||
return qty and flt(qty[0][0]) or 0.0
|
||||
|
||||
def get_po_qty_and_warehouse(self, po_detail):
|
||||
po_qty, po_warehouse = webnotes.conn.get_value("Purchase Order Item", po_detail,
|
||||
["qty", "warehouse"])
|
||||
return po_qty, po_warehouse
|
||||
|
||||
def bk_flush_supp_wh(self, sl_entries):
|
||||
for d in getlist(self.doclist, 'pr_raw_material_details'):
|
||||
@@ -201,7 +209,7 @@ class DocType(BuyingController):
|
||||
sl_entries.append(self.get_sl_entries(d, {
|
||||
"item_code": d.rm_item_code,
|
||||
"warehouse": self.doc.supplier_warehouse,
|
||||
"actual_qty": -1*flt(consumed_qty),
|
||||
"actual_qty": -1*flt(d.consumed_qty),
|
||||
"incoming_rate": 0
|
||||
}))
|
||||
|
||||
@@ -281,7 +289,7 @@ class DocType(BuyingController):
|
||||
|
||||
webnotes.conn.set(self.doc,'status','Cancelled')
|
||||
|
||||
self.update_ordered_qty(is_cancelled="Yes")
|
||||
self.update_ordered_qty()
|
||||
|
||||
self.update_stock()
|
||||
self.update_serial_nos(cancel=True)
|
||||
|
||||
@@ -246,6 +246,7 @@ class DocType(StockController):
|
||||
"stock_uom": webnotes.conn.get_value("Item", row.item_code, "stock_uom"),
|
||||
"voucher_detail_no": row.voucher_detail_no,
|
||||
"fiscal_year": self.doc.fiscal_year,
|
||||
"is_cancelled": "No"
|
||||
})
|
||||
args.update(opts)
|
||||
self.make_sl_entries([args])
|
||||
|
||||
@@ -209,5 +209,4 @@ class DocType:
|
||||
msgprint("""Warehosue can not be deleted as stock ledger entry
|
||||
exists for this warehouse.""", raise_exception=1)
|
||||
else:
|
||||
webnotes.conn.sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
|
||||
|
||||
webnotes.conn.sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
|
||||
@@ -126,10 +126,11 @@ erpnext.StockBalance = erpnext.StockAnalytics.extend({
|
||||
} else {
|
||||
item.inflow_value += value_diff;
|
||||
}
|
||||
}
|
||||
|
||||
item.closing_qty += qty_diff;
|
||||
item.closing_value += value_diff;
|
||||
item.closing_qty += qty_diff;
|
||||
item.closing_value += value_diff;
|
||||
}
|
||||
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -14,29 +14,31 @@ _exceptions = webnotes.local('stockledger_exceptions')
|
||||
# _exceptions = []
|
||||
|
||||
def make_sl_entries(sl_entries, is_amended=None):
|
||||
from stock.utils import update_bin
|
||||
if sl_entries:
|
||||
from stock.utils import update_bin
|
||||
|
||||
cancel = True if sl_entries[0].get("is_cancelled") == "Yes" else False
|
||||
if cancel:
|
||||
set_as_cancel(sl_entries[0].get('voucher_no'), sl_entries[0].get('voucher_type'))
|
||||
cancel = True if sl_entries[0].get("is_cancelled") == "Yes" else False
|
||||
if cancel:
|
||||
set_as_cancel(sl_entries[0].get('voucher_no'), sl_entries[0].get('voucher_type'))
|
||||
|
||||
for sle in sl_entries:
|
||||
sle_id = None
|
||||
if sle.get('is_cancelled') == 'Yes':
|
||||
sle['actual_qty'] = -flt(sle['actual_qty'])
|
||||
for sle in sl_entries:
|
||||
sle_id = None
|
||||
if sle.get('is_cancelled') == 'Yes':
|
||||
sle['actual_qty'] = -flt(sle['actual_qty'])
|
||||
|
||||
if sle.get("actual_qty"):
|
||||
sle_id = make_entry(sle)
|
||||
if sle.get("actual_qty"):
|
||||
sle_id = make_entry(sle)
|
||||
|
||||
args = sle.copy()
|
||||
args.update({
|
||||
"sle_id": sle_id,
|
||||
"is_amended": is_amended
|
||||
})
|
||||
update_bin(args)
|
||||
args = sle.copy()
|
||||
args.update({
|
||||
"sle_id": sle_id,
|
||||
"is_amended": is_amended
|
||||
})
|
||||
update_bin(args)
|
||||
|
||||
if cancel:
|
||||
delete_cancelled_entry(sl_entries[0].get('voucher_type'), sl_entries[0].get('voucher_no'))
|
||||
if cancel:
|
||||
delete_cancelled_entry(sl_entries[0].get('voucher_type'),
|
||||
sl_entries[0].get('voucher_no'))
|
||||
|
||||
def set_as_cancel(voucher_type, voucher_no):
|
||||
webnotes.conn.sql("""update `tabStock Ledger Entry` set is_cancelled='Yes',
|
||||
|
||||
Reference in New Issue
Block a user