Stock Return: fetch customer and supplier details
This commit is contained in:
parent
8dc2c6a16c
commit
b5be7bab9b
@ -93,9 +93,8 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
|
|||||||
|
|
||||||
if(cint(wn.defaults.get_default("auto_accounting_for_stock"))) {
|
if(cint(wn.defaults.get_default("auto_accounting_for_stock"))) {
|
||||||
var account_for = "stock_adjustment_account";
|
var account_for = "stock_adjustment_account";
|
||||||
if (this.frm.doc.purpose == "Sales Return")
|
|
||||||
account_for = "stock_in_hand_account";
|
if (this.frm.doc.purpose == "Purchase Return")
|
||||||
else if (this.frm.doc.purpose == "Purchase Return")
|
|
||||||
account_for = "stock_received_but_not_billed";
|
account_for = "stock_received_but_not_billed";
|
||||||
|
|
||||||
return this.frm.call({
|
return this.frm.call({
|
||||||
@ -236,7 +235,50 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
|
|||||||
|
|
||||||
mtn_details_on_form_rendered: function(doc, grid_row) {
|
mtn_details_on_form_rendered: function(doc, grid_row) {
|
||||||
erpnext.setup_serial_no(grid_row)
|
erpnext.setup_serial_no(grid_row)
|
||||||
|
},
|
||||||
|
|
||||||
|
customer: function() {
|
||||||
|
return this.frm.call({
|
||||||
|
method: "erpnext.selling.doctype.customer.customer.get_customer_details",
|
||||||
|
args: { customer: this.frm.doc.customer }
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
supplier: function() {
|
||||||
|
return this.frm.call({
|
||||||
|
method: "erpnext.buying.doctype.supplier.supplier.get_supplier_details",
|
||||||
|
args: { supplier: this.frm.doc.supplier }
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
delivery_note_no: function() {
|
||||||
|
this.get_party_details({
|
||||||
|
ref_dt: "Delivery Note",
|
||||||
|
ref_dn: this.frm.doc.delivery_note_no
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
sales_invoice_no: function() {
|
||||||
|
this.get_party_details({
|
||||||
|
ref_dt: "Sales Invoice",
|
||||||
|
ref_dn: this.frm.doc.sales_invoice_no
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
purchase_receipt_no: function() {
|
||||||
|
this.get_party_details({
|
||||||
|
ref_dt: "Purchase Receipt",
|
||||||
|
ref_dn: this.frm.doc.purchase_receipt_no
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
get_party_details: function(args) {
|
||||||
|
return this.frm.call({
|
||||||
|
method: "erpnext.stock.doctype.stock_entry.stock_entry.get_party_details",
|
||||||
|
args: args,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cur_frm.script_manager.make(erpnext.stock.StockEntry);
|
cur_frm.script_manager.make(erpnext.stock.StockEntry);
|
||||||
@ -265,32 +307,6 @@ cur_frm.cscript.toggle_related_fields = function(doc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_frm.cscript.delivery_note_no = function(doc, cdt, cdn) {
|
|
||||||
if(doc.delivery_note_no)
|
|
||||||
return get_server_fields('get_cust_values', '', '', doc, cdt, cdn, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.cscript.sales_invoice_no = function(doc, cdt, cdn) {
|
|
||||||
if(doc.sales_invoice_no)
|
|
||||||
return get_server_fields('get_cust_values', '', '', doc, cdt, cdn, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.cscript.customer = function(doc, cdt, cdn) {
|
|
||||||
if(doc.customer)
|
|
||||||
return get_server_fields('get_cust_addr', '', '', doc, cdt, cdn, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.cscript.purchase_receipt_no = function(doc, cdt, cdn) {
|
|
||||||
if(doc.purchase_receipt_no)
|
|
||||||
return get_server_fields('get_supp_values', '', '', doc, cdt, cdn, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.cscript.supplier = function(doc, cdt, cdn) {
|
|
||||||
if(doc.supplier)
|
|
||||||
return get_server_fields('get_supp_addr', '', '', doc, cdt, cdn, 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.fields_dict['production_order'].get_query = function(doc) {
|
cur_frm.fields_dict['production_order'].get_query = function(doc) {
|
||||||
return{
|
return{
|
||||||
filters:[
|
filters:[
|
||||||
|
@ -591,56 +591,6 @@ class DocType(StockController):
|
|||||||
idx += 1
|
idx += 1
|
||||||
return idx
|
return idx
|
||||||
|
|
||||||
def get_cust_values(self):
|
|
||||||
"""fetches customer details"""
|
|
||||||
if self.doc.delivery_note_no:
|
|
||||||
doctype = "Delivery Note"
|
|
||||||
name = self.doc.delivery_note_no
|
|
||||||
else:
|
|
||||||
doctype = "Sales Invoice"
|
|
||||||
name = self.doc.sales_invoice_no
|
|
||||||
|
|
||||||
result = webnotes.conn.sql("""select customer, customer_name,
|
|
||||||
address_display as customer_address
|
|
||||||
from `tab%s` where name=%s""" % (doctype, "%s"), (name,), as_dict=1)
|
|
||||||
|
|
||||||
return result and result[0] or {}
|
|
||||||
|
|
||||||
def get_cust_addr(self):
|
|
||||||
from erpnext.utilities.transaction_base import get_default_address, get_address_display
|
|
||||||
res = webnotes.conn.sql("select customer_name from `tabCustomer` where name = '%s'"%self.doc.customer)
|
|
||||||
address_display = None
|
|
||||||
customer_address = get_default_address("customer", self.doc.customer)
|
|
||||||
if customer_address:
|
|
||||||
address_display = get_address_display(customer_address)
|
|
||||||
ret = {
|
|
||||||
'customer_name' : res and res[0][0] or '',
|
|
||||||
'customer_address' : address_display}
|
|
||||||
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def get_supp_values(self):
|
|
||||||
result = webnotes.conn.sql("""select supplier, supplier_name,
|
|
||||||
address_display as supplier_address
|
|
||||||
from `tabPurchase Receipt` where name=%s""", (self.doc.purchase_receipt_no,),
|
|
||||||
as_dict=1)
|
|
||||||
|
|
||||||
return result and result[0] or {}
|
|
||||||
|
|
||||||
def get_supp_addr(self):
|
|
||||||
from erpnext.utilities.transaction_base import get_default_address, get_address_display
|
|
||||||
res = webnotes.conn.sql("""select supplier_name from `tabSupplier`
|
|
||||||
where name=%s""", self.doc.supplier)
|
|
||||||
address_display = None
|
|
||||||
supplier_address = get_default_address("customer", self.doc.customer)
|
|
||||||
if supplier_address:
|
|
||||||
address_display = get_address_display(supplier_address)
|
|
||||||
|
|
||||||
ret = {
|
|
||||||
'supplier_name' : res and res[0][0] or '',
|
|
||||||
'supplier_address' : address_display }
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def validate_with_material_request(self):
|
def validate_with_material_request(self):
|
||||||
for item in self.doclist.get({"parentfield": "mtn_details"}):
|
for item in self.doclist.get({"parentfield": "mtn_details"}):
|
||||||
if item.material_request:
|
if item.material_request:
|
||||||
@ -653,6 +603,17 @@ class DocType(StockController):
|
|||||||
+ _("Material Request") + (" - %s" % item.material_request),
|
+ _("Material Request") + (" - %s" % item.material_request),
|
||||||
raise_exception=webnotes.MappingMismatchError)
|
raise_exception=webnotes.MappingMismatchError)
|
||||||
|
|
||||||
|
@webnotes.whitelist()
|
||||||
|
def get_party_details(ref_dt, ref_dn):
|
||||||
|
if ref_dt in ["Delivery Note", "Sales Invoice"]:
|
||||||
|
res = webnotes.conn.get_value(ref_dt, ref_dn,
|
||||||
|
["customer", "customer_name", "address_display as customer_address"], as_dict=1)
|
||||||
|
else:
|
||||||
|
res = webnotes.conn.get_value(ref_dt, ref_dn,
|
||||||
|
["supplier", "supplier_name", "address_display as supplier_address"], as_dict=1)
|
||||||
|
print ref_dt, ref_dn, res
|
||||||
|
return res or {}
|
||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def get_production_order_details(production_order):
|
def get_production_order_details(production_order):
|
||||||
result = webnotes.conn.sql("""select bom_no,
|
result = webnotes.conn.sql("""select bom_no,
|
||||||
@ -966,4 +927,3 @@ def make_return_jv_from_purchase_receipt(se, ref):
|
|||||||
result = [parent] + [{"account": account} for account in children]
|
result = [parent] + [{"account": account} for account in children]
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -2,28 +2,14 @@
|
|||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes, json
|
import webnotes
|
||||||
from webnotes import msgprint, _
|
from webnotes import msgprint, _
|
||||||
from webnotes.utils import cstr, flt, now_datetime, cint
|
from webnotes.utils import cstr, flt, now_datetime, cint
|
||||||
from webnotes.model.doc import addchild
|
|
||||||
|
|
||||||
from erpnext.controllers.status_updater import StatusUpdater
|
from erpnext.controllers.status_updater import StatusUpdater
|
||||||
|
|
||||||
|
|
||||||
class TransactionBase(StatusUpdater):
|
class TransactionBase(StatusUpdater):
|
||||||
def set_address_fields(self):
|
|
||||||
party_type, party_name = self.get_party_type_and_name()
|
|
||||||
|
|
||||||
if party_type in ("Customer", "Lead"):
|
|
||||||
if self.doc.customer_address:
|
|
||||||
self.doc.address_display = get_address_display(self.doc.customer_address)
|
|
||||||
|
|
||||||
if self.doc.shipping_address_name:
|
|
||||||
self.doc.shipping_address = get_address_display(self.doc.shipping_address_name)
|
|
||||||
|
|
||||||
elif self.doc.supplier_address:
|
|
||||||
self.doc.address_display = get_address_display(self.doc.supplier_address)
|
|
||||||
|
|
||||||
def set_contact_fields(self):
|
def set_contact_fields(self):
|
||||||
party_type, party_name = self.get_party_type_and_name()
|
party_type, party_name = self.get_party_type_and_name()
|
||||||
|
|
||||||
@ -60,74 +46,6 @@ class TransactionBase(StatusUpdater):
|
|||||||
def set_lead_defaults(self):
|
def set_lead_defaults(self):
|
||||||
self.doc.fields.update(self.get_lead_defaults())
|
self.doc.fields.update(self.get_lead_defaults())
|
||||||
|
|
||||||
# TODO deprecate this - used only in sales_order.js
|
|
||||||
def get_shipping_address(self, name):
|
|
||||||
shipping_address = get_default_address("customer", name, is_shipping_address=True)
|
|
||||||
return {
|
|
||||||
'shipping_address_name' : shipping_address,
|
|
||||||
'shipping_address' : get_address_display(shipping_address) if shipping_address else None
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get Supplier Default Primary Address - first load
|
|
||||||
# -----------------------
|
|
||||||
def get_default_supplier_address(self, args):
|
|
||||||
if isinstance(args, basestring):
|
|
||||||
args = json.loads(args)
|
|
||||||
|
|
||||||
address_name = get_default_address("supplier", args["supplier"])
|
|
||||||
ret = {
|
|
||||||
'supplier_address' : address_name,
|
|
||||||
'address_display' : get_address_display(address_name),
|
|
||||||
}
|
|
||||||
ret.update(map_party_contact_details(None, "supplier", args["supplier"]))
|
|
||||||
ret.update(self.get_supplier_details(args['supplier']))
|
|
||||||
return ret
|
|
||||||
|
|
||||||
# Get Supplier Address
|
|
||||||
# -----------------------
|
|
||||||
def get_supplier_address(self, args):
|
|
||||||
args = json.loads(args)
|
|
||||||
ret = {
|
|
||||||
'supplier_address' : args['address'],
|
|
||||||
'address_display' : get_address_display(args["address"]),
|
|
||||||
}
|
|
||||||
ret.update(map_party_contact_details(contact_name=args['contact']))
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def set_supplier_address(self, args):
|
|
||||||
self.doc.fields.update(self.get_supplier_address(args))
|
|
||||||
|
|
||||||
# Get Supplier Details
|
|
||||||
# -----------------------
|
|
||||||
def get_supplier_details(self, name):
|
|
||||||
supplier_details = webnotes.conn.sql("""\
|
|
||||||
select supplier_name, default_currency
|
|
||||||
from `tabSupplier`
|
|
||||||
where name = %s and docstatus < 2""", name, as_dict=1)
|
|
||||||
if supplier_details:
|
|
||||||
return {
|
|
||||||
'supplier_name': (supplier_details[0]['supplier_name']
|
|
||||||
or self.doc.fields.get('supplier_name')),
|
|
||||||
'currency': (supplier_details[0]['default_currency']
|
|
||||||
or self.doc.fields.get('currency')),
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
# Get Sales Person Details of Customer
|
|
||||||
# ------------------------------------
|
|
||||||
def get_sales_person(self, name):
|
|
||||||
self.doclist = self.doc.clear_table(self.doclist,'sales_team')
|
|
||||||
idx = 0
|
|
||||||
for d in webnotes.conn.sql("select sales_person, allocated_percentage, allocated_amount, incentives from `tabSales Team` where parent = '%s'" % name):
|
|
||||||
ch = addchild(self.doc, 'sales_team', 'Sales Team', self.doclist)
|
|
||||||
ch.sales_person = d and cstr(d[0]) or ''
|
|
||||||
ch.allocated_percentage = d and flt(d[1]) or 0
|
|
||||||
ch.allocated_amount = d and flt(d[2]) or 0
|
|
||||||
ch.incentives = d and flt(d[3]) or 0
|
|
||||||
ch.idx = idx
|
|
||||||
idx += 1
|
|
||||||
|
|
||||||
def load_notification_message(self):
|
def load_notification_message(self):
|
||||||
dt = self.doc.doctype.lower().replace(" ", "_")
|
dt = self.doc.doctype.lower().replace(" ", "_")
|
||||||
if int(webnotes.conn.get_value("Notification Control", None, dt) or 0):
|
if int(webnotes.conn.get_value("Notification Control", None, dt) or 0):
|
||||||
@ -209,17 +127,6 @@ class TransactionBase(StatusUpdater):
|
|||||||
if prevdoc_values[field] is not None:
|
if prevdoc_values[field] is not None:
|
||||||
self.validate_value(field, condition, prevdoc_values[field], doc)
|
self.validate_value(field, condition, prevdoc_values[field], doc)
|
||||||
|
|
||||||
def get_default_address(party_field, party_name, is_shipping_address=False):
|
|
||||||
if is_shipping_address:
|
|
||||||
order_by = "is_shipping_address desc, is_primary_address desc, name asc"
|
|
||||||
else:
|
|
||||||
order_by = "is_primary_address desc, name asc"
|
|
||||||
|
|
||||||
address = webnotes.conn.sql("""select name from `tabAddress` where `%s`=%s order by %s
|
|
||||||
limit 1""" % (party_field, "%s", order_by), party_name)
|
|
||||||
|
|
||||||
return address[0][0] if address else None
|
|
||||||
|
|
||||||
def get_default_contact(party_field, party_name):
|
def get_default_contact(party_field, party_name):
|
||||||
contact = webnotes.conn.sql("""select name from `tabContact` where `%s`=%s
|
contact = webnotes.conn.sql("""select name from `tabContact` where `%s`=%s
|
||||||
order by is_primary_contact desc, name asc limit 1""" % (party_field, "%s"),
|
order by is_primary_contact desc, name asc limit 1""" % (party_field, "%s"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user